mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-23 21:16:06 +00:00
fix(opencode): refresh effect sqlite client after reset
This commit is contained in:
parent
4faa6c64d6
commit
8e2c15214e
1 changed files with 13 additions and 1 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue