Skip to content

D1Client.ts

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



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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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
}

Source

Since v4.0.0

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
}

Source

Since v4.0.0

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>

Source

Since v4.0.0

Unique runtime identifier used to tag D1Client values.

Signature

declare const TypeId: "~@effect/sql-d1/D1Client"

Source

Since v4.0.0

Type-level literal for the D1Client runtime identifier.

Signature

type TypeId = "~@effect/sql-d1/D1Client"

Source

Since v4.0.0