-- | The FFI adapter, backed by @postgresql-libpq@.
--
-- 'adapter' bundles the three functions that produce a 'Pqi.Connection'
-- whose fields are closures over the underlying C-backed @PGconn@.
-- 'Pqi.Result' and 'Pqi.Cancel' values are constructed the same way, closing
-- over the underlying @PGresult@\/@PGcancel@.
--
-- Each closure is a near-mechanical delegation to the matching
-- @Database.PostgreSQL.LibPQ@ function, with the only work being the
-- conversion between this family's portable types (OIDs as 'Word32', indices
-- as 'Int32', the shared enums) and @postgresql-libpq@'s C-specific newtypes.
module Pqi.Ffi
  ( adapter,
  )
where

import qualified Database.PostgreSQL.LibPQ as Pq
import qualified Pqi
import Pqi.Ffi.Prelude

-- | The FFI adapter.
adapter :: Pqi.Adapter
adapter :: Adapter
adapter =
  Pqi.Adapter
    { name :: Text
Pqi.name = Text
"pqi-ffi",
      connectdb :: ByteString -> IO Connection
Pqi.connectdb = \ByteString
conninfo -> Connection -> Connection
mkConnection (Connection -> Connection) -> IO Connection -> IO Connection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> IO Connection
Pq.connectdb ByteString
conninfo,
      connectStart :: ByteString -> IO Connection
Pqi.connectStart = \ByteString
conninfo -> Connection -> Connection
mkConnection (Connection -> Connection) -> IO Connection -> IO Connection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> IO Connection
Pq.connectStart ByteString
conninfo,
      newNullConnection :: IO Connection
Pqi.newNullConnection = Connection -> Connection
mkConnection (Connection -> Connection) -> IO Connection -> IO Connection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO Connection
Pq.newNullConnection,
      unescapeBytea :: ByteString -> IO (Maybe ByteString)
Pqi.unescapeBytea = \ByteString
input -> ByteString -> IO (Maybe ByteString)
Pq.unescapeBytea ByteString
input,
      resStatus :: ExecStatus -> IO ByteString
Pqi.resStatus = \ExecStatus
execStatus -> ExecStatus -> IO ByteString
Pq.resStatus (ExecStatus -> ExecStatus
toExecStatus ExecStatus
execStatus)
    }

-- | Build a 'Pqi.Connection' whose fields close over the given
-- @postgresql-libpq@ connection handle.
mkConnection :: Pq.Connection -> Pqi.Connection
mkConnection :: Connection -> Connection
mkConnection Connection
c =
  Pqi.Connection
    { connectPoll :: IO PollingStatus
Pqi.connectPoll = PollingStatus -> PollingStatus
fromPollingStatus (PollingStatus -> PollingStatus)
-> IO PollingStatus -> IO PollingStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO PollingStatus
Pq.connectPoll Connection
c,
      isNullConnection :: Bool
Pqi.isNullConnection = Connection -> Bool
Pq.isNullConnection Connection
c,
      finish :: IO ()
Pqi.finish = Connection -> IO ()
Pq.finish Connection
c,
      reset :: IO ()
Pqi.reset = Connection -> IO ()
Pq.reset Connection
c,
      resetStart :: IO Bool
Pqi.resetStart = Connection -> IO Bool
Pq.resetStart Connection
c,
      resetPoll :: IO PollingStatus
Pqi.resetPoll = PollingStatus -> PollingStatus
fromPollingStatus (PollingStatus -> PollingStatus)
-> IO PollingStatus -> IO PollingStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO PollingStatus
Pq.resetPoll Connection
c,
      db :: IO (Maybe ByteString)
Pqi.db = Connection -> IO (Maybe ByteString)
Pq.db Connection
c,
      user :: IO (Maybe ByteString)
Pqi.user = Connection -> IO (Maybe ByteString)
Pq.user Connection
c,
      pass :: IO (Maybe ByteString)
Pqi.pass = Connection -> IO (Maybe ByteString)
Pq.pass Connection
c,
      host :: IO (Maybe ByteString)
Pqi.host = Connection -> IO (Maybe ByteString)
Pq.host Connection
c,
      port :: IO (Maybe ByteString)
Pqi.port = Connection -> IO (Maybe ByteString)
Pq.port Connection
c,
      options :: IO (Maybe ByteString)
Pqi.options = Connection -> IO (Maybe ByteString)
Pq.options Connection
c,
      status :: IO ConnStatus
Pqi.status = ConnStatus -> ConnStatus
fromConnStatus (ConnStatus -> ConnStatus) -> IO ConnStatus -> IO ConnStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO ConnStatus
Pq.status Connection
c,
      transactionStatus :: IO TransactionStatus
Pqi.transactionStatus = TransactionStatus -> TransactionStatus
fromTransactionStatus (TransactionStatus -> TransactionStatus)
-> IO TransactionStatus -> IO TransactionStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO TransactionStatus
Pq.transactionStatus Connection
c,
      parameterStatus :: ByteString -> IO (Maybe ByteString)
Pqi.parameterStatus = \ByteString
name -> Connection -> ByteString -> IO (Maybe ByteString)
Pq.parameterStatus Connection
c ByteString
name,
      protocolVersion :: IO Int
Pqi.protocolVersion = Connection -> IO Int
Pq.protocolVersion Connection
c,
      serverVersion :: IO Int
Pqi.serverVersion = Connection -> IO Int
Pq.serverVersion Connection
c,
      errorMessage :: IO (Maybe ByteString)
Pqi.errorMessage = Connection -> IO (Maybe ByteString)
Pq.errorMessage Connection
c,
      socket :: IO (Maybe Fd)
Pqi.socket = Connection -> IO (Maybe Fd)
Pq.socket Connection
c,
      backendPID :: IO Int32
Pqi.backendPID = CPid -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CPid -> Int32) -> IO CPid -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO CPid
Pq.backendPID Connection
c,
      connectionNeedsPassword :: IO Bool
