Skip to content

SqlConnection

Low-level SQL connection contract used by driver integrations.

A Connection is the driver-facing layer under SqlClient. It executes already-compiled SQL with positional parameters and can return transformed rows, raw driver results, streams, value arrays, or unprepared statement results. This module also defines the scoped connection acquirer type, the connection service tag, and the generic row shape.

4 exports Added in v4.0.0 Source

Models

Acquirer type

Added in v4.0.0 Source

Scoped effect that acquires a Connection, may fail with SqlError, and requires a Scope for release.

Signature

type Acquirer = Effect<Connection, SqlError, Scope>;

Connection interface

Added in v4.0.0 Source

Low-level SQL driver connection capable of executing compiled SQL as transformed rows, raw results, streams, value arrays, or unprepared statements.

Signature

interface Connection {
  readonly execute: (sql: string, params: readonly Array<unknown>, transformRows: <A extends object>(row: readonly Array<A>) => readonly Array<A> | undefined) => Effect<readonly Array<any>, SqlError>;
  readonly executeRaw: (sql: string, params: readonly Array<unknown>) => Effect<unknown, SqlError>;
  readonly executeStream: (sql: string, params: readonly Array<unknown>, transformRows: <A extends object>(row: readonly Array<A>) => readonly Array<A> | undefined) => Stream<any, SqlError>;
  readonly executeUnprepared: (sql: string, params: readonly Array<unknown>, transformRows: <A extends object>(row: readonly Array<A>) => readonly Array<A> | undefined) => Effect<readonly Array<any>, SqlError>;
  readonly executeValues: (sql: string, params: readonly Array<unknown>) => Effect<readonly Array<readonly Array<unknown>>, SqlError>;
  readonly executeValuesUnprepared: (sql: string, params: readonly Array<unknown>) => Effect<readonly Array<readonly Array<unknown>>, SqlError>;
}

Row type

Added in v4.0.0 Source

Generic SQL row shape mapping column names to unknown values.

Signature

type Row = {
  [column: string]: unknown;
};

Services

Connection

Added in v4.0.0 Source

Service tag for a low-level SQL Connection.

Signature

declare const Connection: Service<Connection, Connection>;