@hackage hasql-postgresql-types0.1.0.1

Integration of "hasql" with "postgresql-types"

hasql-postgresql-types

Hackage Continuous Haddock

Integration of "hasql" with "postgresql-types" via the IsScalar typeclass from "postgresql-types-algebra". Provides automatic encoder and decoder generation for precise PostgreSQL scalar types.

Motivation

The standard "hasql" codecs use common Haskell types like Text, DiffTime, UTCTime, etc. However these types do not always map precisely to PostgreSQL types. E.g., the PostgreSQL interval type carries information about months, years and microseconds, while the Haskell DiffTime type only represents a time difference in picoseconds. Such mismatches can lead to data loss or unexpected behavior. The "postgresql-types" library addresses such issues by providing precise Haskell representations for PostgreSQL types. This package integrates it with "hasql". It also provides a class-based polymorphic interface for defining "hasql" Value codecs.

Usage

import Hasql.PostgresqlTypes (encoder, decoder)
import qualified PostgresqlTypes as Pt
import qualified Hasql.Statement as Statement
import qualified Hasql.Encoders as Encoders
import qualified Hasql.Decoders as Decoders

myStatement :: Statement.Statement Pt.Timestamptz [Pt.Timestamptz]
myStatement = Statement.preparable sql enc dec
  where
    sql = "SELECT $1::timestamptz"
    enc = Encoders.param (Encoders.nonNullable encoder)
    dec = Decoders.rowList (Decoders.column (Decoders.nonNullable decoder))