SqliteClient.ts
SqliteClient.ts overview
Section titled “SqliteClient.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”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>Since v4.0.0
makeMemory
Section titled “makeMemory”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>Since v4.0.0
layers
Section titled “layers”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>Since v4.0.0
layerConfig
Section titled “layerConfig”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>Since v4.0.0
layerMemory
Section titled “layerMemory”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>Since v4.0.0
layerMemoryConfig
Section titled “layerMemoryConfig”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>Since v4.0.0
models
Section titled “models”SqliteClient (interface)
Section titled “SqliteClient (interface)”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}Since v4.0.0
SqliteClientConfig (interface)
Section titled “SqliteClientConfig (interface)”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}Since v4.0.0
SqliteClientMemoryConfig (interface)
Section titled “SqliteClientMemoryConfig (interface)”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}Since v4.0.0
services
Section titled “services”SqliteClient
Section titled “SqliteClient”Service tag for the SQLite WASM client.
Signature
declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>Since v4.0.0
transferables
Section titled “transferables”Transferables
Section titled “Transferables”Fiber reference that stores transferables to include with worker-backed SQLite WASM query messages.
Signature
declare const Transferables: Context.Reference<ReadonlyArray<Transferable>>Since v4.0.0
withTransferables
Section titled “withTransferables”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>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Runtime identifier attached to SQLite WASM client values.
Signature
declare const TypeId: "~@effect/sql-sqlite-wasm/SqliteClient"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Type-level identifier for SQLite WASM client values.
Signature
type TypeId = "~@effect/sql-sqlite-wasm/SqliteClient"Since v4.0.0