@cemusta/nestjs-pulse
Version:
The modern MongoDB-powered scheduling library pulse for NestJS
43 lines • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabaseService = void 0;
const tslib_1 = require("tslib");
const mongodb_1 = require("mongodb");
const common_1 = require("@nestjs/common");
const constants_1 = require("../constants");
let DatabaseService = class DatabaseService {
config;
connection;
client;
constructor(config) {
this.config = config;
if (config.mongo) {
this.connection = config.mongo;
}
else {
this.client = new mongodb_1.MongoClient(config.db?.address, config.db?.options);
}
}
async connect() {
if (!this.connection) {
this.client = new mongodb_1.MongoClient(this.config.db?.address, this.config.db?.options);
await this.client.connect();
this.connection = this.client.db();
}
}
getConnection() {
return this.connection;
}
async disconnect() {
if (this.client) {
await this.client.close();
}
}
};
exports.DatabaseService = DatabaseService;
exports.DatabaseService = DatabaseService = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__param(0, (0, common_1.Inject)(constants_1.PULSE_MODULE_CONFIG)),
tslib_1.__metadata("design:paramtypes", [Object])
], DatabaseService);
//# sourceMappingURL=database.service.js.map