20 lines
590 B
TypeScript
20 lines
590 B
TypeScript
import { mongoose } from '@typegoose/typegoose'
|
||
|
||
/**
|
||
* 为model指定数据库连接
|
||
* @param {string} name 数据库连接名字, 在config中必须要有对应的配置, 比如main, 则必须要有 db_main
|
||
* */
|
||
export function dbconn(name?: string) {
|
||
return target => {
|
||
name = name || 'main'
|
||
const dbName = ('db_' + name).toUpperCase()
|
||
const url = process.env[dbName]
|
||
target['db'] = mongoose.createConnection(url, {
|
||
// useNewUrlParser: true,
|
||
// useCreateIndex: true,
|
||
// useFindAndModify: false,
|
||
// useUnifiedTopology: true,
|
||
})
|
||
}
|
||
}
|