Skip to content

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 supports database export and extension loading. Streaming queries and updateValues are not supported by this driver.

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 by default and serializing access. 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 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 behavior, span attributes, and query/result name transforms.

Signature

interface SqliteClientConfig {
  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";