postgresql-typed-0.4.3: A PostgreSQL access library with compile-time SQL type inference

Safe HaskellNone
LanguageHaskell98

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

pgDBHost :: HostName

The hostname (ignored if pgDBPort is UnixSocket)

pgDBPort :: PortID

The port, likely either PortNumber 5432 or UnixSocket "/tmp/.s.PGSQL.5432"

pgDBName :: ByteString

The name of the database

pgDBUser, pgDBPass :: ByteString
 
pgDBDebug :: Bool

Log all low-level server messages

pgDBLogMessage :: MessageFields -> IO ()

How to log server notice messages (e.g., print . PGError)

Instances

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.

data 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

pgErrorFields :: MessageFields
 

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.

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.

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

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