Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

PgliteClient unstable

Connects Effect SQL to PGlite, the embedded PostgreSQL-compatible database from @electric-sql/pglite.

This module can create a managed PGlite instance or wrap an existing one and expose it as both PgliteClient and the generic Effect SQL client. The client runs PostgreSQL-style SQL, adds helpers for JSON values and LISTEN/NOTIFY messages, can dump the PGlite data directory, and can refresh PGlite array types. It also provides layers and maps common PostgreSQL-style failures into Effect SQL errors.

13 exports Added in v4.0.0 Source

Constructors

fromClient unstable

Added in v4.0.0 Source

Builds a PgliteClient around an existing PGlite instance, adding SQL client operations, LISTEN/NOTIFY, dump helpers, and serialized access.

Signature

declare function fromClient(options: Base & {
readonly liveClient: PGliteInterface;
}): Effect<PgliteClient, SqlError, Scope | Reactivity>

make unstable

Added in v4.0.0 Source

Creates a scoped PGlite SQL client. When no live client is supplied it creates and closes a PGlite instance; when liveClient is supplied, the caller retains ownership.

Signature

declare function make(options: PgliteClientConfig): Effect<PgliteClient, SqlError, Scope | Reactivity>

makeCompiler unstable

Added in v4.0.0 Source

Creates the PGlite statement compiler, using PostgreSQL $1 placeholders, double-quoted identifiers, returning clauses, and optional JSON value transformation.

Signature

declare function makeCompiler(transform?: (_: string) => string, transformJson: boolean): Compiler

Layers

layer unstable

Added in v4.0.0 Source

Creates a layer from a concrete PGlite client configuration, providing both PgliteClient and SqlClient.

Signature

declare function layer(config?: PgliteClientConfig): Layer<PgliteClient | SqlClient, SqlError>

layerConfig unstable

Added in v4.0.0 Source

Creates a layer from a Config-wrapped PGlite client configuration, providing both PgliteClient and SqlClient.

Signature

declare const layerConfig: (config: Config.Wrap<PgliteClientConfig.ConfigBase>) => Layer.Layer<PgliteClient | Client.SqlClient, Config.ConfigError | SqlError>

layerFrom unstable

Added in v4.0.0 Source

Creates a layer from an effect that acquires a PgliteClient, providing both PgliteClient and SqlClient.

Signature

declare function layerFrom<E, R>(acquire: Effect<PgliteClient, E, R>): Layer<PgliteClient | SqlClient, E, Exclude<R, Scope | Reactivity>>

Models

PgCustom type unstable

Added in v4.0.0 Source

PGlite-specific custom statement fragments supported by the compiler, currently JSON parameter fragments.

Signature

type PgCustom = PgJson

PgliteClientConfig type unstable

Added in v4.0.0 Source

Configuration for a PGlite client, either by supplying PGlite creation options or an existing live PGlite client.

Signature

type PgliteClientConfig = PgliteClientConfig.Create | PgliteClientConfig.Live

Other

PgliteClientConfig unstable

Added in v4.0.0 Source

Namespace containing the configuration variants for PgliteClient.

Services

PgliteClient unstable

Added in v4.0.0 Source

Service tag for the PGlite client service.

When to use

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

Signature

declare const PgliteClient: Service<PgliteClient, PgliteClient>

PgliteClient interface unstable

Added in v4.0.0 Source

PGlite-backed PostgreSQL client service, extending SqlClient with access to the PGlite instance, JSON fragments, LISTEN/NOTIFY, data directory dumps, and array type refresh.

Signature

interface PgliteClient extends SqlClient {
<A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
(value: string): Identifier;
readonly "~@effect/sql-pglite/PgliteClient": "~@effect/sql-pglite/PgliteClient";
readonly config: PgliteClientConfig;
readonly dumpDataDir: (compression?: "none" | "gzip" | "auto") => Effect<File | Blob, SqlError>;
readonly json: (_: unknown) => Fragment;
readonly listen: (channel: string) => Effect<Dequeue<string, never>, SqlError, Scope>;
readonly notify: (channel: string, payload: string) => Effect<void, SqlError>;
readonly pglite: PGliteInterface;
readonly refreshArrayTypes: Effect<void, SqlError>;
}

Type IDs

TypeId unstable

Added in v4.0.0 Source

Runtime type identifier used to mark PgliteClient values.

Signature

declare const TypeId: TypeId

TypeId type unstable

Added in v4.0.0 Source

Type-level identifier used to mark PgliteClient values.

Signature

type TypeId = "~@effect/sql-pglite/PgliteClient"