D1Client.ts
D1Client.ts overview
Section titled “D1Client.ts overview”Cloudflare D1 client implementation for Effect SQL, backed by a Workers D1Database binding.
This module adapts a Cloudflare D1 database binding into both the
D1-specific D1Client service and the generic Effect SqlClient service.
It uses the SQLite statement compiler, caches prepared statements, maps D1
failures to SqlError, and provides direct or config-backed layers.
Transactions, streaming queries, and updateValues are not supported by this
driver.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
Signature
declare const make: (options: D1ClientConfig) => Effect.Effect<D1Client, never, Scope.Scope | Reactivity.Reactivity>Since v4.0.0
layers
Section titled “layers”Creates a layer from a concrete D1 client configuration, providing both D1Client and SqlClient.
Signature
declare const layer: (config: D1ClientConfig) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>Since v4.0.0
layerConfig
Section titled “layerConfig”Creates a layer from a Config-wrapped D1 client configuration, providing both D1Client and SqlClient.
Signature
declare const layerConfig: ( config: Config.Wrap<D1ClientConfig>) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>Since v4.0.0
models
Section titled “models”D1Client (interface)
Section titled “D1Client (interface)”Cloudflare D1 SQL client service, extending SqlClient with its D1 configuration and no updateValues support.
Signature
export interface D1Client extends Client.SqlClient { readonly [TypeId]: TypeId readonly config: D1ClientConfig
/** Not supported in d1 */ readonly updateValues: never}Since v4.0.0
D1ClientConfig (interface)
Section titled “D1ClientConfig (interface)”Configuration for a Cloudflare D1 client, including the D1Database, prepared statement cache settings, span attributes, and query/result name transforms.
Signature
export interface D1ClientConfig { readonly db: D1Database readonly prepareCacheSize?: number | undefined readonly prepareCacheTTL?: Duration.Input | undefined readonly spanAttributes?: Record<string, unknown> | undefined
readonly transformResultNames?: ((str: string) => string) | undefined readonly transformQueryNames?: ((str: string) => string) | undefined}Since v4.0.0
services
Section titled “services”D1Client
Section titled “D1Client”Service tag for the Cloudflare D1 SQL client.
When to use
Use to access or provide a Cloudflare D1 SQL client through the Effect context.
Signature
declare const D1Client: Context.Service<D1Client, D1Client>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Unique runtime identifier used to tag D1Client values.
Signature
declare const TypeId: "~@effect/sql-d1/D1Client"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Type-level literal for the D1Client runtime identifier.
Signature
type TypeId = "~@effect/sql-d1/D1Client"Since v4.0.0