mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: db: add collectionMap support
This commit is contained in:
1 file changed
+4
-2
@@ -22,6 +22,7 @@ interface MongoConfig {
|
||||
url?: string,
|
||||
uri?: string,
|
||||
prefix?: string,
|
||||
collectionMap?: Record<string, string>,
|
||||
}
|
||||
|
||||
class MongoService {
|
||||
@@ -54,8 +55,9 @@ class MongoService {
|
||||
}
|
||||
|
||||
public collection<K extends keyof Collections>(c: K) {
|
||||
if (this.opts.prefix) return this.db.collection<Collections[K]>(`${this.opts.prefix}.${c}`);
|
||||
return this.db.collection<Collections[K]>(c);
|
||||
let coll = this.opts.prefix ? `${this.opts.prefix}.${c}` : c;
|
||||
if (this.opts.collectionMap?.[coll]) coll = this.opts.collectionMap[coll];
|
||||
return this.db.collection<Collections[K]>(coll);
|
||||
}
|
||||
|
||||
public async fixExpireAfter() {
|
||||
|
||||
Reference in new issue
Block a user