Pqi.connectionNeedsPassword = Connection -> IO Bool
Pq.connectionNeedsPassword Connection
c,
      connectionUsedPassword :: IO Bool
Pqi.connectionUsedPassword = Connection -> IO Bool
Pq.connectionUsedPassword Connection
c,
      exec :: ByteString -> IO (Maybe Result)
Pqi.exec = \ByteString
sql -> (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> ByteString -> IO (Maybe Result)
Pq.exec Connection
c ByteString
sql,
      execParams :: ByteString
-> [Maybe (Word32, ByteString, Format)]
-> Format
-> IO (Maybe Result)
Pqi.execParams = \ByteString
sql [Maybe (Word32, ByteString, Format)]
params Format
resultFormat ->
        (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection
-> ByteString
-> [Maybe (Oid, ByteString, Format)]
-> Format
-> IO (Maybe Result)
Pq.execParams Connection
c ByteString
sql ((Maybe (Word32, ByteString, Format)
 -> Maybe (Oid, ByteString, Format))
-> [Maybe (Word32, ByteString, Format)]
-> [Maybe (Oid, ByteString, Format)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Word32, ByteString, Format) -> (Oid, ByteString, Format))
-> Maybe (Word32, ByteString, Format)
-> Maybe (Oid, ByteString, Format)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word32, ByteString, Format) -> (Oid, ByteString, Format)
toParam) [Maybe (Word32, ByteString, Format)]
params) (Format -> Format
toFormat Format
resultFormat),
      prepare :: ByteString -> ByteString -> Maybe [Word32] -> IO (Maybe Result)
Pqi.prepare = \ByteString
name ByteString
sql Maybe [Word32]
paramTypes ->
        (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection
-> ByteString -> ByteString -> Maybe [Oid] -> IO (Maybe Result)
Pq.prepare Connection
c ByteString
name ByteString
sql (([Word32] -> [Oid]) -> Maybe [Word32] -> Maybe [Oid]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Word32 -> Oid) -> [Word32] -> [Oid]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Oid
toOid) Maybe [Word32]
paramTypes),
      execPrepared :: ByteString
-> [Maybe (ByteString, Format)] -> Format -> IO (Maybe Result)
Pqi.execPrepared = \ByteString
name [Maybe (ByteString, Format)]
params Format
resultFormat ->
        (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection
-> ByteString
-> [Maybe (ByteString, Format)]
-> Format
-> IO (Maybe Result)
Pq.execPrepared Connection
c ByteString
name ((Maybe (ByteString, Format) -> Maybe (ByteString, Format))
-> [Maybe (ByteString, Format)] -> [Maybe (ByteString, Format)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((ByteString, Format) -> (ByteString, Format))
-> Maybe (ByteString, Format) -> Maybe (ByteString, Format)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ByteString, Format) -> (ByteString, Format)
toBoundParam) [Maybe (ByteString, Format)]
params) (Format -> Format
toFormat Format
resultFormat),
      describePrepared :: ByteString -> IO (Maybe Result)
Pqi.describePrepared = \ByteString
name -> (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> ByteString -> IO (Maybe Result)
Pq.describePrepared Connection
c ByteString
name,
      describePortal :: ByteString -> IO (Maybe Result)
Pqi.describePortal = \ByteString
name -> (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> ByteString -> IO (Maybe Result)
Pq.describePortal Connection
c ByteString
name,
      escapeStringConn :: ByteString -> IO (Maybe ByteString)
Pqi.escapeStringConn = \ByteString
s -> Connection -> ByteString -> IO (Maybe ByteString)
Pq.escapeStringConn Connection
c ByteString
s,
      escapeByteaConn :: ByteString -> IO (Maybe ByteString)
Pqi.escapeByteaConn = \ByteString
s -> Connection -> ByteString -> IO (Maybe ByteString)
Pq.escapeByteaConn Connection
c ByteString
s,
      escapeIdentifier :: ByteString -> IO (Maybe ByteString)
Pqi.escapeIdentifier = \ByteString
s -> Connection -> ByteString -> IO (Maybe ByteString)
Pq.escapeIdentifier Connection
c ByteString
s,
      sendQuery :: ByteString -> IO Bool
Pqi.sendQuery = \ByteString
sql -> Connection -> ByteString -> IO Bool
Pq.sendQuery Connection
c ByteString
sql,
      sendQueryParams :: ByteString
-> [Maybe (Word32, ByteString, Format)] -> Format -> IO Bool
Pqi.sendQueryParams = \ByteString
sql [Maybe (Word32, ByteString, Format)]
params Format
resultFormat ->
        Connection
-> ByteString
-> [Maybe (Oid, ByteString, Format)]
-> Format
-> IO Bool
Pq.sendQueryParams Connection
c ByteString
sql ((Maybe (Word32, ByteString, Format)
 -> Maybe (Oid, ByteString, Format))
-> [Maybe (Word32, ByteString, Format)]
-> [Maybe (Oid, ByteString, Format)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Word32, ByteString, Format) -> (Oid, ByteString, Format))
-> Maybe (Word32, ByteString, Format)
-> Maybe (Oid, ByteString, Format)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word32, ByteString, Format) -> (Oid, ByteString, Format)
toParam) [Maybe (Word32, ByteString, Format)]
params) (Format -> Format
toFormat Format
resultFormat),
      sendPrepare :: ByteString -> ByteString -> Maybe [Word32] -> IO Bool
