This commit is contained in:
2026-01-21 16:00:28 +08:00
parent 76796613b4
commit f5fd28621e
13 changed files with 23 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
import { os } from '@orpc/server'
import { createDb } from '@/db/utils'
const IS_SERVERLESS = false // TODO: 这里需要优化
let globalDb: ReturnType<typeof createDb> | null = null
function getDb() {
if (IS_SERVERLESS) {
return createDb()
}
if (!globalDb) {
globalDb = createDb()
}
return globalDb
}
export const dbProvider = os.middleware(async ({ context, next }) => {
const db = getDb()
return next({
context: {
...context,
db,
},
})
})