pgsql-simple-0.1.2: A mid-level PostgreSQL client library.

Safe HaskellNone

Database.PostgreSQL.Base

Description

A front-end implementation for the PostgreSQL database protocol version 3.0 (implemented in PostgreSQL 7.4 and later).

Synopsis

Documentation

begin :: (MonadCatchIO m, MonadIO m) => Connection -> m ()Source

Begin a transaction.

rollback :: (MonadCatchIO m, MonadIO m) => Connection -> m ()Source

Rollback a transaction.

commit :: (MonadCatchIO m, MonadIO m) => Connection -> m ()Source

Commit a transaction.

querySource

Arguments

:: MonadCatchIO m 
=> Connection

The connection.

-> ByteString

The query.

-> m ([Field], [[Maybe ByteString]]) 

Run a simple query on a connection.

exec :: MonadCatchIO m => Connection -> ByteString -> m IntegerSource

Exec a command.

escapeBS :: ByteString -> ByteStringSource

Escape a string for PostgreSQL.

connectSource

Arguments

:: MonadIO m 
=> ConnectInfo 
-> m Connection

The datase connection.

Connect with the given username to the given database. Will throw an exception if it cannot connect.

defaultConnectInfo :: ConnectInfoSource

Default information for setting up a connection.

Defaults are as follows:

  • Server on localhost
  • User postgres
  • No password
  • Database test
  • Character set utf8

Use as in the following example:

 connect defaultConnectInfo { connectHost = "db.example.com" }

closeSource

Arguments

:: MonadIO m 
=> Connection

The connection.

-> m () 

Close a connection. Can safely be called any number of times.

withDB :: (MonadCatchIO m, MonadIO m) => ConnectInfo -> (Connection -> m a) -> m aSource

Run a an action with a connection and close the connection afterwards (protects against exceptions).

withTransaction :: (MonadCatchIO m, MonadIO m) => Connection -> m a -> m aSource

With a transaction, do some action (protects against exceptions).

newPoolSource

Arguments

:: MonadIO m 
=> ConnectInfo

Connect info.

-> m Pool 

Create a new connection pool.

pconnect :: MonadIO m => Pool -> m ConnectionSource

Connect using the connection pool.

withPoolConnectionSource

Arguments

:: (MonadCatchIO m, MonadIO m) 
=> Pool

The connection pool.

-> (Connection -> m a)

Use the connection.

-> m () 

Use the connection pool.