import { os } from '@orpc/server' import { createDb } from '@/db' const IS_SERVERLESS = false // TODO: 这里需要优化 let globalDb: ReturnType | 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, }, }) })