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

PgPool unstable

Pools of native PgConnection sessions.

6 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a scoped PostgreSQL session pool.

Details

Connections are opened lazily up to maxConnections and released down to minConnections after idleTimeout without use. Closing the scope shuts the pool down and releases every session.

With SpanPropagationEnabled, a statement that waited for a new session gets a db.connect child span covering the part of the connect it waited for.

Signature

declare const make: (...args: [options: Config]) => Effect<PgPool, SqlError, Scope>

Models

Config

interface unstable
Since v4.0.0

Connection and sizing settings for a PostgreSQL session pool.

Details

The defaults are 0 to 10 connections and a 60-second idle timeout. connectionTTL replaces connections that exceed the configured lifetime. Every connection is used at least once, so a TTL of zero disables reuse. acquireTimeout bounds how long a checkout waits for a free connection; by default it waits indefinitely.

With multiplex enabled, fibers may share pooled connections for pipelined queries. Reserved connections remain exclusive. Without multiplexing, every checkout is exclusive.

Signature

interface Config extends Config {
readonly acquireTimeout?: Input;
readonly connectionTTL?: Input;
readonly idleTimeout?: Input;
readonly maxConnections?: number;
readonly minConnections?: number;
readonly multiplexConcurrency?: number;
}

PgPool

interface unstable
Since v4.0.0

A PostgreSQL session pool.

Signature

interface PgPool {
readonly "~@effect/sql-pg/PgPool": "~@effect/sql-pg/PgPool";
readonly config: Config;
readonly get: Effect<PgConnection, SqlError, Scope>;
readonly invalidate: (connection: PgConnection) => Effect<void>;
readonly reserve: Effect<PgConnection, SqlError, Scope>;
readonly use: <A, E, R>(f: (connection: PgConnection) => Effect<A, E, R>) => Effect<A, SqlError | E, R>;
}

Services

PgPool

unstable
Since v4.0.0

The service tag for PgPool.

Signature

declare const PgPool: Service<PgPool, PgPool>

Type IDs

TypeId

unstable
Since v4.0.0

The runtime type identifier for PgPool.

Signature

declare const TypeId: TypeId

TypeId

type unstable
Since v4.0.0

The type-level identifier for PgPool.

Signature

type TypeId = "~@effect/sql-pg/PgPool"