desi-mongoose
Version:
A fun and intuitive MongoDB ODM for Node.js with a Hinglish twist
74 lines (73 loc) • 1.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DesiQuery = void 0;
class DesiQuery {
constructor() {
this.query = {};
this.options = {};
}
jahaPe(field, value) {
this.query[field] = value;
return this;
}
badalKe(field, value) {
this.query[field] = { $regex: value, $options: 'i' };
return this;
}
baraabarNahi(field, value) {
this.query[field] = { $ne: value };
return this;
}
zyada(field, value) {
this.query[field] = { $gt: value };
return this;
}
kam(field, value) {
this.query[field] = { $lt: value };
return this;
}
zyadaYaBarabar(field, value) {
this.query[field] = { $gte: value };
return this;
}
kamYaBarabar(field, value) {
this.query[field] = { $lte: value };
return this;
}
inMeinHai(field, values) {
this.query[field] = { $in: values };
return this;
}
inMeinNahiHai(field, values) {
this.query[field] = { $nin: values };
return this;
}
exists(field, exists = true) {
this.query[field] = { $exists: exists };
return this;
}
sortKaro(field, order = 'asc') {
this.options.sort = { [field]: order === 'asc' ? 1 : -1 };
return this;
}
limitKaro(limit) {
this.options.limit = limit;
return this;
}
skipKaro(skip) {
this.options.skip = skip;
return this;
}
pageMeinDikhao(page, perPage = 10) {
this.options.skip = (page - 1) * perPage;
this.options.limit = perPage;
return this;
}
getQuery() {
return this.query;
}
getOptions() {
return this.options;
}
}
exports.DesiQuery = DesiQuery;