Pqi.sendPrepare = \ByteString
name ByteString
sql Maybe [Word32]
paramTypes ->
        Connection -> ByteString -> ByteString -> Maybe [Oid] -> IO Bool
Pq.sendPrepare Connection
c ByteString
name ByteString
sql (([Word32] -> [Oid]) -> Maybe [Word32] -> Maybe [Oid]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Word32 -> Oid) -> [Word32] -> [Oid]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Oid
toOid) Maybe [Word32]
paramTypes),
      sendQueryPrepared :: ByteString -> [Maybe (ByteString, Format)] -> Format -> IO Bool
Pqi.sendQueryPrepared = \ByteString
name [Maybe (ByteString, Format)]
params Format
resultFormat ->
        Connection
-> ByteString -> [Maybe (ByteString, Format)] -> Format -> IO Bool
Pq.sendQueryPrepared Connection
c ByteString
name ((Maybe (ByteString, Format) -> Maybe (ByteString, Format))
-> [Maybe (ByteString, Format)] -> [Maybe (ByteString, Format)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((ByteString, Format) -> (ByteString, Format))
-> Maybe (ByteString, Format) -> Maybe (ByteString, Format)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ByteString, Format) -> (ByteString, Format)
toBoundParam) [Maybe (ByteString, Format)]
params) (Format -> Format
toFormat Format
resultFormat),
      sendDescribePrepared :: ByteString -> IO Bool
Pqi.sendDescribePrepared = \ByteString
name -> Connection -> ByteString -> IO Bool
Pq.sendDescribePrepared Connection
c ByteString
name,
      sendDescribePortal :: ByteString -> IO Bool
Pqi.sendDescribePortal = \ByteString
name -> Connection -> ByteString -> IO Bool
Pq.sendDescribePortal Connection
c ByteString
name,
      getResult :: IO (Maybe Result)
Pqi.getResult = (Result -> Result) -> Maybe Result -> Maybe Result
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Result -> Result
mkResult (Maybe Result -> Maybe Result)
-> IO (Maybe Result) -> IO (Maybe Result)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO (Maybe Result)
Pq.getResult Connection
c,
      consumeInput :: IO Bool
Pqi.consumeInput = Connection -> IO Bool
Pq.consumeInput Connection
c,
      isBusy :: IO Bool
Pqi.isBusy = Connection -> IO Bool
Pq.isBusy Connection
c,
      setnonblocking :: Bool -> IO Bool
Pqi.setnonblocking = \Bool
nonBlocking -> Connection -> Bool -> IO Bool
Pq.setnonblocking Connection
c Bool
nonBlocking,
      isnonblocking :: IO Bool
Pqi.isnonblocking = Connection -> IO Bool
Pq.isnonblocking Connection
c,
      setSingleRowMode :: IO Bool
Pqi.setSingleRowMode = Connection -> IO Bool
Pq.setSingleRowMode Connection
c,
      flush :: IO FlushStatus
Pqi.flush = FlushStatus -> FlushStatus
fromFlushStatus (FlushStatus -> FlushStatus) -> IO FlushStatus -> IO FlushStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO FlushStatus
Pq.flush Connection
c,
      pipelineStatus :: IO PipelineStatus
Pqi.pipelineStatus = PipelineStatus -> PipelineStatus
fromPipelineStatus (PipelineStatus -> PipelineStatus)
-> IO PipelineStatus -> IO PipelineStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO PipelineStatus
Pq.pipelineStatus Connection
c,
      enterPipelineMode :: IO Bool
Pqi.enterPipelineMode = Connection -> IO Bool
Pq.enterPipelineMode Connection
c,
      exitPipelineMode :: IO Bool
Pqi.exitPipelineMode = Connection -> IO Bool
Pq.exitPipelineMode Connection
c,
      pipelineSync :: IO Bool
Pqi.pipelineSync = Connection -> IO Bool
Pq.pipelineSync Connection
c,
      sendFlushRequest :: IO Bool
Pqi.sendFlushRequest = Connection -> IO Bool
Pq.sendFlushRequest Connection
c,
      getCancel :: IO (Maybe Cancel)
