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

Pqi

Description

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

Connection, Result and Cancel are records of IO closures, each already closed over the handle it needs (a C PGconn pointer, a native socket, ...).

Connections come from adapter packages - pqi-ffi (C libpq via postgresql-libpq) and pqi-native (pure-Haskell wire protocol) - each exporting one top-level Adapter value. An adapter must be identical to libpq on every protocol-derived value. pqi-conformance enforces that differentially.

Differences from postgresql-libpq

Everything else - names, argument order, semantics - mirrors Database.PostgreSQL.LibPQ.

  • Connection acquisition lives in Adapter: connectdb, connectStart and newNullConnection are its fields, not top-level functions.
  • unescapeBytea and resStatus are Adapter fields too. They take no connection, but their implementations are adapter-specific.
  • Connection, Result and Cancel are records of closures rather than opaque handles fed to top-level functions. Call sites are unchanged: exec connection sql selects a field and applies it.
  • Oid is Word32; Row, Column, LoFd are Int32. No invalidOid constant - it is 0.
  • libpqVersion is omitted.
Synopsis

Adapter

data Adapter Source #

An adapter package's connection-establishing functions, bundled into one value. Each adapter package (e.g. pqi-ffi, pqi-native) exports exactly one value of this type, conventionally named adapter.

This is the only value that identifies an adapter: Connection, Result and Cancel say nothing about which adapter produced them. Callers that must stay adapter-agnostic - a differential test harness, a library letting its users pick a driver at runtime - pass an Adapter around instead of a family of adapter-qualified top-level functions.

Constructors

Adapter 

Fields

Connection

data Connection Source #

One flat capability record: closing, inspecting, querying, escaping, async commands, pipelining, cancellation handles, notifications, copy, large objects, control.

Produced by the connectdb/connectStart/newNullConnection fields of an Adapter, which close each field over their own connection representation (a C PGconn pointer, a native socket, ...).

Constructors

Connection 

Fields

Result inspection

data Result Source #

Result-accessor closures, closed over an adapter's own result representation (e.g. a C PGresult pointer).

Carries no reference to the connection that produced it, so decoders can consume a result without knowing its origin.

Constructors

Result 

Fields

Cancellation

data Cancel Source #

A cancellation handle, isolated from the connection that produced it, hence usable from another thread while that connection is busy.

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.

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