UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

19 lines (18 loc) 888 B
import { Kysely } from "kysely"; import { DOWorkerDialect } from "./DOWorkerDialect.js"; export function createDb(durableObjectBinding, name = "main") { return new Kysely({ dialect: new DOWorkerDialect({ kyselyExecuteQuery: (...args) => { const durableObjectId = durableObjectBinding.idFromName(name); // context(justinvdm, 2 Oct 2025): First prize would be a type parameter // for the durable object and then use it for `durableObjectBinding`'s // type, rather than casting like this. However, that would prevent // users from being able to do createDb<InferredDbType> then though. const stub = durableObjectBinding.get(durableObjectId); stub.initialize(); return stub.kyselyExecuteQuery(...args); }, }), }); }