Skip to content

SqliteClient

Connects Effect SQL to SQLite storage inside Cloudflare Durable Objects.

This module adapts a Durable Object SqlStorage handle into both the Durable Object-specific SqliteClient service and the generic Effect SqlClient service. Use it from inside a Durable Object to run local per-object queries, repositories, migrations, transactional read/write workflows, and tests that exercise Cloudflare's SQLite-backed storage API.

Durable Object SQLite storage is scoped to one object id, so each object instance has its own database. Callers can pass the SqlStorage handle for normal queries, or the full DurableObjectStorage when withTransaction or migrations need Cloudflare-managed transactions. This adapter serializes Effect SQL access through one connection; a transaction holds that permit for the lifetime of its scope, so keep transactions short, avoid suspending them across unrelated work, and use them when multi-statement writes must commit atomically. SqlStorage.exec returns ArrayBuffer values for SQLite blobs, which this client normalizes to Uint8Array, and SQLite does not support updateValues.

8 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates a scoped Cloudflare Durable Object SQLite client around Durable Object SQLite storage, serializing access and converting returned ArrayBuffer values to Uint8Array.

Signature

declare function make(options: SqliteClientConfig): Effect<SqliteClient, never, Scope | Reactivity>;

Layers

layer

Added in v4.0.0 Source

Creates a layer from a concrete Durable Object SQLite client configuration, providing both SqliteClient and SqlClient.

Signature

declare function layer(config: SqliteClientConfig): Layer<SqliteClient | SqlClient>;

layerConfig

Added in v4.0.0 Source

Creates a layer from a Config-wrapped Durable Object SQLite client configuration, providing both SqliteClient and SqlClient.

Signature

declare function layerConfig(
  config:
    | {
        readonly db?: Config<any>;
        readonly spanAttributes?:
          | {
              [key: string]: Config<unknown>;
            }
          | Config<Record<string, unknown> | undefined>;
        readonly storage?: Config<any>;
        readonly transformQueryNames?: Config<(str: string) => string | undefined>;
        readonly transformResultNames?: Config<(str: string) => string | undefined>;
      }
    | Config<SqliteClientConfig>,
): Layer<SqliteClient | SqlClient, ConfigError>;

Models

SqliteClientConfig interface

Added in v4.0.0 Source

Configuration for a Cloudflare Durable Object SQLite client, including either a SqlStorage handle or the full DurableObjectStorage for transaction support, span attributes, and query/result name transforms.

Signature

interface SqliteClientConfig {
  readonly db?: any;
  readonly spanAttributes?: Record<string, unknown>;
  readonly storage?: any;
  readonly transformQueryNames?: (str: string) => string;
  readonly transformResultNames?: (str: string) => string;
}

Services

SqliteClient

Added in v4.0.0 Source

Service tag for the Cloudflare Durable Object SQLite client service.

When to use

Use to access or provide a Durable Object SQLite client through the Effect context.

Signature

declare const SqliteClient: Service<SqliteClient, SqliteClient>;

SqliteClient interface

Added in v4.0.0 Source

Cloudflare Durable Object SQLite client service, extending SqlClient with its configuration. updateValues is not supported.

Signature

interface SqliteClient extends SqlClient {
  <A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
  (value: string): Identifier;
  readonly "~@effect/sql-sqlite-do/SqliteClient": "~@effect/sql-sqlite-do/SqliteClient";
  readonly config: SqliteClientConfig;
  readonly updateValues: never;
}

Type IDs

TypeId

Added in v4.0.0 Source

Runtime type identifier used to mark Cloudflare Durable Object SqliteClient values.

Signature

declare const TypeId: TypeId;

TypeId type

Added in v4.0.0 Source

Type-level identifier used to mark Cloudflare Durable Object SqliteClient values.

Signature

type TypeId = "~@effect/sql-sqlite-do/SqliteClient";