Skip to content

SqliteClient

Connects Effect SQL to SQLite in React Native using @op-engineering/op-sqlite.

This module opens an on-device SQLite database and exposes it as both SqliteClient and the generic Effect SQL client. It serializes access, supports normal and value-based queries, and uses the driver's synchronous query API by default. AsyncQuery and withAsyncQuery switch a scoped effect to the driver's asynchronous query API. Streaming queries and updateValues are not supported by this driver.

10 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates a scoped React Native SQLite client from the supplied configuration, using a single serialized connection and honoring AsyncQuery for query execution.

Signature

declare function make(options: SqliteClientConfig): Effect<SqliteClient, never, Scope | Reactivity>;

Layers

layer

Added in v4.0.0 Source

Builds a layer from a React Native 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 React Native SqliteClient service and the generic SqlClient service.

Signature

declare function layerConfig(
  config:
    | {
        readonly encryptionKey?: Config<string | undefined>;
        readonly filename: Config<string>;
        readonly location?: Config<string | 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 React Native SQLite client, including the database filename, optional location and encryption key, span attributes, and query/result name transforms.

Signature

interface SqliteClientConfig {
  readonly encryptionKey?: string;
  readonly filename: string;
  readonly location?: string;
  readonly spanAttributes?: Record<string, unknown>;
  readonly transformQueryNames?: (str: string) => string;
  readonly transformResultNames?: (str: string) => string;
}

Providing Services

Runs an effect with AsyncQuery enabled, causing React Native SQLite queries in that effect to use the asynchronous driver API.

Signature

declare function withAsyncQuery<R, E, A>(effect: Effect<A, E, R>): Effect<A, E, Exclude<R, never>>;

Services

AsyncQuery

Added in v4.0.0 Source

Fiber reference that makes the React Native SQLite client run queries through the asynchronous execute API instead of executeSync.

When to use

Use to switch React Native SQLite query execution to the asynchronous driver API for a scoped effect.

Signature

declare const AsyncQuery: Reference<boolean>;

SqliteClient

Added in v4.0.0 Source

Service tag for the React Native SQLite client.

Signature

declare const SqliteClient: Service<SqliteClient, SqliteClient>;

SqliteClient interface

Added in v4.0.0 Source

React Native SQLite client service interface, extending SqlClient with its configuration and marking updateValues as unsupported for SQLite.

Signature

interface SqliteClient extends SqlClient {
  <A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
  (value: string): Identifier;
  readonly "~@effect/sql-sqlite-react-native/SqliteClient": "~@effect/sql-sqlite-react-native/SqliteClient";
  readonly config: SqliteClientConfig;
  readonly updateValues: never;
}

Type IDs

TypeId

Added in v4.0.0 Source

Runtime identifier attached to SQLite React Native client values.

Signature

declare const TypeId: TypeId;

TypeId type

Added in v4.0.0 Source

Type-level identifier for SQLite React Native client values.

Signature

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