@wbg-mde/repository
Version:
Managing all common method for file system CRUD operations.
42 lines (41 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const model_1 = require("@wbg-mde/model");
const nedbRepository_1 = require("./nedbRepository");
const mongodbRepository_1 = require("./mongodbRepository");
class Container {
constructor() {
this._singletons = new Map();
}
get() {
const dbname = (model_1.configuration.db) ? model_1.configuration.db.db : model_1.Db.nedb;
const singletonInstance = this._singletons.get(dbname);
if (singletonInstance) {
return singletonInstance;
}
else {
switch (dbname) {
case model_1.Db.nedb:
const nedbInstance = new nedbRepository_1.NeDBRepository();
this._singletons.set(model_1.Db.nedb, nedbInstance);
return nedbInstance;
case model_1.Db.mongodb:
const mongoInstance = new mongodbRepository_1.MongoDBRepository();
this._singletons.set(model_1.Db.mongodb, mongoInstance);
return mongoInstance;
default:
const defaultInstance = this._singletons.get(model_1.Db.nedb);
if (defaultInstance) {
return defaultInstance;
}
else {
const nedbInstance = new nedbRepository_1.NeDBRepository();
this._singletons.set(model_1.Db.nedb, nedbInstance);
return nedbInstance;
}
}
}
}
}
exports.Container = Container;
exports.repoContainer = new Container();