fix(opencode): refresh effect sqlite client after reset
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user