pqi-0.1.0.2: Driver-agnostic interface to the PostgreSQL libpq API
Safe HaskellNone
LanguageHaskell2010

Pqi

Description

A driver-agnostic reproduction of the postgresql-libpq API (version 0.11, the pipelining-capable release).

The connection is reified as a single concrete record type, Connection, whose fields are the closures that implement each capability. Result accessors live in the independent Result record, and cancellation handles in the Cancel record. A Connection produces Results and Cancels directly (via its exec, getResult, getCancel, etc. fields) — there is no type-level indirection: the whole package defines exactly one Connection, one Result, and one Cancel type.

Each field of these records is a closure that has already captured whatever underlying handle (e.g. a C PGconn pointer, or a native socket) it needs; from the caller's perspective a Connection is simply a bundle of IO actions. This trades the old class-based polymorphism for a concrete, monomorphic value that can be passed around, stored, and constructed by whichever adapter package is in use.

Adapter packages (e.g. pqi-ffi, pqi-native) are responsible for constructing Connection values — this package does not provide any connectdb/connectStart/newNullConnection-style constructors of its own, since those don't have a connection to close over yet. Instead, each adapter package exports a single top-level value of type Adapter, bundling its connection-establishing functions together so that callers who need to be adapter-agnostic (e.g. a differential test harness, or a consumer that lets its own users pick an adapter) can hold onto one value rather than a family of adapter-qualified functions.

Function names, argument order, and semantics mirror the API of the C library binding postgresql-libpq. The only deliberate departures are:

  • Connection, Result, and Cancel are plain records of closures rather than a class-parameterised type and its associated types.
  • OIDs are a plain Word32 and row/column/parameter indices and LoFds are a plain Int32, rather than the C-specific newtypes of the original.
  • Ambiguous, rarely-useful helpers (e.g. resStatus) are omitted, libpqVersion is omitted too.
  • There's no invalidOid constant. It's just 0.
  • unescapeBytea is a field of Adapter rather than a connection-independent top-level function, since its implementation is adapter-specific.
Synopsis

Adapter

data Adapter Source #

An adapter package's connection-establishing functions, bundled into one value.

Connection, Result, and Cancel are per-connection and per-result; they carry no information about which adapter produced them, so they cannot themselves stand in for "the FFI adapter" or "the native adapter" the way a driver-parameterised type could. Adapter fills that gap: it is the one value that names an adapter and knows how to bring a Connection into being, so a caller that must remain adapter-agnostic (a differential test harness comparing two adapters, or a library that lets its users pick an adapter at runtime) can hold onto a single Adapter value instead of a family of adapter-qualified top-level functions.

Each adapter package (e.g. pqi-ffi, pqi-native) exports exactly one top-level value of this type, conventionally named adapter.

Constructors

Adapter 

Fields

Connection

data Connection Source #

The single flat capability record: closing, inspecting, querying, escaping, async commands, pipelining, cancellation handle creation, notifications, copy, large objects, and control.

There is exactly one Connection type in the whole pqi package. Adapter packages (e.g. pqi-ffi, pqi-native) construct values of this type from their own top-level connectdb/connectStart functions, closing each field over their own underlying connection representation (e.g. a C PGconn pointer, or a native socket). This module only defines the shape; it does not construct any connections.

See the field-level documentation for the semantics of each capability.

Constructors

Connection 

Fields

Result inspection

data Result Source #

Result-accessor closures, independent of the connection that produced the result. This allows row decoders and projection functions (such as observeResult in pqi-conformance) to operate on any result value without knowing the originating connection or adapter.

There is exactly one Result type in the whole pqi package; adapters construct values of this type by closing each field over their own underlying result representation (e.g. a C PGresult pointer).

Constructors

Result 

Fields

Cancellation

data Cancel Source #

A cancellation handle, isolated from the connection that produced it.

There is exactly one Cancel type in the whole pqi package; adapters construct values of this type by closing over their own underlying cancellation handle.

Constructors

Cancel 

Fields

Shared types

data Format Source #

Format of a parameter or result column: textual or binary.

Constructors

Text 
Binary 

Instances

Instances details
Bounded Format Source # 
Instance details

Defined in Pqi

Enum Format Source # 
Instance details

Defined in Pqi

Show Format Source # 
Instance details

Defined in Pqi

