mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import mongodb from 'mongodb';
|
||||
import * as bus from './bus';
|
||||
import options from '../options';
|
||||
|
||||
let mongourl = 'mongodb://';
|
||||
if (options.username) mongourl += `${options.username}:${options.password}@`;
|
||||
mongourl += `${options.host}:${options.port}/${options.name}`;
|
||||
|
||||
export let db: mongodb.Db = null;
|
||||
|
||||
mongodb.MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true })
|
||||
.then((Client) => {
|
||||
db = Client.db(options.name);
|
||||
bus.publish('system_database_connected', null);
|
||||
});
|
||||
|
||||
export function collection(c: string) {
|
||||
return db.collection(c);
|
||||
}
|
||||
|
||||
global.Hydro.service.db = { collection };
|
||||
|
||||
export default { collection };
|
||||
Reference in new issue
Block a user