Pqi.getCancel = (Cancel -> Cancel) -> Maybe Cancel -> Maybe Cancel
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Cancel -> Cancel
mkCancel (Maybe Cancel -> Maybe Cancel)
-> IO (Maybe Cancel) -> IO (Maybe Cancel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO (Maybe Cancel)
Pq.getCancel Connection
c,
      notifies :: IO (Maybe Notify)
Pqi.notifies = (Notify -> Notify) -> Maybe Notify -> Maybe Notify
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Notify -> Notify
fromNotify (Maybe Notify -> Maybe Notify)
-> IO (Maybe Notify) -> IO (Maybe Notify)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO (Maybe Notify)
Pq.notifies Connection
c,
      disableNoticeReporting :: IO ()
Pqi.disableNoticeReporting = Connection -> IO ()
Pq.disableNoticeReporting Connection
c,
      enableNoticeReporting :: IO ()
Pqi.enableNoticeReporting = Connection -> IO ()
Pq.enableNoticeReporting Connection
c,
      getNotice :: IO (Maybe ByteString)
Pqi.getNotice = Connection -> IO (Maybe ByteString)
Pq.getNotice Connection
c,
      putCopyData :: ByteString -> IO CopyInResult
Pqi.putCopyData = \ByteString
value -> CopyInResult -> CopyInResult
fromCopyInResult (CopyInResult -> CopyInResult)
-> IO CopyInResult -> IO CopyInResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> ByteString -> IO CopyInResult
Pq.putCopyData Connection
c ByteString
value,
      putCopyEnd :: Maybe ByteString -> IO CopyInResult
Pqi.putCopyEnd = \Maybe ByteString
reason -> CopyInResult -> CopyInResult
fromCopyInResult (CopyInResult -> CopyInResult)
-> IO CopyInResult -> IO CopyInResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> Maybe ByteString -> IO CopyInResult
Pq.putCopyEnd Connection
c Maybe ByteString
reason,
      getCopyData :: Bool -> IO CopyOutResult
Pqi.getCopyData = \Bool
nonBlocking -> CopyOutResult -> CopyOutResult
fromCopyOutResult (CopyOutResult -> CopyOutResult)
-> IO CopyOutResult -> IO CopyOutResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> Bool -> IO CopyOutResult
Pq.getCopyData Connection
c Bool
nonBlocking,
      loCreat :: IO (Maybe Word32)
Pqi.loCreat = (Oid -> Word32) -> Maybe Oid -> Maybe Word32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Oid -> Word32
fromOid (Maybe Oid -> Maybe Word32) -> IO (Maybe Oid) -> IO (Maybe Word32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO (Maybe Oid)
Pq.loCreat Connection
c,
      loCreate :: Word32 -> IO (Maybe Word32)
Pqi.loCreate = \Word32
oid -> (Oid -> Word32) -> Maybe Oid -> Maybe Word32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Oid -> Word32
fromOid (Maybe Oid -> Maybe Word32) -> IO (Maybe Oid) -> IO (Maybe Word32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> Oid -> IO (Maybe Oid)
Pq.loCreate Connection
c (Word32 -> Oid
toOid Word32
oid),
      loImport :: String -> IO (Maybe Word32)
Pqi.loImport = \String
path -> (Oid -> Word32) -> Maybe Oid -> Maybe Word32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Oid -> Word32
fromOid (Maybe Oid -> Maybe Word32) -> IO (Maybe Oid) -> IO (Maybe Word32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> String -> IO (Maybe Oid)
Pq.loImport Connection
c String
path,
      loImportWithOid :: String -> Word32 -> IO (Maybe Word32)
Pqi.loImportWithOid = \String
path Word32
oid -> (Oid -> Word32) -> Maybe Oid -> Maybe Word32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Oid -> Word32
fromOid (Maybe Oid -> Maybe Word32) -> IO (Maybe Oid) -> IO (Maybe Word32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> String -> Oid -> IO (Maybe Oid)
Pq.loImportWithOid Connection
c String
path (Word32 -> Oid
toOid Word32
oid),
      loExport :: Word32 -> String -> IO (Maybe ())
Pqi.loExport = \Word32
oid String
path -> Connection -> Oid -> String -> IO (Maybe ())
Pq.loExport Connection
c (Word32 -> Oid
toOid Word32
oid) String
path,
      loOpen :: Word32 -> IOMode -> IO (Maybe Int32)
Pqi.loOpen = \Word32
oid IOMode
mode -> (LoFd -> Int32) -> Maybe LoFd -> Maybe Int32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LoFd -> Int32
fromLibPQLoFd (Maybe LoFd -> Maybe Int32) -> IO (Maybe LoFd) -> IO (Maybe Int32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> Oid -> IOMode -> IO (Maybe LoFd)
Pq.loOpen Connection
c (Word32 -> Oid
toOid Word32
oid) IOMode
mode,
      loWrite :: Int32 -> ByteString -> IO (Maybe Int)
Pqi.loWrite = \Int32
fd ByteString
value -> Connection -> LoFd -> ByteString -> IO (Maybe Int)
Pq.loWrite Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd) ByteString
value,
      loRead :: Int32 -> Int -> IO (Maybe ByteString)
Pqi.loRead = \Int32
fd Int
len -> Connection -> LoFd -> Int -> IO (Maybe ByteString)
Pq.loRead Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd) Int
len,
      loSeek :: Int32 -> SeekMode -> Int -> IO (Maybe Int)
Pqi.loSeek = \Int32
fd SeekMode
mode Int
offset -> Connection -> LoFd -> SeekMode -> Int -> IO (Maybe Int)
Pq.loSeek Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd) SeekMode
mode Int
offset,
      loTell :: Int32 -> IO (Maybe Int)
Pqi.loTell = \Int32
fd -> Connection -> LoFd -> IO (Maybe Int)
Pq.loTell Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd),
      loTruncate :: Int32 -> Int -> IO (Maybe ())
Pqi.loTruncate = \Int32
fd Int
len -> Connection -> LoFd -> Int -> IO (Maybe ())
Pq.loTruncate Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd) Int
len,
      loClose :: Int32 -> IO (Maybe ())
Pqi.loClose = \Int32
fd -> Connection -> LoFd -> IO (Maybe ())
Pq.loClose Connection
c (Int32 -> LoFd
toLibPQLoFd Int32
fd),
      loUnlink :: Word32 -> IO (Maybe ())
Pqi.loUnlink = \Word32
oid -> Connection -> Oid -> IO (Maybe ())
Pq.loUnlink Connection
c (Word32 -> Oid
toOid Word32
oid),
      clientEncoding :: IO ByteString
Pqi.clientEncoding = Connection -> IO ByteString
Pq.clientEncoding Connection
c,
      setClientEncoding :: ByteString -> IO Bool
Pqi.setClientEncoding = \ByteString
encoding -> Connection -> ByteString -> IO Bool
Pq.setClientEncoding Connection
c ByteString
encoding,
      setErrorVerbosity :: Verbosity -> IO Verbosity
Pqi.setErrorVerbosity = \Verbosity
verbosity ->
        Verbosity -> Verbosity
fromVerbosity (Verbosity -> Verbosity) -> IO Verbosity -> IO Verbosity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> Verbosity -> IO Verbosity
Pq.setErrorVerbosity Connection
c (Verbosity -> Verbosity
toVerbosity Verbosity
verbosity)
    }

