generic-persistence-0.4.0.0: Database persistence using generics
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.GP.Conn

Synopsis

Documentation

data Conn Source #

This module defines a wrapper around an HDBC IConnection. Using this wrapper Conn simplifies the signature of the functions in the GP module. It allows to use any HDBC connection without having to define a new function for each connection type. It also provides additional attributes to the connection, like the database type and the implicit commit flag. These attributes can be used to implement database specific functionality, modify transaction behaviour, etc.

This code has been inspired by the HDBC ConnectionWrapper and some parts have been copied verbatim from the HDBC Database.HDBC.Types module.

This module also defines a ConnectionPool type, which provides basic connection pooling functionality.

A wrapper around an HDBC IConnection.

Constructors

forall conn.IConnection conn => Conn 

Fields

Instances

Instances details
IConnection Conn Source #

manually implement the IConnection type class for the Conn type.

Instance details

Defined in Database.GP.Conn

connect :: forall conn. IConnection conn => Database -> conn -> Conn Source #

a smart constructor for the Conn type.

data Database Source #

An enumeration of the supported database types.

Constructors

Postgres 
MySQL 
SQLite 
Oracle 
MSSQL 

Instances

Instances details
Enum Database Source # 
Instance details

Defined in Database.GP.Conn

Show Database Source # 
Instance details

Defined in Database.GP.Conn

Eq Database Source # 
Instance details

Defined in Database.GP.Conn

type ConnectionPool = Pool Conn Source #

A pool of connections.

createConnPool Source #

Arguments

:: IConnection conn 
=> Database

the database type e.g. Postgres, MySQL, SQLite

-> String

the connection string

-> (String -> IO conn)

a function that takes a connection string and returns an IConnection

-> Double

the time (in seconds) to keep idle connections open

-> Int

the maximum number of connections to keep open

-> IO ConnectionPool

the resulting connection pool

Creates a connection pool.

withResource :: Pool a -> (a -> IO r) -> IO r #

Take a resource from the pool, perform an action with it and return it to the pool afterwards.

  • If the pool has an idle resource available, it is used immediately.
  • Otherwise, if the maximum number of resources has not yet been reached, a new resource is created and used.
  • If the maximum number of resources has been reached, this function blocks until a resource becomes available.

If the action throws an exception of any type, the resource is destroyed and not returned to the pool.

It probably goes without saying that you should never manually destroy a pooled resource, as doing so will almost certainly cause a subsequent user (who expects the resource to be valid) to throw an exception.