UNPKG

@sinkingsheep/jsondb

Version:

A lightweight JSON-based database for Node.js

53 lines 1.99 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.QueryChain = void 0; class QueryChain { constructor(db, collectionName) { this.db = db; this.collectionName = collectionName; this.queryConditions = {}; this.sortConditions = {}; } where(query) { this.queryConditions = Object.assign(Object.assign({}, this.queryConditions), query); return this; } sort(sort) { this.sortConditions = Object.assign(Object.assign({}, this.sortConditions), sort); return this; } limit(limit) { this.limitValue = limit; return this; } skip(skip) { this.skipValue = skip; return this; } find() { return __awaiter(this, void 0, void 0, function* () { return this.db.find(this.collectionName, this.queryConditions, { sort: this.sortConditions, limit: this.limitValue, skip: this.skipValue, }); }); } findOne() { return __awaiter(this, void 0, void 0, function* () { const results = yield this.limit(1).find(); return results[0] || null; }); } } exports.QueryChain = QueryChain; //# sourceMappingURL=queryChain.js.map