| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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, andCancelare plain records of closures rather than a class-parameterised type and its associated types.- OIDs are a plain
Word32and row/column/parameter indices and LoFds are a plainInt32, rather than the C-specific newtypes of the original. - Ambiguous, rarely-useful helpers (e.g.
resStatus) are omitted,libpqVersionis omitted too. - There's no
invalidOidconstant. It's just 0. unescapeByteais a field ofAdapterrather than a connection-independent top-level function, since its implementation is adapter-specific.
Synopsis
- data Adapter = Adapter {
- name :: Text
- connectdb :: ByteString -> IO Connection
- connectStart :: ByteString -> IO Connection
- newNullConnection :: IO Connection
- unescapeBytea :: ByteString -> IO (Maybe ByteString)
- data Connection = Connection {
- connectPoll :: IO PollingStatus
- isNullConnection :: Bool
- finish :: IO ()
- reset :: IO ()
- resetStart :: IO Bool
- resetPoll :: IO PollingStatus
- db :: IO (Maybe ByteString)
- user :: IO (Maybe ByteString)
- pass :: IO (Maybe ByteString)
- host :: IO (Maybe ByteString)
- port :: IO (Maybe ByteString)
- options :: IO (Maybe ByteString)
- status :: IO ConnStatus
- transactionStatus :: IO TransactionStatus
- parameterStatus :: ByteString -> IO (Maybe ByteString)
- protocolVersion :: IO Int
- serverVersion :: IO Int
- errorMessage :: IO (Maybe ByteString)
- socket :: IO (Maybe Fd)
- backendPID :: IO Int32
- connectionNeedsPassword :: IO Bool
- connectionUsedPassword :: IO Bool
- exec :: ByteString -> IO (Maybe Result)
- execParams :: ByteString -> [Maybe (Word32, ByteString, Format)] -> Format -> IO (Maybe Result)
- prepare :: ByteString -> ByteString -> Maybe [Word32] -> IO (Maybe Result)
- execPrepared :: ByteString -> [Maybe (ByteString, Format)] -> Format -> IO (Maybe Result)
- describePrepared :: ByteString -> IO (Maybe Result)
- describePortal :: ByteString -> IO (Maybe Result)
- escapeStringConn :: ByteString -> IO (Maybe ByteString)
- escapeByteaConn :: ByteString -> IO (Maybe ByteString)
- escapeIdentifier :: ByteString -> IO (Maybe ByteString)
- sendQuery :: ByteString -> IO Bool
- sendQueryParams :: ByteString -> [Maybe (Word32, ByteString, Format)] -> Format -> IO Bool
- sendPrepare :: ByteString -> ByteString -> Maybe [Word32] -> IO Bool
- sendQueryPrepared :: ByteString -> [Maybe (ByteString, Format)] -> Format -> IO Bool
- sendDescribePrepared :: ByteString -> IO Bool
- sendDescribePortal :: ByteString -> IO Bool
- getResult :: IO (Maybe Result)
- consumeInput :: IO Bool
- isBusy :: IO Bool
- setnonblocking :: Bool -> IO Bool
- isnonblocking :: IO Bool
- setSingleRowMode :: IO Bool
- flush :: IO FlushStatus
- pipelineStatus :: IO PipelineStatus
- enterPipelineMode :: IO Bool
- exitPipelineMode :: IO Bool
- pipelineSync :: IO Bool
- sendFlushRequest :: IO Bool
- getCancel :: IO (Maybe Cancel)
- notifies :: IO (Maybe Notify)
- disableNoticeReporting :: IO ()
- enableNoticeReporting :: IO ()
- getNotice :: IO (Maybe ByteString)
- putCopyData :: ByteString -> IO CopyInResult
- putCopyEnd :: Maybe ByteString -> IO CopyInResult
- getCopyData :: Bool -> IO CopyOutResult
- loCreat :: IO (Maybe Word32)
- loCreate :: Word32 -> IO (Maybe Word32)
- loImport :: FilePath -> IO (Maybe Word32)
- loImportWithOid :: FilePath -> Word32 -> IO (Maybe Word32)
- loExport :: Word32 -> FilePath -> IO (Maybe ())
- loOpen :: Word32 -> IOMode -> IO (Maybe Int32)
- loWrite :: Int32 -> ByteString -> IO (Maybe Int)
- loRead :: Int32 -> Int -> IO (Maybe ByteString)
- loSeek :: Int32 -> SeekMode -> Int -> IO (Maybe Int)
- loTell :: Int32 -> IO (Maybe Int)
- loTruncate :: Int32 -> Int -> IO (Maybe ())
- loClose :: Int32 -> IO (Maybe ())
- loUnlink :: Word32 -> IO (Maybe ())
- clientEncoding :: IO ByteString
- setClientEncoding :: ByteString -> IO Bool
- setErrorVerbosity :: Verbosity -> IO Verbosity
- data Result = Result {
- resultStatus :: IO ExecStatus
- resultErrorMessage :: IO (Maybe ByteString)
- resultErrorField :: FieldCode -> IO (Maybe ByteString)
- unsafeFreeResult :: IO ()
- ntuples :: IO Int32
- nfields :: IO Int32
- fname :: Int32 -> IO (Maybe ByteString)
- fnumber :: ByteString -> IO (Maybe Int32)
- ftable :: Int32 -> IO Word32
- ftablecol :: Int32 -> IO Int32
- fformat :: Int32 -> IO Format
- ftype :: Int32 -> IO Word32
- fmod :: Int32 -> IO Int
- fsize :: Int32 -> IO Int
- getvalue :: Int32 -> Int32 -> IO (Maybe ByteString)
- getvalue' :: Int32 -> Int32 -> IO (Maybe ByteString)
- getisnull :: Int32 -> Int32 -> IO Bool
- getlength :: Int32 -> Int32 -> IO Int
- nparams :: IO Int32
- paramtype :: Int32 -> IO Word32
- cmdStatus :: IO (Maybe ByteString)
- cmdTuples :: IO (Maybe ByteString)
- data Cancel = Cancel {
- cancel :: IO (Either ByteString ())
- data Format
- data ExecStatus
- data ConnStatus
- data TransactionStatus
- data PollingStatus
- data PipelineStatus
- data FieldCode
- data Verbosity
- data FlushStatus
- data CopyInResult
- data CopyOutResult
- data Notify = Notify {
- relname :: ByteString
- bePid :: Int32
- extra :: ByteString
Adapter
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
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
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
Format of a parameter or result column: textual or binary.
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
|
| 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 |
| PipelineSync | The |
| PipelineAbort | The |
Instances
| Bounded ExecStatus Source # | |
Defined in Pqi | |
| Enum ExecStatus Source # | |
Defined in Pqi Methods succ :: ExecStatus -> ExecStatus # pred :: ExecStatus -> ExecStatus # toEnum :: Int -> ExecStatus # fromEnum :: ExecStatus -> Int # enumFrom :: ExecStatus -> [ExecStatus] # enumFromThen :: ExecStatus -> ExecStatus -> [ExecStatus] # enumFromTo :: ExecStatus -> ExecStatus -> [ExecStatus] # enumFromThenTo :: ExecStatus -> ExecStatus -> ExecStatus -> [ExecStatus] # | |
| Show ExecStatus Source # | |
Defined in Pqi Methods showsPrec :: Int -> ExecStatus -> ShowS # show :: ExecStatus -> String # showList :: [ExecStatus] -> ShowS # | |
| Eq ExecStatus Source # | |
Defined in Pqi | |
| Ord ExecStatus Source # | |
Defined in Pqi Methods compare :: ExecStatus -> ExecStatus -> Ordering # (<) :: ExecStatus -> ExecStatus -> Bool # (<=) :: ExecStatus -> ExecStatus -> Bool # (>) :: ExecStatus -> ExecStatus -> Bool # (>=) :: ExecStatus -> ExecStatus -> Bool # max :: ExecStatus -> ExecStatus -> ExecStatus # min :: ExecStatus -> ExecStatus -> ExecStatus # | |
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. |
Instances
| Bounded ConnStatus Source # | |
Defined in Pqi | |
| Enum ConnStatus Source # | |
Defined in Pqi Methods succ :: ConnStatus -> ConnStatus # pred :: ConnStatus -> ConnStatus # toEnum :: Int -> ConnStatus # fromEnum :: ConnStatus -> Int # enumFrom :: ConnStatus -> [ConnStatus] # enumFromThen :: ConnStatus -> ConnStatus -> [ConnStatus] # enumFromTo :: ConnStatus -> ConnStatus -> [ConnStatus] # enumFromThenTo :: ConnStatus -> ConnStatus -> ConnStatus -> [ConnStatus] # | |
| Show ConnStatus Source # | |
Defined in Pqi Methods showsPrec :: Int -> ConnStatus -> ShowS # show :: ConnStatus -> String # showList :: [ConnStatus] -> ShowS # | |
| Eq ConnStatus Source # | |
Defined in Pqi | |
| Ord ConnStatus Source # | |
Defined in Pqi Methods compare :: ConnStatus -> ConnStatus -> Ordering # (<) :: ConnStatus -> ConnStatus -> Bool # (<=) :: ConnStatus -> ConnStatus -> Bool # (>) :: ConnStatus -> ConnStatus -> Bool # (>=) :: ConnStatus -> ConnStatus -> Bool # max :: ConnStatus -> ConnStatus -> ConnStatus # min :: ConnStatus -> ConnStatus -> ConnStatus # | |
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
data PollingStatus Source #
Result of a non-blocking connection-polling step.
Constructors
| PollingFailed | |
| PollingReading | |
| PollingWriting | |
| PollingOk |
Instances
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. |
Instances
Field identifier for the structured fields of an error report, as accepted
by PQresultErrorField.
Constructors
Instances
| Bounded FieldCode Source # | |
| Enum FieldCode Source # | |
Defined in Pqi Methods succ :: FieldCode -> FieldCode # pred :: FieldCode -> FieldCode # fromEnum :: FieldCode -> Int # enumFrom :: FieldCode -> [FieldCode] # enumFromThen :: FieldCode -> FieldCode -> [FieldCode] # enumFromTo :: FieldCode -> FieldCode -> [FieldCode] # enumFromThenTo :: FieldCode -> FieldCode -> FieldCode -> [FieldCode] # | |
| Show FieldCode Source # | |
| Eq FieldCode Source # | |
| Ord FieldCode Source # | |
Verbosity of error reporting, as set by PQsetErrorVerbosity.
Constructors
| ErrorsTerse | |
| ErrorsDefault | |
| ErrorsVerbose |
Instances
| Bounded Verbosity Source # | |
| Enum Verbosity Source # | |
Defined in Pqi Methods succ :: Verbosity -> Verbosity # pred :: Verbosity -> Verbosity # fromEnum :: Verbosity -> Int # enumFrom :: Verbosity -> [Verbosity] # enumFromThen :: Verbosity -> Verbosity -> [Verbosity] # enumFromTo :: Verbosity -> Verbosity -> [Verbosity] # enumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity] # | |
| Show Verbosity Source # | |
| Eq Verbosity Source # | |
| Ord Verbosity Source # | |
data FlushStatus Source #
Result of attempting to flush the output buffer in non-blocking mode.
Constructors
| FlushOk | |
| FlushFailed | |
| FlushWriting |
Instances
data CopyInResult Source #
Result of PQputCopyData/PQputCopyEnd.
Constructors
| CopyInOk | |
| CopyInError | |
| CopyInWouldBlock |
Instances
data CopyOutResult Source #
Result of PQgetCopyData.
Constructors
| CopyOutRow ByteString | |
| CopyOutWouldBlock | |
| CopyOutDone | |
| CopyOutError |
Instances
| Show CopyOutResult Source # | |
Defined in Pqi Methods showsPrec :: Int -> CopyOutResult -> ShowS # show :: CopyOutResult -> String # showList :: [CopyOutResult] -> ShowS # | |
| Eq CopyOutResult Source # | |
Defined in Pqi Methods (==) :: CopyOutResult -> CopyOutResult -> Bool # (/=) :: CopyOutResult -> CopyOutResult -> Bool # | |
| Ord CopyOutResult Source # | |
Defined in Pqi Methods compare :: CopyOutResult -> CopyOutResult -> Ordering # (<) :: CopyOutResult -> CopyOutResult -> Bool # (<=) :: CopyOutResult -> CopyOutResult -> Bool # (>) :: CopyOutResult -> CopyOutResult -> Bool # (>=) :: CopyOutResult -> CopyOutResult -> Bool # max :: CopyOutResult -> CopyOutResult -> CopyOutResult # min :: CopyOutResult -> CopyOutResult -> CopyOutResult # | |