-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.db.ts
33 lines (27 loc) · 864 Bytes
/
index.db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { initializeMongoDb, connectMongoDb, disconnectMongoDb } from './mongo/index.service';
import { connectSqlite3Db } from './sqlite3/index.service';
/**
* By default, we support mongodb and sqlite3.
* But you can decide to plugin your desired db
*/
export class Db {
public static readonly DB_TYPES = {
mongo: 'mongo',
sqlite3: 'sqlite3',
};
private onConnectDb: (_onSuccess?: () => void) => Promise<any>;
constructor(dbType: keyof typeof Db.DB_TYPES) {
if (dbType === 'mongo') {
initializeMongoDb();
this.onConnectDb = connectMongoDb;
} else {
this.onConnectDb = connectSqlite3Db;
}
}
public async connect(onSuccess: () => void) {
this.onConnectDb(onSuccess);
}
public async disconnect() {
await disconnectMongoDb();
}
}