-- | Build a 'Pqi.Result' whose fields close over the given
-- @postgresql-libpq@ result handle.
mkResult :: Pq.Result -> Pqi.Result
mkResult :: Result -> Result
mkResult Result
r =
  Pqi.Result
    { resultStatus :: IO ExecStatus
Pqi.resultStatus = ExecStatus -> ExecStatus
fromExecStatus (ExecStatus -> ExecStatus) -> IO ExecStatus -> IO ExecStatus
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> IO ExecStatus
Pq.resultStatus Result
r,
      resultErrorMessage :: IO (Maybe ByteString)
Pqi.resultErrorMessage = Result -> IO (Maybe ByteString)
Pq.resultErrorMessage Result
r,
      resultErrorField :: FieldCode -> IO (Maybe ByteString)
Pqi.resultErrorField = \FieldCode
field -> Result -> FieldCode -> IO (Maybe ByteString)
Pq.resultErrorField Result
r (FieldCode -> FieldCode
toFieldCode FieldCode
field),
      unsafeFreeResult :: IO ()
Pqi.unsafeFreeResult = Result -> IO ()
Pq.unsafeFreeResult Result
r,
      ntuples :: IO Int32
Pqi.ntuples = Row -> Int32
fromRow (Row -> Int32) -> IO Row -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> IO Row
Pq.ntuples Result
r,
      nfields :: IO Int32
Pqi.nfields = Column -> Int32
fromColumn (Column -> Int32) -> IO Column -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> IO Column
Pq.nfields Result
r,
      fname :: Int32 -> IO (Maybe ByteString)
Pqi.fname = \Int32
column -> Result -> Column -> IO (Maybe ByteString)
Pq.fname Result
r (Int32 -> Column
toColumn Int32
column),
      fnumber :: ByteString -> IO (Maybe Int32)
Pqi.fnumber = \ByteString
name -> (Column -> Int32) -> Maybe Column -> Maybe Int32
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Column -> Int32
fromColumn (Maybe Column -> Maybe Int32)
-> IO (Maybe Column) -> IO (Maybe Int32)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> ByteString -> IO (Maybe Column)
Pq.fnumber Result
r ByteString
name,
      ftable :: Int32 -> IO Word32
Pqi.ftable = \Int32
column -> Oid -> Word32
fromOid (Oid -> Word32) -> IO Oid -> IO Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> Column -> IO Oid
Pq.ftable Result
r (Int32 -> Column
toColumn Int32
column),
      ftablecol :: Int32 -> IO Int32
Pqi.ftablecol = \Int32
column -> Column -> Int32
fromColumn (Column -> Int32) -> IO Column -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> Column -> IO Column
Pq.ftablecol Result
r (Int32 -> Column
toColumn Int32
column),
      fformat :: Int32 -> IO Format
Pqi.fformat = \Int32
column -> Format -> Format
fromFormat (Format -> Format) -> IO Format -> IO Format
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> Column -> IO Format
Pq.fformat Result
r (Int32 -> Column
toColumn Int32
column),
      ftype :: Int32 -> IO Word32
Pqi.ftype = \Int32
column -> Oid -> Word32
fromOid (Oid -> Word32) -> IO Oid -> IO Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> Column -> IO Oid
Pq.ftype Result
r (Int32 -> Column
toColumn Int32
column),
      fmod :: Int32 -> IO Int
Pqi.fmod = \Int32
column -> Result -> Column -> IO Int
Pq.fmod Result
r (Int32 -> Column
toColumn Int32
column),
      fsize :: Int32 -> IO Int
Pqi.fsize = \Int32
column -> Result -> Column -> IO Int
Pq.fsize Result
r (Int32 -> Column
toColumn Int32
column),
      getvalue :: Int32 -> Int32 -> IO (Maybe ByteString)
Pqi.getvalue = \Int32
row Int32
column -> Result -> Row -> Column -> IO (Maybe ByteString)
Pq.getvalue' Result
r (Int32 -> Row
toRow Int32
row) (Int32 -> Column
toColumn Int32
column),
      getvalue' :: Int32 -> Int32 -> IO (Maybe ByteString)
Pqi.getvalue' = \Int32
row Int32
column -> Result -> Row -> Column -> IO (Maybe ByteString)
Pq.getvalue' Result
r (Int32 -> Row
toRow Int32
row) (Int32 -> Column
toColumn Int32
column),
      getisnull :: Int32 -> Int32 -> IO Bool
Pqi.getisnull = \Int32
row Int32
column -> Result -> Row -> Column -> IO Bool
Pq.getisnull Result
r (Int32 -> Row
toRow Int32
row) (Int32 -> Column
toColumn Int32
column),
      getlength :: Int32 -> Int32 -> IO Int
Pqi.getlength = \Int32
row Int32
column -> Result -> Row -> Column -> IO Int
Pq.getlength Result
r (Int32 -> Row
toRow Int32
row) (Int32 -> Column
toColumn Int32
column),
      nparams :: IO Int32
Pqi.nparams = Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int32) -> IO Int -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> IO Int
Pq.nparams Result
r,
      paramtype :: Int32 -> IO Word32
