postgresql-typed-0.6.1.2: PostgreSQL interface with compile-time SQL type checking, optional HDBC backend

Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Typed.Protocol

Contents

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

Documentation

data PGDatabase Source #

Information for how to connect to a database, to be passed to pgConnect.

Constructors

PGDatabase 

Fields

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.

newtype PGError Source #

PGException is thrown upon encountering an ErrorResponse with severity of ERROR, FATAL, or PANIC. It holds the message of the error.

Constructors

PGError 

Fields

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

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.

pgDisconnect Source #

Arguments

:: PGConnection

a handle from pgConnect

-> 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

pgDescribe Source #

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).

pgSimpleQuery Source #

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).

pgSimpleQueries_ Source #

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.

pgPreparedQuery Source #

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.

pgPreparedLazyQuery Source #

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.

pgCommit :: PGConnection -> IO () Source #

Commit the most recent pgBegin.

pgRollback :: PGConnection -> IO () Source #

Rollback to the most recent pgBegin.

pgCommitAll :: PGConnection -> IO () Source #

Commit all active pgBegins.

pgRollbackAll :: PGConnection -> IO () Source #

Rollback all active pgBegins.

pgTransaction :: PGConnection -> IO a -> IO a Source #

Wrap a computation in a pgBegin, pgCommit block, or pgRollback on exception.

HDBC support

pgDisconnectOnce Source #

Arguments

:: PGConnection

a handle from pgConnect

-> 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.

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.

pgBind :: PGConnection -> PGPreparedStatement -> PGValues -> IO PGRowDescription Source #

Bind a prepared statement, and return the row description. After pgBind, you must either call pgFetch until it completes (returns (_, Just _)) or pgFinish before calling pgBind again on the same prepared statement.

pgFetch 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

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)