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.
Constructors
Layers
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
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
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
withAsyncQuery
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
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
Service tag for the React Native SQLite client.
Signature
declare const SqliteClient: Service<SqliteClient, SqliteClient>;SqliteClient interface
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
Runtime identifier attached to SQLite React Native client values.
Signature
declare const TypeId: TypeId;Type-level identifier for SQLite React Native client values.
Signature
type TypeId = "~@effect/sql-sqlite-react-native/SqliteClient";
Creates a scoped React Native SQLite client from the supplied configuration, using a single serialized connection and honoring
AsyncQueryfor query execution.