Pqi.paramtype = \Int32
index -> Oid -> Word32
fromOid (Oid -> Word32) -> IO Oid -> IO Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result -> Int -> IO Oid
Pq.paramtype Result
r (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
index),
      cmdStatus :: IO (Maybe ByteString)
Pqi.cmdStatus = Result -> IO (Maybe ByteString)
Pq.cmdStatus Result
r,
      cmdTuples :: IO (Maybe ByteString)
Pqi.cmdTuples = Result -> IO (Maybe ByteString)
Pq.cmdTuples Result
r
    }

-- | Build a 'Pqi.Cancel' whose field closes over the given
-- @postgresql-libpq@ cancellation handle.
mkCancel :: Pq.Cancel -> Pqi.Cancel
mkCancel :: Cancel -> Cancel
mkCancel Cancel
handle =
  Pqi.Cancel
    { cancel :: IO (Either ByteString ())
Pqi.cancel = Cancel -> IO (Either ByteString ())
Pq.cancel Cancel
handle
    }

-- * Type conversions

toParam :: (Word32, ByteString, Pqi.Format) -> (Pq.Oid, ByteString, Pq.Format)
toParam :: (Word32, ByteString, Format) -> (Oid, ByteString, Format)
toParam (Word32
oid, ByteString
value, Format
format) = (Word32 -> Oid
toOid Word32
oid, ByteString
value, Format -> Format
toFormat Format
format)

toBoundParam :: (ByteString, Pqi.Format) -> (ByteString, Pq.Format)
toBoundParam :: (ByteString, Format) -> (ByteString, Format)
toBoundParam (ByteString
value, Format
format) = (ByteString
value, Format -> Format
toFormat Format
format)

toOid :: Word32 -> Pq.Oid
toOid :: Word32 -> Oid
toOid = CUInt -> Oid
Pq.Oid (CUInt -> Oid) -> (Word32 -> CUInt) -> Word32 -> Oid
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral

fromOid :: Pq.Oid -> Word32
fromOid :: Oid -> Word32
fromOid (Pq.Oid CUInt
value) = CUInt -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
value

toRow :: Int32 -> Pq.Row
toRow :: Int32 -> Row
toRow = Int32 -> Row
forall a. Integral a => a -> Row
Pq.toRow

fromRow :: Pq.Row -> Int32
fromRow :: Row -> Int32
fromRow = Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int32) -> (Row -> Int) -> Row -> Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Row -> Int
forall a. Enum a => a -> Int
fromEnum

toColumn :: Int32 -> Pq.Column
toColumn :: Int32 -> Column
toColumn = Int32 -> Column
forall a. Integral a => a -> Column
Pq.toColumn

fromColumn :: Pq.Column -> Int32
fromColumn :: Column -> Int32
fromColumn = Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int32) -> (Column -> Int) -> Column -> Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Column -> Int
forall a. Enum a => a -> Int
fromEnum

toLibPQLoFd :: Int32 -> Pq.LoFd
toLibPQLoFd :: Int32 -> LoFd
toLibPQLoFd = CInt -> LoFd
Pq.LoFd (CInt -> LoFd) -> (Int32 -> CInt) -> Int32 -> LoFd
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral

fromLibPQLoFd :: Pq.LoFd -> Int32
fromLibPQLoFd :: LoFd -> Int32
fromLibPQLoFd (Pq.LoFd CInt
fd) = CInt -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
fd

