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,
|
url?: string,
|
||||||
uri?: string,
|
uri?: string,
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
|
collectionMap?: Record<string, string>,
|
||||||
}
|
}
|
||||||
|
|
||||||
class MongoService {
|
class MongoService {
|
||||||
@@ -54,8 +55,9 @@ class MongoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public collection<K extends keyof Collections>(c: K) {
|
public collection<K extends keyof Collections>(c: K) {
|
||||||
if (this.opts.prefix) return this.db.collection<Collections[K]>(`${this.opts.prefix}.${c}`);
|
let coll = this.opts.prefix ? `${this.opts.prefix}.${c}` : c;
|
||||||
return this.db.collection<Collections[K]>(c);
|
if (this.opts.collectionMap?.[coll]) coll = this.opts.collectionMap[coll];
|
||||||
|
return this.db.collection<Collections[K]>(coll);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fixExpireAfter() {
|
public async fixExpireAfter() {
|
||||||
|
|||||||
Reference in new issue
Block a user