Eq Format Source # 
Instance details

Defined in Pqi

Methods

(==) :: Format -> Format -> Bool #

(/=) :: Format -> Format -> Bool #

Ord Format Source # 
Instance details

Defined in Pqi

data ExecStatus Source #

Status of a command result, as reported by PQresultStatus.

Constructors

EmptyQuery

The string sent to the server was empty.

CommandOk

Successful completion of a command returning no data.

TuplesOk

Successful completion of a command returning data (such as a SELECT or SHOW).

CopyOut

Copy Out (from server) data transfer started.

CopyIn

Copy In (to server) data transfer started.

CopyBoth

Copy In/Out data transfer started.

BadResponse

The server's response was not understood.

NonfatalError

A nonfatal error (a notice or warning) occurred.

FatalError

A fatal error occurred.

SingleTuple

The Result contains a single result tuple from the current command. This status occurs only when single-row mode has been selected for the query.

PipelineSync

The Result represents a synchronization point in pipeline mode, requested by pipelineSync. This status occurs only in pipeline mode.

PipelineAbort

The Result represents a pipeline that has received an error from the server. getResult must be called repeatedly, and each time it will return this status code until the end of the current pipeline, at which point it will return PipelineSync and normal processing can resume.

data ConnStatus Source #

Status of a connection, as reported by PQstatus.

Constructors

ConnectionOk

The connection is ready.

ConnectionBad

The connection procedure has failed.

ConnectionStarted

Waiting for connection to be made.

ConnectionMade

Connection OK; waiting to send.

ConnectionAwaitingResponse

Waiting for a response from the server.

ConnectionAuthOk

Received authentication; waiting for backend start-up to finish.

ConnectionSetEnv

Negotiating environment-driven parameter settings.

ConnectionSSLStartup

Negotiating SSL encryption.

data TransactionStatus Source #

Current in-transaction status of the server, as reported by PQtransactionStatus.

Constructors

TransIdle

Currently idle.

TransActive

A command is in progress.

TransInTrans

Idle, within a transaction block.

TransInError

Idle, within a failed transaction.

TransUnknown

Connection is bad.

Instances

Instances details
Bounded TransactionStatus Source # 
Instance details

Defined in Pqi

Enum TransactionStatus Source # 
Instance details

Defined in Pqi

Show TransactionStatus Source # 
Instance details

Defined in Pqi

Eq TransactionStatus Source # 
Instance details

Defined in Pqi

Ord TransactionStatus Source # 
Instance details

Defined in Pqi

data PollingStatus Source #

Result of a non-blocking connection-polling step.

data PipelineStatus Source #

Pipeline-mode status of a connection, as reported by PQpipelineStatus.

Constructors

PipelineOn

The connection is in pipeline mode.

PipelineOff

The connection is not in pipeline mode.

PipelineAborted

The connection is in pipeline mode and an error occurred while processing the current pipeline.

data FieldCode Source #

Field identifier for the structured fields of an error report, as accepted by PQresultErrorField.

Instances

Instances details
Bounded FieldCode Source # 
Instance details

Defined in Pqi

Enum FieldCode Source # 
Instance details

Defined in Pqi

Show FieldCode Source # 
Instance details

Defined in Pqi

Eq FieldCode Source # 
Instance details

Defined in Pqi

Ord FieldCode Source # 
Instance details

Defined in Pqi

data Verbosity Source #

Verbosity of error reporting, as set by PQsetErrorVerbosity.

Instances

Instances details
Bounded Verbosity Source # 
Instance details

Defined in Pqi

Enum Verbosity Source # 
Instance details

Defined in Pqi

Show Verbosity Source # 
Instance details

Defined in Pqi

Eq Verbosity Source # 
Instance details

Defined in Pqi

Ord Verbosity Source # 
Instance details

Defined in Pqi

data FlushStatus Source #

Result of attempting to flush the output buffer in non-blocking mode.

data Notify Source #

An asynchronous notification, as returned by notifies.

Constructors

Notify 

Instances

Instances details
Show Notify Source # 
Instance details

Defined in Pqi

Eq Notify Source # 
Instance details

Defined in Pqi

Methods

(==) :: Notify -> Notify -> Bool #

(/=) :: Notify -> Notify -> Bool #

Ord Notify Source # 
Instance details

Defined in Pqi