fromNotify :: Pq.Notify -> Pqi.Notify
fromNotify :: Notify -> Notify
fromNotify Notify
notification =
  Pqi.Notify
    { notifyRelname :: ByteString
Pqi.notifyRelname = Notify -> ByteString
Pq.notifyRelname Notify
notification,
      notifyBePid :: Int32
Pqi.notifyBePid = CPid -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Notify -> CPid
Pq.notifyBePid Notify
notification),
      notifyExtra :: ByteString
Pqi.notifyExtra = Notify -> ByteString
Pq.notifyExtra Notify
notification
    }

toFormat :: Pqi.Format -> Pq.Format
toFormat :: Format -> Format
toFormat = \case
  Format
Pqi.Text -> Format
Pq.Text
  Format
Pqi.Binary -> Format
Pq.Binary

fromFormat :: Pq.Format -> Pqi.Format
fromFormat :: Format -> Format
fromFormat = \case
  Format
Pq.Text -> Format
Pqi.Text
  Format
Pq.Binary -> Format
Pqi.Binary

fromExecStatus :: Pq.ExecStatus -> Pqi.ExecStatus
fromExecStatus :: ExecStatus -> ExecStatus
fromExecStatus = \case
  ExecStatus
Pq.EmptyQuery -> ExecStatus
Pqi.EmptyQuery
  ExecStatus
Pq.CommandOk -> ExecStatus
Pqi.CommandOk
  ExecStatus
Pq.TuplesOk -> ExecStatus
Pqi.TuplesOk
  ExecStatus
Pq.CopyOut -> ExecStatus
Pqi.CopyOut
  ExecStatus
Pq.CopyIn -> ExecStatus
Pqi.CopyIn
  ExecStatus
Pq.CopyBoth -> ExecStatus
Pqi.CopyBoth
  ExecStatus
Pq.BadResponse -> ExecStatus
Pqi.BadResponse
  ExecStatus
Pq.NonfatalError -> ExecStatus
Pqi.NonfatalError
  ExecStatus
Pq.FatalError -> ExecStatus
Pqi.FatalError
  ExecStatus
Pq.SingleTuple -> ExecStatus
Pqi.SingleTuple
  ExecStatus
Pq.PipelineSync -> ExecStatus
Pqi.PipelineSync
  ExecStatus
Pq.PipelineAbort -> ExecStatus
Pqi.PipelineAbort

toExecStatus :: Pqi.ExecStatus -> Pq.ExecStatus
toExecStatus :: ExecStatus -> ExecStatus
toExecStatus = \case
  ExecStatus
Pqi.EmptyQuery -> ExecStatus
Pq.EmptyQuery
  ExecStatus
Pqi.CommandOk -> ExecStatus
Pq.CommandOk
  ExecStatus
Pqi.TuplesOk -> ExecStatus
Pq.TuplesOk
  ExecStatus
Pqi.CopyOut -> ExecStatus
Pq.CopyOut
  ExecStatus
Pqi.CopyIn -> ExecStatus
Pq.CopyIn
  ExecStatus
Pqi.CopyBoth -> ExecStatus
Pq.CopyBoth
  ExecStatus
Pqi.BadResponse -> ExecStatus
Pq.BadResponse
  ExecStatus
Pqi.NonfatalError -> ExecStatus
Pq.NonfatalError
  ExecStatus
Pqi.FatalError -> ExecStatus
Pq.FatalError
  ExecStatus
Pqi.SingleTuple -> ExecStatus
Pq.SingleTuple
  ExecStatus
Pqi.PipelineSync -> ExecStatus
Pq.PipelineSync
  ExecStatus
Pqi.PipelineAbort -> ExecStatus
Pq.PipelineAbort

fromConnStatus :: Pq.ConnStatus -> Pqi.ConnStatus
fromConnStatus :: ConnStatus -> ConnStatus
fromConnStatus = \case
  ConnStatus
Pq.ConnectionOk -> ConnStatus
Pqi.ConnectionOk
  ConnStatus
Pq.ConnectionBad -> ConnStatus
Pqi.ConnectionBad
  ConnStatus
Pq.ConnectionStarted -> ConnStatus
Pqi.ConnectionStarted
  ConnStatus
Pq.ConnectionMade -> ConnStatus
Pqi.ConnectionMade
  ConnStatus
Pq.ConnectionAwaitingResponse -> ConnStatus
Pqi.ConnectionAwaitingResponse
  ConnStatus
Pq.ConnectionAuthOk -> ConnStatus
Pqi.ConnectionAuthOk
  ConnStatus
Pq.ConnectionSetEnv -> ConnStatus
Pqi.ConnectionSetEnv
  ConnStatus
Pq.ConnectionSSLStartup -> ConnStatus
Pqi.ConnectionSSLStartup

fromTransactionStatus :: Pq.TransactionStatus -> Pqi.TransactionStatus
fromTransactionStatus :: TransactionStatus -> TransactionStatus
fromTransactionStatus = \case
  TransactionStatus
Pq.TransIdle -> TransactionStatus
Pqi.TransIdle
  TransactionStatus
Pq.TransActive -> TransactionStatus
Pqi.TransActive
  TransactionStatus
Pq.TransInTrans -> TransactionStatus
Pqi.TransInTrans
  TransactionStatus
