anyone know of a better way to use a

anyone know of a better way to use a regular POJO as a durable object (sometimes). example code in thread
3 Replies
matt
mattOP5w ago
export class ProjectDB extends DurableObject<Bindings> implements DB {
pdb: DB

constructor(ctx: DurableObjectState, env: Bindings) {
super(ctx, env)
const db = drizzle<typeof schema>(ctx.storage, {
schema,
logger: false,
casing: 'snake_case',
})
this.pdb = connect(db)
ctx.blockConcurrencyWhile(async () => {
await migrate(db, migrations)
})
}

insertRun(...args: Parameters<DB['insertRun']>) {
return this.pdb.insertRun(...args)
}

listRuns(...args: Parameters<DB['listRuns']>) {
return this.pdb.listRuns(...args)
}
export class ProjectDB extends DurableObject<Bindings> implements DB {
pdb: DB

constructor(ctx: DurableObjectState, env: Bindings) {
super(ctx, env)
const db = drizzle<typeof schema>(ctx.storage, {
schema,
logger: false,
casing: 'snake_case',
})
this.pdb = connect(db)
ctx.blockConcurrencyWhile(async () => {
await migrate(db, migrations)
})
}

insertRun(...args: Parameters<DB['insertRun']>) {
return this.pdb.insertRun(...args)
}

listRuns(...args: Parameters<DB['listRuns']>) {
return this.pdb.listRuns(...args)
}
freddie
freddie5w ago
there isn’t a way as far as I know, and also why? classes are fine
matt
mattOP4w ago
The object I’m wrapping is used in an in-memory test cluster as well, where there’s only a JS runtime Ie. no cloudflare / workers

Did you find this page helpful?