Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.PostgreSQL.Typed.Protocol
Description
The Protocol module allows for direct, low-level communication with a PostgreSQL server over TCP/IP. You probably don't want to use this module directly.
Synopsis
- data PGDatabase = PGDatabase {
- pgDBAddr :: Either (HostName, ServiceName) SockAddr
- pgDBName :: ByteString
- pgDBUser :: ByteString
- pgDBPass :: ByteString
- pgDBParams :: [(ByteString, ByteString)]
- pgDBDebug :: Bool
- pgDBLogMessage :: MessageFields -> IO ()
- pgDBTLS :: PGTlsMode
- defaultPGDatabase :: PGDatabase
- data PGConnection
- newtype PGError = PGError {
- pgErrorFields :: MessageFields
- data PGTlsMode
- data PGTlsValidateMode
- pgErrorCode :: PGError -> ByteString
- pgConnectionDatabase :: PGConnection -> PGDatabase
- pgTypeEnv :: PGConnection -> PGTypeEnv
- pgConnect :: PGDatabase -> IO PGConnection
- pgDisconnect :: PGConnection -> IO ()
- pgReconnect :: PGConnection -> PGDatabase -> IO PGConnection
- pgDescribe :: PGConnection -> ByteString -> [OID] -> Bool -> IO ([OID], [(ByteString, OID, Bool)])
- pgSimpleQuery :: PGConnection -> ByteString -> IO (Int, [PGValues])
- pgSimpleQueries_ :: PGConnection -> ByteString -> IO ()
- pgPreparedQuery :: PGConnection -> ByteString -> [OID] -> PGValues -> [Bool] -> IO (Int, [PGValues])
- pgPreparedLazyQuery :: PGConnection -> ByteString -> [OID] -> PGValues -> [Bool] -> Word32 -> IO [PGValues]
- pgCloseStatement :: PGConnection -> ByteString -> [OID] -> IO ()
- pgBegin :: PGConnection -> IO ()
- pgCommit :: PGConnection -> IO ()
- pgRollback :: PGConnection -> IO ()
- pgCommitAll :: PGConnection -> IO ()
- pgRollbackAll :: PGConnection -> IO ()
- pgTransaction :: PGConnection -> IO a -> IO a
- pgDisconnectOnce :: PGConnection -> IO ()
- pgRun :: PGConnection -> ByteString -> [OID] -> PGValues -> IO (Maybe Integer)
- data PGPreparedStatement
- pgPrepare :: PGConnection -> ByteString -> [OID] -> IO PGPreparedStatement
- pgClose :: PGConnection -> PGPreparedStatement -> IO ()
- data PGColDescription = PGColDescription {
- pgColName :: ByteString
- pgColTable :: !OID
- pgColNumber :: !Int16
- pgColType :: !OID
- pgColSize :: !Int16
- pgColModifier :: !Int32
- pgColBinary :: !Bool
- type PGRowDescription = [PGColDescription]
- pgBind :: PGConnection -> PGPreparedStatement -> PGValues -> IO PGRowDescription
- pgFetch :: PGConnection -> PGPreparedStatement -> Word32 -> IO ([PGValues], Maybe Integer)
- data PGNotification = PGNotification {}
- pgGetNotification :: PGConnection -> IO PGNotification
- pgGetNotifications :: PGConnection -> IO [PGNotification]
- pgTlsValidate :: PGTlsValidateMode -> ByteString -> Either String PGTlsMode
- pgSupportsTls :: PGConnection -> Bool
Documentation
data PGDatabase Source #
Information for how to connect to a database, to be passed to pgConnect
.
Constructors
PGDatabase | |
Fields
|
Instances
Show PGDatabase Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods showsPrec :: Int -> PGDatabase -> ShowS # show :: PGDatabase -> String # showList :: [PGDatabase] -> ShowS # | |
Eq PGDatabase Source # | |
Defined in Database.PostgreSQL.Typed.Protocol |
defaultPGDatabase :: PGDatabase Source #
A database connection with sane defaults: localhost:5432:postgres
data PGConnection Source #
An established connection to the PostgreSQL server. These objects are not thread-safe and must only be used for a single request at a time.
PGException is thrown upon encountering an ErrorResponse
with severity of
ERROR, FATAL, or PANIC. It holds the message of the error.
Constructors
PGError | |
Fields
|
Instances
Exception PGError Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods toException :: PGError -> SomeException # fromException :: SomeException -> Maybe PGError # displayException :: PGError -> String # backtraceDesired :: PGError -> Bool # | |
Show PGError Source # | |
Constructors
TlsDisabled | TLS is disabled |
TlsNoValidate | |
TlsValidate PGTlsValidateMode SignedCertificate |
data PGTlsValidateMode Source #
Constructors
TlsValidateFull | Equivalent to sslmode=verify-full. Ie: Check the FQHN against the certicate's CN |
TlsValidateCA | Equivalent to sslmode=verify-ca. Ie: Only check that the certificate has been signed by the root certificate we provide |
Instances
Show PGTlsValidateMode Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods showsPrec :: Int -> PGTlsValidateMode -> ShowS # show :: PGTlsValidateMode -> String # showList :: [PGTlsValidateMode] -> ShowS # | |
Eq PGTlsValidateMode Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods (==) :: PGTlsValidateMode -> PGTlsValidateMode -> Bool # (/=) :: PGTlsValidateMode -> PGTlsValidateMode -> Bool # |
pgErrorCode :: PGError -> ByteString Source #
Message SQLState code. See http://www.postgresql.org/docs/current/static/errcodes-appendix.html.
pgConnectionDatabase :: PGConnection -> PGDatabase Source #
The database information for this connection.
pgTypeEnv :: PGConnection -> PGTypeEnv Source #
The type environment for this connection.
pgConnect :: PGDatabase -> IO PGConnection Source #
Connect to a PostgreSQL server.
Arguments
:: PGConnection | a handle from |
-> IO () |
Disconnect cleanly from the PostgreSQL server.
pgReconnect :: PGConnection -> PGDatabase -> IO PGConnection Source #
Possibly re-open a connection to a different database, either reusing the connection if the given database is already connected or closing it and opening a new one. Regardless, the input connection must not be used afterwards.
Query operations
Arguments
:: PGConnection | |
-> ByteString | SQL string |
-> [OID] | Optional type specifications |
-> Bool | Guess nullability, otherwise assume everything is |
-> IO ([OID], [(ByteString, OID, Bool)]) | a list of parameter types, and a list of result field names, types, and nullability indicators. |
Describe a SQL statement/query. A statement description consists of 0 or more parameter descriptions (a PostgreSQL type) and zero or more result field descriptions (for queries) (consist of the name of the field, the type of the field, and a nullability indicator).
Arguments
:: PGConnection | |
-> ByteString | SQL string |
-> IO (Int, [PGValues]) | The number of rows affected and a list of result rows |
A simple query is one which requires sending only a single SimpleQuery
message to the PostgreSQL server. The query is sent as a single string; you
cannot bind parameters. Note that queries can return 0 results (an empty
list).
Arguments
:: PGConnection | |
-> ByteString | SQL string |
-> IO () |
A simple query which may contain multiple queries (separated by semi-colons) whose results are all ignored.
This function can also be used for "SET" parameter queries if necessary, but it's safer better to use pgDBParams
.
Arguments
:: PGConnection | |
-> ByteString | SQL statement with placeholders |
-> [OID] | Optional type specifications (only used for first call) |
-> PGValues | Paremeters to bind to placeholders |
-> [Bool] | Requested binary format for result columns |
-> IO (Int, [PGValues]) |
Prepare a statement, bind it, and execute it. If the given statement has already been prepared (and not yet closed) on this connection, it will be re-used.
Arguments
:: PGConnection | |
-> ByteString | |
-> [OID] | |
-> PGValues | |
-> [Bool] | |
-> Word32 | Chunk size (1 is common, 0 is all-at-once) |
-> IO [PGValues] |
Like pgPreparedQuery
but requests results lazily in chunks of the given size.
Does not use a named portal, so other requests may not intervene.
pgCloseStatement :: PGConnection -> ByteString -> [OID] -> IO () Source #
Close a previously prepared query (if necessary).
Transactions
pgBegin :: PGConnection -> IO () Source #
Begin a new transaction. If there is already a transaction in progress (created with pgBegin
or pgTransaction
) instead creates a savepoint.
pgRollback :: PGConnection -> IO () Source #
Rollback to the most recent pgBegin
.
pgCommitAll :: PGConnection -> IO () Source #
Commit all active pgBegin
s.
pgRollbackAll :: PGConnection -> IO () Source #
Rollback all active pgBegin
s.
pgTransaction :: PGConnection -> IO a -> IO a Source #
Wrap a computation in a pgBegin
, pgCommit
block, or pgRollback
on exception.
HDBC support
Arguments
:: PGConnection | a handle from |
-> IO () |
Disconnect cleanly from the PostgreSQL server, but only if it's still connected.
pgRun :: PGConnection -> ByteString -> [OID] -> PGValues -> IO (Maybe Integer) Source #
Prepare, bind, execute, and close a single (unnamed) query, and return the number of rows affected, or Nothing if there are (ignored) result rows.
data PGPreparedStatement Source #
Instances
Show PGPreparedStatement Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods showsPrec :: Int -> PGPreparedStatement -> ShowS # show :: PGPreparedStatement -> String # showList :: [PGPreparedStatement] -> ShowS # | |
Eq PGPreparedStatement Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods (==) :: PGPreparedStatement -> PGPreparedStatement -> Bool # (/=) :: PGPreparedStatement -> PGPreparedStatement -> Bool # |
pgPrepare :: PGConnection -> ByteString -> [OID] -> IO PGPreparedStatement Source #
Prepare a single query and return its handle.
pgClose :: PGConnection -> PGPreparedStatement -> IO () Source #
Close a previously prepared query.
data PGColDescription Source #
Constructors
PGColDescription | |
Fields
|
Instances
Show PGColDescription Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods showsPrec :: Int -> PGColDescription -> ShowS # show :: PGColDescription -> String # showList :: [PGColDescription] -> ShowS # |
type PGRowDescription = [PGColDescription] Source #
pgBind :: PGConnection -> PGPreparedStatement -> PGValues -> IO PGRowDescription Source #
Arguments
:: PGConnection | |
-> PGPreparedStatement | |
-> Word32 | Maximum number of rows to return, or 0 for all |
-> IO ([PGValues], Maybe Integer) |
Fetch some rows from an executed prepared statement, returning the next N result rows (if any) and number of affected rows when complete.
Notifications
data PGNotification Source #
Constructors
PGNotification | |
Fields |
Instances
Show PGNotification Source # | |
Defined in Database.PostgreSQL.Typed.Protocol Methods showsPrec :: Int -> PGNotification -> ShowS # show :: PGNotification -> String # showList :: [PGNotification] -> ShowS # |
pgGetNotification :: PGConnection -> IO PGNotification Source #
Retrieve a notifications, blocking if necessary.
pgGetNotifications :: PGConnection -> IO [PGNotification] Source #
Retrieve any pending notifications. Non-blocking.
TLS Helpers
pgTlsValidate :: PGTlsValidateMode -> ByteString -> Either String PGTlsMode Source #
Constructs a PGTlsMode
to validate the server certificate with given root
certificate (in PEM format)
pgSupportsTls :: PGConnection -> Bool Source #