Skip to content
Effect Days 2026 Get your ticket

SqliteClient

Connects Effect SQL to SQLite when running on Bun, using bun:sqlite.

This module opens a SQLite database and exposes it as both SqliteClient and the generic Effect SQL client. It serializes access to the database, enables WAL mode unless disabled, and waits up to five seconds for busy databases by default. Explicit transactions on writable connections use BEGIN IMMEDIATE to avoid read-to-write lock upgrades, which serializes them behind other writers even when they only read. Clients opened with readonly: true are unaffected. Busy waits block the event loop because bun:sqlite is synchronous. Database export and extension loading are supported; streaming queries and updateValues are not.

8 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates a scoped Bun SQLite client for a database file, enabling WAL and a 5-second busy timeout by default. Explicit transactions on writable connections take the write lock for their duration, even when they only read; clients opened with readonly: true are unaffected. Streaming queries are not implemented.

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 Bun 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 Bun SQLite client configuration, providing both SqliteClient and SqlClient.

Signature

declare function layerConfig(config: {
readonly busyTimeout?: Config<Input | undefined>;
readonly create?: Config<boolean | undefined>;
readonly disableWAL?: Config<boolean | undefined>;
readonly filename: Config<string>;
readonly readonly?: Config<boolean | undefined>;
readonly readwrite?: 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<SqliteClientConfig>): Layer<SqliteClient | SqlClient, ConfigError>

Models

SqliteClientConfig interface

Added in v4.0.0 Source

Configuration for a Bun SQLite client, including filename, open mode flags, WAL and busy timeout behavior, span attributes, and query/result name transforms.

Signature

interface SqliteClientConfig {
readonly busyTimeout?: Input;
readonly create?: boolean;
readonly disableWAL?: boolean;
readonly filename: string;
readonly readonly?: boolean;
readonly readwrite?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly transformQueryNames?: (str: string) => string;
readonly transformResultNames?: (str: string) => string;
}

Services

SqliteClient

Added in v4.0.0 Source

Service tag for the Bun SQLite client service.

When to use

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

Signature

declare const SqliteClient: Service<SqliteClient, SqliteClient>

SqliteClient interface

Added in v4.0.0 Source

Bun SQLite client service, extending SqlClient with database export and extension loading helpers. 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-bun/SqliteClient": "~@effect/sql-sqlite-bun/SqliteClient";
readonly config: SqliteClientConfig;
readonly export: Effect<Uint8Array<ArrayBufferLike>, SqlError>;
readonly loadExtension: (path: string) => Effect<void, SqlError>;
readonly updateValues: never;
}

Type IDs

TypeId

Added in v4.0.0 Source

Runtime type identifier used to mark Bun SqliteClient values.

Signature

declare const TypeId: TypeId

TypeId type

Added in v4.0.0 Source

Type-level identifier used to mark Bun SqliteClient values.

Signature

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