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

Safe HaskellNone



This module exposes the high-level Template Haskell interface for querying and manipulating the PostgreSQL server.

All SQL string arguments support expression interpolation. Just enclose your expression in {} in the SQL string.

Note that transactions are messy and untested. Attempt to use them at your own risk.



queryTuples :: String -> ExpQ Source #

queryTuples :: String -> (PGConnection -> IO [(column1, column2, ...)])

Query a PostgreSQL server and return the results as a list of tuples.

Example (where h is a handle from pgConnect):

$(queryTuples "SELECT usesysid, usename FROM pg_user") h :: IO [(Maybe String, Maybe Integer)]

queryTuple :: String -> ExpQ Source #

queryTuple :: String -> (PGConnection -> IO (Maybe (column1, column2, ...)))

Convenience function to query a PostgreSQL server and return the first result as a tuple. If the query produces no results, return Nothing.

Example (where h is a handle from pgConnect):

let sysid = 10::Integer;
$(queryTuple "SELECT usesysid, usename FROM pg_user WHERE usesysid = {sysid}") h :: IO (Maybe (Maybe String, Maybe Integer))

execute :: String -> ExpQ Source #

execute :: String -> (PGConnection -> IO ())

Convenience function to execute a statement on the PostgreSQL server.

Example (where h is a handle from pgConnect):

insertIgnore :: IO () -> IO () Source #

Ignore duplicate key errors. This is also limited to the IO Monad.

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

Run a sequence of IO actions (presumably SQL statements) wrapped in a transaction. Unfortunately you're restricted to using this in the IO Monad for now due to the use of onException. I'm debating adding a MonadPeelIO version.

rollback :: PGConnection -> IO () Source #

Roll back a transaction.

pgConnect Source #


:: String

the host to connect to

-> PortID

the port to connect on

-> ByteString

the database to connect to

-> ByteString

the username to connect as

-> ByteString

the password to connect with

-> IO PGConnection

a handle to communicate with the PostgreSQL server on

pgDisconnect Source #


:: PGConnection

a handle from pgConnect

-> IO () 

Disconnect cleanly from the PostgreSQL server.