Skip to content

SqliteClient.ts

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.

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 const make: (
options: SqliteClientConfig
) => Effect.Effect<SqliteClient, SqlError, Scope.Scope | Reactivity.Reactivity>

Source

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 const makeMemory: (
options: SqliteClientMemoryConfig
) => Effect.Effect<SqliteClient, SqlError, Scope.Scope | Reactivity.Reactivity>

Source

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 const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient, SqlError>

Source

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 const layerConfig: (
config: Config.Wrap<SqliteClientConfig>
) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError>

Source

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 const layerMemory: (config: SqliteClientMemoryConfig) => Layer.Layer<SqliteClient | Client.SqlClient, SqlError>

Source

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 const layerMemoryConfig: (
config: Config.Wrap<SqliteClientMemoryConfig>
) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError>

Source

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

export interface SqliteClient extends Client.SqlClient {
readonly [TypeId]: TypeId
readonly config: SqliteClientMemoryConfig
readonly export: Effect.Effect<Uint8Array, SqlError>
readonly import: (data: Uint8Array) => Effect.Effect<void, SqlError>
/** Not supported in sqlite */
readonly updateValues: never
}

Source

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

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

Source

Since v4.0.0

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

Signature

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

Source

Since v4.0.0

Service tag for the SQLite WASM client.

Signature

declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>

Source

Since v4.0.0

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

Signature

declare const Transferables: Context.Reference<ReadonlyArray<Transferable>>

Source

Since v4.0.0

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

Signature

declare const withTransferables: (
transferables: ReadonlyArray<Transferable>
) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>

Source

Since v4.0.0

Runtime identifier attached to SQLite WASM client values.

Signature

declare const TypeId: "~@effect/sql-sqlite-wasm/SqliteClient"

Source

Since v4.0.0

Type-level identifier for SQLite WASM client values.

Signature

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

Source

Since v4.0.0