desi-mongoose
Version:
A fun and intuitive MongoDB ODM for Node.js with a Hinglish twist
43 lines (42 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.desiConnect = void 0;
const mongodb_1 = require("mongodb");
class DesiConnection {
constructor() {
this.client = null;
this.db = null;
}
async connect(url = 'mongodb://localhost:27017', dbName = 'test') {
try {
console.log('🙏 Namaste MongoDB!');
this.client = await mongodb_1.MongoClient.connect(url);
this.db = this.client.db(dbName);
console.log('✨ Connection ho gaya!');
return this.db;
}
catch (error) {
console.error('😢 Arre baap re! Connection nahi hua:', error);
throw error;
}
}
async disconnect() {
if (this.client) {
await this.client.close();
console.log('👋 Alvida, MongoDB!');
}
}
getDb() {
if (!this.db) {
throw new Error('Database connection nahi hai!');
}
return this.db;
}
getConnection() {
if (!this.client) {
throw new Error('MongoDB connection nahi hai!');
}
return this.client;
}
}
exports.desiConnect = new DesiConnection();