Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

SqliteClient unstable

Connects Effect SQL to SQLite compiled to WebAssembly with @effect/wa-sqlite.

This module can create an in-memory SQLite database in the current runtime or connect to a worker-backed database, such as the OPFS worker from OpfsWorker. Both clients are exposed as SqliteClient and the generic Effect SQL client, serialize access, support database import and export, and can install reactivity hooks from SQLite update notifications. In-memory clients can stream query rows; worker-backed clients cannot. updateValues is not supported by this driver.

14 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a scoped worker-backed SQLite WASM client, communicating with the configured worker or message port, restarting the scoped connection on worker errors, and exposing database export and import operations.

Signature

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

makeMemory

unstable
Since v4.0.0

Creates a scoped in-memory SQLite WASM client using the memory VFS, serializing access through a semaphore and exposing database export and import operations.

Signature

declare function makeMemory(options: SqliteClientMemoryConfig): Effect<SqliteClient, SqlError, Scope | Reactivity>

Layers

layer

unstable
Since v4.0.0

Builds a layer from a worker-backed SQLite WASM client configuration, providing both SqliteClient and the generic SqlClient service.

Signature

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

layerConfig

unstable
Since v4.0.0

Builds a layer from an Effect Config value, providing both the worker-backed SQLite WASM SqliteClient service and the generic SqlClient service.

Signature

declare function layerConfig(config: {
readonly installReactivityHooks?: Config<boolean | 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>;
readonly worker: Config<Effect<MessagePort | Worker | SharedWorker, never, Scope>>;
} | Config<SqliteClientConfig>): Layer<SqliteClient | SqlClient, SqlError | ConfigError>

layerMemory

unstable
Since v4.0.0

Builds a layer from an in-memory SQLite WASM client configuration, providing both SqliteClient and the generic SqlClient service.

Signature

declare function layerMemory(config: SqliteClientMemoryConfig): Layer<SqliteClient | SqlClient, SqlError>
Since v4.0.0

Builds a layer from an Effect Config value, providing both the in-memory SQLite WASM SqliteClient service and the generic SqlClient service.

Signature

declare function layerMemoryConfig(config: {
readonly installReactivityHooks?: Config<boolean | 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<SqliteClientMemoryConfig>): Layer<SqliteClient | SqlClient, SqlError | ConfigError>

Models

SqliteClientConfig

interface unstable
Since v4.0.0

Configuration for a worker-backed SQLite WASM client, including the scoped worker or message port, optional reactivity hooks, span attributes, and query/result name transforms.

Signature

interface SqliteClientConfig {
readonly installReactivityHooks?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly transformQueryNames?: (str: string) => string;
readonly transformResultNames?: (str: string) => string;
readonly worker: Effect<MessagePort | Worker | SharedWorker, never, Scope>;
}

SqliteClientMemoryConfig

interface unstable
Since v4.0.0

Configuration for an in-memory SQLite WASM client, including optional reactivity hooks, span attributes, and query/result name transforms.

Signature

interface SqliteClientMemoryConfig {
readonly installReactivityHooks?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly transformQueryNames?: (str: string) => string;
readonly transformResultNames?: (str: string) => string;
}

Services

Since v4.0.0

Service tag for the SQLite WASM client.

Signature

declare const SqliteClient: Service<SqliteClient, SqliteClient>

SqliteClient

interface unstable
Since v4.0.0

SQLite WASM client service interface, extending SqlClient with database export and import operations and marking updateValues as unsupported for SQLite.

Signature

interface SqliteClient extends SqlClient {
<A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
(value: string): Identifier;
readonly "~@effect/sql-sqlite-wasm/SqliteClient": "~@effect/sql-sqlite-wasm/SqliteClient";
readonly config: SqliteClientMemoryConfig;
readonly export: Effect<Uint8Array<ArrayBufferLike>, SqlError>;
readonly import: (data: Uint8Array) => Effect<void, SqlError>;
readonly updateValues: never;
}
Since v4.0.0

Fiber reference that stores transferables to include with worker-backed SQLite WASM query messages.

Signature

declare const Transferables: Reference<readonly Array<Transferable>>

Transferables

Since v4.0.0

Runs an effect with the supplied transferables attached to worker-backed SQLite WASM query messages.

Signature

declare function withTransferables(transferables: readonly Array<Transferable>): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>

Type IDs

TypeId

unstable
Since v4.0.0

Runtime identifier attached to SQLite WASM client values.

Signature

declare const TypeId: TypeId

TypeId

type unstable
Since v4.0.0

Type-level identifier for SQLite WASM client values.

Signature

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