forked from imbytecat/fullstack-starter
refactor: 优化数据库实例获取逻辑,移除无用变量
- 移除未使用的 IS_SERVERLESS 变量并直接调用 getDb 不传参数 - 修改数据库实例获取逻辑,将 serverless 参数改为 singleton 标志,控制是否返回单例实例。
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import { os } from '@orpc/server'
|
||||
import { getDb } from '@/db'
|
||||
|
||||
const IS_SERVERLESS = false // TODO: 这里需要优化
|
||||
|
||||
export const db = os.middleware(async ({ context, next }) => {
|
||||
return next({
|
||||
context: {
|
||||
...context,
|
||||
db: getDb(IS_SERVERLESS),
|
||||
db: getDb(),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,8 +16,8 @@ export type Db = ReturnType<typeof createDb>
|
||||
export const getDb = (() => {
|
||||
let db: Db | null = null
|
||||
|
||||
return (serverless: boolean = false): Db => {
|
||||
if (serverless) {
|
||||
return (singleton = true): Db => {
|
||||
if (!singleton) {
|
||||
return createDb()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user