D1Client.ts overview
A SqlClient over Alchemy’s D1 client, the package’s only D1-specific code. D1 has no interactive transactions, so sql.withTransaction buffers writes and sends them as batch()es: the writes between two reads commit together, but nothing is atomic across a read.
Exports Grouped by Category
utils
layer
make as a Layer, with Reactivity provided. It still needs the RuntimeContext of the event it is built in.
Example
const stores = Sql.layer.pipe(Layer.provide(D1Client.layer({ db })))
Signature
declare const layer: (options: {
readonly db: QueryDatabaseClient
readonly spanAttributes?: ReadonlyArray<readonly [string, unknown]>
}) => Layer.Layer<SqlClient.SqlClient, never, RuntimeContext>
make
Build a SqlClient over the D1 client Cloudflare.D1.QueryDatabase(database) binds. Needs the RuntimeContext of the Worker, Durable Object or Action it runs in, which it captures for every statement the client sends.
Example
const db = yield * Cloudflare.D1.QueryDatabase(AuthDatabase)
const sql = yield * D1Client.make({ db })
Signature
declare const make: (options: {
readonly db: QueryDatabaseClient
readonly spanAttributes?: ReadonlyArray<readonly [string, unknown]>
}) => Effect.Effect<SqlClient.SqlClient, never, Reactivity.Reactivity | RuntimeContext>