Skip to content

SqliteClient

Connects Effect SQL to SQLite on Node.js using node:sqlite.

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

9 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

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 function make(options: SqliteClientConfig): Effect<SqliteClient, never, Scope | Reactivity>;

Layers

layer

Added in v4.0.0 Source

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

Signature

declare function layer(config: SqliteClientConfig): Layer<SqliteClient | SqlClient>;

layerConfig

Added in v4.0.0 Source

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

Signature

declare function layerConfig(
  config:
    | {
        readonly disableWAL?: Config<boolean | undefined>;
        readonly filename: Config<string>;
        readonly prepareCacheSize?: Config<number | undefined>;
        readonly prepareCacheTTL?: Config<Input | undefined>;
        readonly readonly?: 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

BackupMetadata interface

Added in v4.0.0 Source

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

Signature

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

SqliteClientConfig interface

Added in v4.0.0 Source

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

Signature

interface SqliteClientConfig {
  readonly disableWAL?: boolean;
  readonly filename: string;
  readonly prepareCacheSize?: number;
  readonly prepareCacheTTL?: Input;
  readonly readonly?: 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 node SQLite client implementation.

Signature

declare const SqliteClient: Service<SqliteClient, SqliteClient>;

SqliteClient interface

Added in v4.0.0 Source

Node SQLite client service, extending SqlClient with database export, backup, 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-node/SqliteClient": "~@effect/sql-sqlite-node/SqliteClient";
  readonly backup: (destination: string) => Effect<BackupMetadata, SqlError>;
  readonly config: SqliteClientConfig;
  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 Node SqliteClient values.

Signature

declare const TypeId: TypeId;

TypeId type

Added in v4.0.0 Source

Type-level identifier used to mark Node SqliteClient values.

Signature

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