fix(opencode): refresh effect sqlite client after reset

This commit is contained in:
Kit Langton 2026-04-27 22:57:34 -04:00
parent 4faa6c64d6
commit 8e2c15214e

View file

@ -7,6 +7,18 @@ const schema = { ...StorageSchema }
export class Service extends Context.Service<Service, EffectSQLiteDatabase<typeof schema>>()("@opencode/DatabaseEffect") {}
export const layer = Layer.sync(Service, () => drizzle({ client: Database.Client().$client, schema }))
export const layer = Layer.sync(Service, () => {
let current: EffectSQLiteDatabase<typeof schema> | undefined
return new Proxy({} as EffectSQLiteDatabase<typeof schema>, {
get(_target, property) {
const client = Database.Client().$client
if (current?.$client !== client) current = drizzle({ client, schema })
const value = Reflect.get(current, property)
return typeof value === "function" ? value.bind(current) : value
},
})
})
export * as DatabaseEffect from "./db-effect"