mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
fix db mock
This commit is contained in:
1 parent
af9a8fb206
commit
12af2f7542
2 files changed
+22
-1
No files matched your search
@@ -4,6 +4,8 @@ import mongodb, { Db, MongoClient } from 'mongodb';
|
||||
|
||||
export let db: Db = null;
|
||||
export let client: MongoClient = null;
|
||||
export let db2: Db = null;
|
||||
export let client2: MongoClient = null;
|
||||
|
||||
export const bus = new EventEmitter();
|
||||
|
||||
@@ -15,7 +17,16 @@ mongodb.MongoClient.connect(
|
||||
// @ts-ignore
|
||||
db = c.db(global.__MONGO_DB_NAME__);
|
||||
client = c;
|
||||
bus.emit('connect');
|
||||
mongodb.MongoClient.connect(
|
||||
// @ts-ignore
|
||||
global.__MONGO_URI__,
|
||||
{ useNewUrlParser: true, useUnifiedTopology: true },
|
||||
).then((c2) => {
|
||||
// @ts-ignore
|
||||
db2 = c2.db(global.__MONGO_DB_NAME__);
|
||||
client2 = c2;
|
||||
bus.emit('connect');
|
||||
});
|
||||
});
|
||||
|
||||
export function collection(c: string) {
|
||||
@@ -26,6 +37,14 @@ export function getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
export function getClient2() {
|
||||
return client2;
|
||||
}
|
||||
|
||||
export function getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
export function getDb2() {
|
||||
return db2;
|
||||
}
|
||||
@@ -14,5 +14,7 @@ export async function connect() {
|
||||
export async function dispose() {
|
||||
const db = require('hydrooj/src/service/db');
|
||||
await db.getClient().close();
|
||||
await db.getClient2().close();
|
||||
await db.getDb().close();
|
||||
await db.getDb2().close();
|
||||
}
|
||||
Reference in new issue
Block a user