This commit is contained in:
2026-01-21 14:41:56 +08:00
parent a6125718f5
commit babd0f5615
63 changed files with 47 additions and 19 deletions

View File

@@ -0,0 +1,29 @@
import { os } from '@orpc/server'
import { createDb } from '@/db'
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,
},
})
})