smartmongo/ts/index.ts

36 lines
833 B
TypeScript
Raw Normal View History

2021-12-20 14:58:23 +00:00
import * as plugins from './smartmongo.plugins';
export class SmartMongo {
// STATIC
public static async createInstance() {
const smartMongoInstance = new SmartMongo();
await smartMongoInstance.readyPromise;
return smartMongoInstance;
}
// INSTANCE
private _readyDeferred = plugins.smartpromise.defer();
public readyPromise = this._readyDeferred.promise;
public mongod: plugins.mongoPlugin.MongoMemoryServer;
constructor() {
this.init();
}
public async init() {
this.mongod = await plugins.mongoPlugin.MongoMemoryServer.create();
this._readyDeferred.resolve();
console.log('mongod started');
}
public async getMongoDescriptor() {
await this.readyPromise;
return {
mongoDbUrl: this.mongod.getUri(),
}
}
public async stop() {
this.mongod.stop();
}
}