Skip to content

SqliteClient.ts

Connects Effect SQL to SQLite on Node.js using better-sqlite3.

This module opens a SQLite database and exposes it as both SqliteClient and the generic Effect SQL client. It serializes access through one connection, caches prepared statements, enables WAL mode unless disabled, and supports database export, backup, and extension loading. Streaming queries and updateValues are not supported by this driver.

Since v4.0.0



Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL enabled by default and exposing SQLite-specific export, backup, and loadExtension operations.

Signature

declare const make: (
options: SqliteClientConfig
) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>

Source

Since v4.0.0

Builds a layer from a node SQLite client configuration, providing both SqliteClient and the generic SqlClient service.

Signature

declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient>

Source

Since v4.0.0

Builds a layer from an Effect Config value, providing both the node SqliteClient service and the generic SqlClient service.

Signature

declare const layerConfig: (
config: Config.Wrap<SqliteClientConfig>
) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError>

Source

Since v4.0.0

Metadata returned from a Node SQLite backup operation, reporting total and remaining page counts.

Signature

export interface BackupMetadata {
readonly totalPages: number
readonly remainingPages: number
}

Source

Since v4.0.0

Node SQLite client service, extending SqlClient with database export, backup, and extension loading helpers. updateValues is not supported.

Signature

export interface SqliteClient extends Client.SqlClient {
readonly [TypeId]: TypeId
readonly config: SqliteClientConfig
readonly export: Effect.Effect<Uint8Array, SqlError>
readonly backup: (destination: string) => Effect.Effect<BackupMetadata, SqlError>
readonly loadExtension: (path: string) => Effect.Effect<void, SqlError>
/** Not supported in sqlite */
readonly updateValues: never
}

Source

Since v4.0.0

Configuration for a node SQLite client backed by better-sqlite3, including the database filename, read-only mode, statement cache settings, WAL behavior, span attributes, and query/result name transforms.

Signature

export interface SqliteClientConfig {
readonly filename: string
readonly readonly?: boolean | undefined
readonly prepareCacheSize?: number | undefined
readonly prepareCacheTTL?: Duration.Input | undefined
readonly disableWAL?: boolean | undefined
readonly spanAttributes?: Record<string, unknown> | undefined
readonly transformResultNames?: ((str: string) => string) | undefined
readonly transformQueryNames?: ((str: string) => string) | undefined
}

Source

Since v4.0.0

Service tag for the node SQLite client implementation.

Signature

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

Source

Since v4.0.0

Runtime type identifier used to mark Node SqliteClient values.

Signature

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

Source

Since v4.0.0

Type-level identifier used to mark Node SqliteClient values.

Signature

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

Source

Since v4.0.0