hasql-0.19.15: A very efficient PostgreSQL driver and a flexible mapping API

Safe HaskellNone
LanguageHaskell2010

Hasql.Decoders

Contents

Description

A DSL for declaration of result decoders.

Synopsis

Result

data Result a Source #

Decoder of a query result.

Instances

Functor Result Source # 

Methods

fmap :: (a -> b) -> Result a -> Result b #

(<$) :: a -> Result b -> Result a #

Default (Result Int64) Source #

Maps to rowsAffected.

Methods

def :: Result Int64 #

Default (Row a) => Default (Result [a]) Source #

Maps to (rowsList def).

Methods

def :: Result [a] #

Default (Row a) => Default (Result (Maybe a)) Source #

Maps to (maybeRow def).

Methods

def :: Result (Maybe a) #

Default (Result ()) Source #

Maps to unit.

Methods

def :: Result () #

Default (Row a) => Default (Result (Identity a)) Source #

Maps to (fmap Identity (singleRow def).

Methods

def :: Result (Identity a) #

Default (Row a) => Default (Result (Vector a)) Source #

Maps to (rowsVector def).

Methods

def :: Result (Vector a) #

unit :: Result () Source #

Decode no value from the result.

Useful for statements like INSERT or CREATE.

rowsAffected :: Result Int64 Source #

Get the amount of rows affected by such statements as UPDATE or DELETE.

singleRow :: Row a -> Result a Source #

Exactly one row. Will raise the UnexpectedAmountOfRows error if it's any other.

Specialized multi-row results

maybeRow :: Row a -> Result (Maybe a) Source #

Maybe one row or none.

rowsVector :: Row a -> Result (Vector a) Source #

Zero or more rows packed into the vector.

It's recommended to prefer this function to rowsList, since it performs notably better.

rowsList :: Row a -> Result [a] Source #

Zero or more rows packed into the list.

Multi-row traversers

foldlRows :: (a -> b -> a) -> a -> Row b -> Result a Source #

Foldl multiple rows.

foldrRows :: (b -> a -> a) -> a -> Row b -> Result a Source #

Foldr multiple rows.

Row

data Row a Source #

Decoder of an individual row, which gets composed of column value decoders.

E.g.:

x :: Row (Maybe Int64, Text, TimeOfDay)
x =
  (,,) <$> nullableValue int8 <*> value text <*> value time

Instances

Monad Row Source # 

Methods

(>>=) :: Row a -> (a -> Row b) -> Row b #

(>>) :: Row a -> Row b -> Row b #

return :: a -> Row a #

fail :: String -> Row a #

Functor Row Source # 

Methods

fmap :: (a -> b) -> Row a -> Row b #

(<$) :: a -> Row b -> Row a #

Applicative Row Source # 

Methods

pure :: a -> Row a #

(<*>) :: Row (a -> b) -> Row a -> Row b #

(*>) :: Row a -> Row b -> Row b #

(<*) :: Row a -> Row b -> Row a #

Default (Value a) => Default (Row (Maybe a)) Source # 

Methods

def :: Row (Maybe a) #

(Default (Value a1), Default (Value a2)) => Default (Row (a1, a2)) Source # 

Methods

def :: Row (a1, a2) #

Default (Value a) => Default (Row (Identity a)) Source # 

Methods

def :: Row (Identity a) #

value :: Value a -> Row a Source #

Lift an individual non-nullable value decoder to a composable row decoder.

nullableValue :: Value a -> Row (Maybe a) Source #

Lift an individual nullable value decoder to a composable row decoder.

Value

data Value a Source #

Decoder of an individual value.

Instances

bool :: Value Bool Source #

Decoder of the BOOL values.

int2 :: Value Int16 Source #

Decoder of the INT2 values.

int4 :: Value Int32 Source #

Decoder of the INT4 values.

int8 :: Value Int64 Source #

Decoder of the INT8 values.

float4 :: Value Float Source #

Decoder of the FLOAT4 values.

float8 :: Value Double Source #

Decoder of the FLOAT8 values.

numeric :: Value Scientific Source #

Decoder of the NUMERIC values.

char :: Value Char Source #

Decoder of the CHAR values. Note that it supports UTF-8 values.

text :: Value Text Source #

Decoder of the TEXT values.

bytea :: Value ByteString Source #

Decoder of the BYTEA values.

date :: Value Day Source #

Decoder of the DATE values.

timestamp :: Value LocalTime Source #

Decoder of the TIMESTAMP values.

timestamptz :: Value UTCTime Source #

Decoder of the TIMESTAMPTZ values.

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.

time :: Value TimeOfDay Source #

Decoder of the TIME values.

timetz :: Value (TimeOfDay, TimeZone) Source #

Decoder of the TIMETZ values.

Unlike in case of TIMESTAMPTZ, Postgres does store the timezone information for TIMETZ. However the Haskell's "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.

interval :: Value DiffTime Source #

Decoder of the INTERVAL values.

uuid :: Value UUID Source #

Decoder of the UUID values.

json :: Value Value Source #

Decoder of the JSON values into a JSON AST.

jsonBytes :: (ByteString -> Either Text a) -> Value a Source #

Decoder of the JSON values into a raw JSON ByteString.

jsonb :: Value Value Source #

Decoder of the JSONB values into a JSON AST.

jsonbBytes :: (ByteString -> Either Text a) -> Value a Source #

Decoder of the JSONB values into a raw JSON ByteString.

array :: Array a -> Value a Source #

Lifts the Array decoder to the Value decoder.

composite :: Composite a -> Value a Source #

Lifts the Composite decoder to the Value decoder.

hstore :: (forall m. Monad m => Int -> m (Text, Maybe Text) -> m a) -> Value a Source #

A generic decoder of HSTORE values.

Here's how you can use it to construct a specific value:

x :: Value [(Text, Maybe Text)]
x =
  hstore replicateM

enum :: (Text -> Maybe a) -> Value a Source #

Given a partial mapping from text to value, produces a decoder of that value.

custom :: (Bool -> ByteString -> Either Text a) -> Value a Source #

Lifts a custom value decoder function to a Value decoder.

Array

data Array a Source #

A generic array decoder.

Here's how you can use it to produce a specific array value decoder:

x :: Value [[Text]]
x =
  array (arrayDimension replicateM (arrayDimension replicateM (arrayValue text)))

Instances

Functor Array Source # 

Methods

fmap :: (a -> b) -> Array a -> Array b #

(<$) :: a -> Array b -> Array a #

arrayDimension :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b Source #

A function for parsing a dimension of an array. Provides support for multi-dimensional arrays.

Accepts:

arrayValue :: Value a -> Array a Source #

Lift a Value decoder into an Array decoder for parsing of non-nullable leaf values.

arrayNullableValue :: Value a -> Array (Maybe a) Source #

Lift a Value decoder into an Array decoder for parsing of nullable leaf values.

Composite

data Composite a Source #

Composable decoder of composite values (rows, records).

Instances

Monad Composite Source # 

Methods

(>>=) :: Composite a -> (a -> Composite b) -> Composite b #

(>>) :: Composite a -> Composite b -> Composite b #

return :: a -> Composite a #

fail :: String -> Composite a #

Functor Composite Source # 

Methods

fmap :: (a -> b) -> Composite a -> Composite b #

(<$) :: a -> Composite b -> Composite a #

Applicative Composite Source # 

Methods

pure :: a -> Composite a #

(<*>) :: Composite (a -> b) -> Composite a -> Composite b #

(*>) :: Composite a -> Composite b -> Composite b #

(<*) :: Composite a -> Composite b -> Composite a #

compositeValue :: Value a -> Composite a Source #

Lift a Value decoder into a Composite decoder for parsing of non-nullable leaf values.

compositeNullableValue :: Value a -> Composite (Maybe a) Source #

Lift a Value decoder into a Composite decoder for parsing of nullable leaf values.