D1Client
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.
Constructors
Layers
Creates a layer from a concrete D1 client configuration, providing both D1Client and SqlClient.
Signature
declare function layer(config: D1ClientConfig): Layer<D1Client | SqlClient, ConfigError>;layerConfig
Creates a layer from a Config-wrapped D1 client configuration, providing both D1Client and SqlClient.
Signature
declare function layerConfig(
config:
| {
readonly db: Config;
readonly prepareCacheSize?: Config<number | undefined>;
readonly prepareCacheTTL?: Config<Input | undefined>;
readonly spanAttributes?:
| {
[key: string]: Config<unknown>;
}
| Config<Record<string, unknown> | undefined>;
readonly transformQueryNames?: Config<(str: string) => string | undefined>;
readonly transformResultNames?: Config<(str: string) => string | undefined>;
}
| Config<D1ClientConfig>,
): Layer<D1Client | SqlClient, ConfigError>;Models
D1ClientConfig interface
Configuration for a Cloudflare D1 client, including the D1Database, prepared statement cache settings, span attributes, and query/result name transforms.
Signature
interface D1ClientConfig {
readonly db: D1Database;
readonly prepareCacheSize?: number;
readonly prepareCacheTTL?: Input;
readonly spanAttributes?: Record<string, unknown>;
readonly transformQueryNames?: (str: string) => string;
readonly transformResultNames?: (str: string) => string;
}Services
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: Service<D1Client, D1Client>;Cloudflare D1 SQL client service, extending SqlClient with its D1 configuration and no updateValues support.
Signature
interface D1Client extends SqlClient {
<A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
(value: string): Identifier;
readonly "~@effect/sql-d1/D1Client": "~@effect/sql-d1/D1Client";
readonly batch: <Statements extends readonly Array<Statement<any>>>(statements: Statements) => Effect<{ [K in string | number | symbol]: Success<Statements[K]> }, SqlError>;
readonly config: D1ClientConfig;
readonly updateValues: never;
}
Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.