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

Safe HaskellNone
LanguageHaskell98

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

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

The name of the database

pgDBUser :: String
 
pgDBPass :: String
 
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 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.

pgDescribe Source

Arguments

:: PGConnection 
-> String

SQL string

-> [OID]

Optional type specifications

-> Bool

Guess nullability, otherwise assume everything is

-> IO ([OID], [(String, 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 
-> String

SQL string

-> IO (Int, Seq 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).

pgPreparedQuery Source

Arguments

:: PGConnection 
-> String

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, Seq 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 
-> String 
-> [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 -> String -> [OID] -> IO () Source

Close a previously prepared query (if necessary).