desi-mongoose
Version:
A fun and intuitive MongoDB ODM for Node.js with a Hinglish twist
46 lines (45 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DesiModel = void 0;
const connection_1 = require("./connection");
class DesiModel {
constructor(name, schema) {
this.schema = schema;
this.collection = connection_1.desiConnect.getDb().collection(name);
}
async nayaBanao(data) {
console.log('✨ Naya record bana rahe hain...');
this.schema.validate(data);
return await this.collection.insertOne({
...data,
createdAt: new Date()
});
}
async dhundo(query = {}) {
console.log('🔍 Dhund rahe hain...');
return await this.collection.find(query).toArray();
}
async ekDhundo(query) {
console.log('🔍 Ek cheez dhund rahe hain...');
return await this.collection.findOne(query);
}
async badlo(query, newData) {
console.log('🔄 Data badal rahe hain...');
return await this.collection.updateOne(query, {
$set: { ...newData, updatedAt: new Date() }
});
}
async hatao(query) {
console.log('🗑️ Data hata rahe hain...');
return await this.collection.deleteOne(query);
}
async sabHatao(query) {
console.log('🗑️ Saara data hata rahe hain...');
return await this.collection.deleteMany(query);
}
async kitneHain(query = {}) {
console.log('🔢 Gin rahe hain...');
return await this.collection.countDocuments(query);
}
}
exports.DesiModel = DesiModel;