Pq.TransInError -> TransactionStatus
Pqi.TransInError
  TransactionStatus
Pq.TransUnknown -> TransactionStatus
Pqi.TransUnknown

fromPollingStatus :: Pq.PollingStatus -> Pqi.PollingStatus
fromPollingStatus :: PollingStatus -> PollingStatus
fromPollingStatus = \case
  PollingStatus
Pq.PollingFailed -> PollingStatus
Pqi.PollingFailed
  PollingStatus
Pq.PollingReading -> PollingStatus
Pqi.PollingReading
  PollingStatus
Pq.PollingWriting -> PollingStatus
Pqi.PollingWriting
  PollingStatus
Pq.PollingOk -> PollingStatus
Pqi.PollingOk

fromPipelineStatus :: Pq.PipelineStatus -> Pqi.PipelineStatus
fromPipelineStatus :: PipelineStatus -> PipelineStatus
fromPipelineStatus = \case
  PipelineStatus
Pq.PipelineOn -> PipelineStatus
Pqi.PipelineOn
  PipelineStatus
Pq.PipelineOff -> PipelineStatus
Pqi.PipelineOff
  PipelineStatus
Pq.PipelineAborted -> PipelineStatus
Pqi.PipelineAborted

fromFlushStatus :: Pq.FlushStatus -> Pqi.FlushStatus
fromFlushStatus :: FlushStatus -> FlushStatus
fromFlushStatus = \case
  FlushStatus
Pq.FlushOk -> FlushStatus
Pqi.FlushOk
  FlushStatus
Pq.FlushFailed -> FlushStatus
Pqi.FlushFailed
  FlushStatus
Pq.FlushWriting -> FlushStatus
Pqi.FlushWriting

fromCopyInResult :: Pq.CopyInResult -> Pqi.CopyInResult
fromCopyInResult :: CopyInResult -> CopyInResult
fromCopyInResult = \case
  CopyInResult
Pq.CopyInOk -> CopyInResult
Pqi.CopyInOk
  CopyInResult
Pq.CopyInError -> CopyInResult
Pqi.CopyInError
  CopyInResult
Pq.CopyInWouldBlock -> CopyInResult
Pqi.CopyInWouldBlock

fromCopyOutResult :: Pq.CopyOutResult -> Pqi.CopyOutResult
fromCopyOutResult :: CopyOutResult -> CopyOutResult
fromCopyOutResult = \case
  Pq.CopyOutRow ByteString
value -> ByteString -> CopyOutResult
Pqi.CopyOutRow ByteString
value
  CopyOutResult
Pq.CopyOutWouldBlock -> CopyOutResult
Pqi.CopyOutWouldBlock
  CopyOutResult
Pq.CopyOutDone -> CopyOutResult
Pqi.CopyOutDone
  CopyOutResult
Pq.CopyOutError -> CopyOutResult
Pqi.CopyOutError

toVerbosity :: Pqi.Verbosity -> Pq.Verbosity
toVerbosity :: Verbosity -> Verbosity
toVerbosity = \case
  Verbosity
Pqi.ErrorsTerse -> Verbosity
Pq.ErrorsTerse
  Verbosity
Pqi.ErrorsDefault -> Verbosity
Pq.ErrorsDefault
  Verbosity
Pqi.ErrorsVerbose -> Verbosity
Pq.ErrorsVerbose

fromVerbosity :: Pq.Verbosity -> Pqi.Verbosity
fromVerbosity :: Verbosity -> Verbosity
fromVerbosity = \case
  Verbosity
Pq.ErrorsTerse -> Verbosity
Pqi.ErrorsTerse
  Verbosity
Pq.ErrorsDefault -> Verbosity
Pqi.ErrorsDefault
  Verbosity
Pq.ErrorsVerbose -> Verbosity
Pqi.ErrorsVerbose

toFieldCode :: Pqi.FieldCode -> Pq.FieldCode
toFieldCode :: FieldCode -> FieldCode
toFieldCode = \case
  FieldCode
Pqi.DiagSeverity -> FieldCode
Pq.DiagSeverity
  FieldCode
Pqi.DiagSqlstate -> FieldCode
Pq.DiagSqlstate
  FieldCode
Pqi.DiagMessagePrimary -> FieldCode
Pq.DiagMessagePrimary
  FieldCode
Pqi.DiagMessageDetail -> FieldCode
Pq.DiagMessageDetail
  FieldCode
Pqi.DiagMessageHint -> FieldCode
Pq.DiagMessageHint
  FieldCode
Pqi.DiagStatementPosition -> FieldCode
Pq.DiagStatementPosition
  FieldCode
Pqi.DiagInternalPosition -> FieldCode
Pq.DiagInternalPosition
  FieldCode
Pqi.DiagInternalQuery -> FieldCode
Pq.DiagInternalQuery
  FieldCode
Pqi.DiagContext -> FieldCode
Pq.DiagContext
  FieldCode
Pqi.DiagSourceFile -> FieldCode
Pq.DiagSourceFile
  FieldCode
Pqi.DiagSourceLine -> FieldCode
Pq.DiagSourceLine
  FieldCode
Pqi.DiagSourceFunction -> FieldCode
Pq.DiagSourceFunction