| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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,connectStartandnewNullConnectionare its fields, not top-level functions. unescapeByteaandresStatusareAdapterfields too. They take no connection, but their implementations are adapter-specific.Connection,ResultandCancelare records of closures rather than opaque handles fed to top-level functions. Call sites are unchanged:exec connection sqlselects a field and applies it.OidisWord32;Row,Column,LoFdareInt32. NoinvalidOidconstant - it is0.libpqVersionis omitted.
Synopsis
- data Adapter = Adapter {
- name :: Text
- connectdb :: ByteString -> IO Connection
- connectStart :: ByteString -> IO Connection
- newNullConnection :: IO Connection
- unescapeBytea :: ByteString -> IO (Maybe ByteString)
- resStatus :: ExecStatus -> IO 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 {}
Adapter
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
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
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
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 # | |