hasql-postgres-0.8.0: A "PostgreSQL" backend for the "hasql" library

Safe HaskellNone
LanguageHaskell2010

Hasql.Postgres

Description

This module contains everything required to use "hasql" with Postgres. For information on how it should be used consult the "hasql" docs.

Please note that there is a few limitations inflicted by Postgres, encoding which in the type system would seriously burden the API, so it was decided to make it the user's responsibility to make sure that certain conditions are satisfied during the runtime. Particularly this concerns the Mapping instances of Maybe, [] and Vector. For details consult the docs on those instances.

Synopsis

Documentation

type Postgres = Settings Source

Just an alias to settings, which is used as a more descriptive identifier type of the backend.

data Settings Source

Connection settings.

Constructors

ParamSettings ByteString Word16 ByteString ByteString ByteString

A host, a port, a user, a password and a database.

StringSettings ByteString

All settings encoded in a single byte string according to the PostgreSQL format.

Instances

Show Settings 
Backend Postgres 
Mapping Postgres Bool

Maps to bool.

Mapping Postgres Char

Maps to char. Note that it supports UTF-8 values.

Mapping Postgres Double

Maps to float8.

Mapping Postgres Float

Maps to float4.

Mapping Postgres Int

Maps to int8.

Mapping Postgres Int8

Maps to int2.

Mapping Postgres Int16

Maps to int2.

Mapping Postgres Int32

Maps to int4.

Mapping Postgres Int64

Maps to int8.

Mapping Postgres Word

Maps to int8.

Mapping Postgres Word8

Maps to int2.

Mapping Postgres Word16

Maps to int2.

Mapping Postgres Word32

Maps to int4.

Mapping Postgres Word64

Maps to int8.

Mapping Postgres ByteString

Maps to bytea.

Mapping Postgres Text

Maps to text.

Mapping Postgres UUID

Maps to uuid.

Mapping Postgres DiffTime

Maps to interval.

Mapping Postgres Day

Maps to date.

Mapping Postgres UTCTime

Maps to timestamptz.

NOTICE

Postgres does not store the timezone information of timestamptz. Instead it stores a UTC value and performs silent conversions to the currently set timezone, when dealt with in the text format. However this library bypasses the silent conversions and communicates with Postgres using the UTC values directly.

Mapping Postgres TimeOfDay

Maps to time.

Mapping Postgres LocalTime

Maps to timestamp.

Mapping Postgres Scientific

Maps to numeric.

(Mapping a, ArrayMapping a) => Mapping Postgres [a]

Maps to Postgres arrays.

LIMITATION 1

In multidimensional lists all rows of a dimension must have the same length.

E.g., the following is a corrupt value:

[[1,2], [3]]

The following is a valid one:

[[1,2], [3,4], [5,6]]

LIMITATION 2

Maybe cannot be used to wrap an intermediate level in a multidimensional list.

E.g., the following is a corrupt type:

[Maybe [a]]

However, both the first level list and the value are allowed to be wrapped in Maybe. So the following is a valid type:

Maybe [[[Maybe a]]]

NOTICE

Also, please note that since String is just an alias to [Char], it will be mapped to an array of characters. So if you want to map to a textual type use Text instead.

Mapping a => Mapping Postgres (Maybe a)

Maps to the same type as the underlying value, encoding Nothing as NULL.

LIMITATION

Multilevel Maybes are not supported. E.g., a value Just Nothing of type (Maybe (Maybe a)) will be encoded the same way as Nothing.

(Mapping a, ArrayMapping a) => Mapping Postgres (Vector a)

Maps to Postgres' arrays.

Same rules as for the list instance apply. Consult its docs for details.

Mapping Postgres (TimeOfDay, TimeZone)

Maps to timetz.

Unlike with timestamptz, Postgres does store the timezone information for timetz. However the "time" library does not contain any composite type, that fits the task, so we use a pair of TimeOfDay and TimeZone to represent a value on the Haskell's side.

data Connection Postgres = Connection {} 
data Result Postgres = Result Environment (Maybe ByteString) 
data StatementArgument Postgres = StatementArgument Oid (Environment -> Maybe ByteString)