PostgreSQL.Binary.Decoding

postgresql-binary-0.12.1: Encoders and decoders for the PostgreSQL's binary format

Safe Haskell | None
Language | Haskell2010

PostgreSQL.Binary.Decoding

Contents

- Primitive
- Textual
- Misc
- Time
- Exotic
  - Array
  - Composite
  - HStore

Synopsis

- valueParser :: Value a -> ByteString -> Either Text a
- type Value = BinaryParser
- int :: (Integral a, Bits a) => Value a
- float4 :: Value Float
- float8 :: Value Double
- bool :: Value Bool
- bytea_strict :: Value ByteString
- bytea_lazy :: Value LazyByteString
- text_strict :: Value Text
- text_lazy :: Value LazyText
- char :: Value Char
- fn :: (ByteString -> Either Text a) -> Value a
- numeric :: Value Scientific
- uuid :: Value UUID
- inet :: Value (NetAddr IP)
- json_ast :: Value Value
- json_bytes :: (ByteString -> Either Text a) -> Value a
- jsonb_ast :: Value Value
- jsonb_bytes :: (ByteString -> Either Text a) -> Value a
- date :: Value Day
- time_int :: Value TimeOfDay
- time_float :: Value TimeOfDay
- timetz_int :: Value (TimeOfDay, TimeZone)
- timetz_float :: Value (TimeOfDay, TimeZone)
- timestamp_int :: Value LocalTime
- timestamp_float :: Value LocalTime
- timestamptz_int :: Value UTCTime
- timestamptz_float :: Value UTCTime
- interval_int :: Value DiffTime
- interval_float :: Value DiffTime
- data Array a
- array :: Array a -> Value a
- valueArray :: Value a -> Array a
- nullableValueArray :: Value a -> Array (Maybe a)
- dimensionArray :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b
- data Composite a
- composite :: Composite a -> Value a
- valueComposite :: Value a -> Composite a
- nullableValueComposite :: Value a -> Composite (Maybe a)
- hstore :: (forall m. Monad m => Int -> m (k, Maybe v) -> m r) -> Value k -> Value v -> Value r
- enum :: (Text -> Maybe a) -> Value a

# Documentation

valueParser :: Value a -> ByteString -> Either Text a #

type Value = BinaryParser #

# Primitive

int :: (Integral a, Bits a) => Value a #

float4 :: Value Float #

float8 :: Value Double #

bool :: Value Bool #

bytea_strict :: Value ByteString #

BYTEA or any other type in its undecoded form.

bytea_lazy :: Value LazyByteString #

BYTEA or any other type in its undecoded form.

# Textual

text_strict :: Value Text #

Any of the variable-length character types: BPCHAR, VARCHAR, NAME and TEXT.

text_lazy :: Value LazyText #

Any of the variable-length character types: BPCHAR, VARCHAR, NAME and TEXT.

char :: Value Char #

A UTF-8-decoded char.

# Misc

fn :: (ByteString -> Either Text a) -> Value a #

Lifts a custom decoder implementation.

numeric :: Value Scientific #

uuid :: Value UUID #

inet :: Value (NetAddr IP) #

json_ast :: Value Value #

json_bytes :: (ByteString -> Either Text a) -> Value a #

Given a function, which parses a plain UTF-8 JSON string encoded as a byte-array, produces a decoder.

jsonb_ast :: Value Value #

jsonb_bytes :: (ByteString -> Either Text a) -> Value a #

Given a function, which parses a plain UTF-8 JSON string encoded as a byte-array, produces a decoder.

For those wondering, yes, JSONB is encoded as plain JSON string in the binary format of Postgres. Sad, but true.

# Time

date :: Value Day #

`DATE` values decoding.

time_int :: Value TimeOfDay #

`TIME` values decoding for servers, which have `integer_datetimes` enabled.

time_float :: Value TimeOfDay #

`TIME` values decoding for servers, which don't have `integer_datetimes` enabled.

timetz_int :: Value (TimeOfDay, TimeZone) #

`TIMETZ` values decoding for servers, which have `integer_datetimes` enabled.

timetz_float :: Value (TimeOfDay, TimeZone) #

`TIMETZ` values decoding for servers, which don't have `integer_datetimes` enabled.

timestamp_int :: Value LocalTime #

`TIMESTAMP` values decoding for servers, which have `integer_datetimes` enabled.

timestamp_float :: Value LocalTime #

`TIMESTAMP` values decoding for servers, which don't have `integer_datetimes` enabled.

timestamptz_int :: Value UTCTime #

`TIMESTAMP` values decoding for servers, which have `integer_datetimes` enabled.

timestamptz_float :: Value UTCTime #

`TIMESTAMP` values decoding for servers, which don't have `integer_datetimes` enabled.

interval_int :: Value DiffTime #

`INTERVAL` values decoding for servers, which don't have `integer_datetimes` enabled.

interval_float :: Value DiffTime #

`INTERVAL` values decoding for servers, which have `integer_datetimes` enabled.

# Exotic

## Array

data Array a #

An efficient generic array decoder, which constructs the result value in place while parsing.

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

    x :: Value [ [ Text ] ]
    x =
      array (dimensionArray replicateM (fmap catMaybes (dimensionArray replicateM (nullableValueArray text))))

Instances

Functor Array # |
Methods fmap :: (a -> b) -> Array a -> Array b # (<$) :: a -> Array b -> Array a #

array :: Array a -> Value a #

Unlift an `Array` to a value `Value`.

valueArray :: Value a -> Array a #

Lift a value `Value` into `Array` for parsing of non-nullable leaf values.

nullableValueArray :: Value a -> Array (Maybe a) #

Lift a value `Value` into `Array` for parsing of nullable leaf values.

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

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

Accepts:

- An implementation of the `replicateM` function (`Control.Monad.`replicateM``, `Data.Vector.`replicateM``), which determines the output value.
- A decoder of its components, which can be either another `dimensionArray` or `nullableValueArray`.

## Composite

data Composite a #

Instances

Monad Composite # |
Methods (>>=) :: Composite a -> (a -> Composite b) -> Composite b # (>>) :: Composite a -> Composite b -> Composite b # return :: a -> Composite a # fail :: String -> Composite a #
Functor Composite # |
Methods fmap :: (a -> b) -> Composite a -> Composite b # (<$) :: a -> Composite b -> Composite a #
Applicative Composite # |
Methods pure :: a -> Composite a # (<*>) :: Composite (a -> b) -> Composite a -> Composite b # (*>) :: Composite a -> Composite b -> Composite b # (<*) :: Composite a -> Composite b -> Composite a #

composite :: Composite a -> Value a #

Unlift a `Composite` to a value `Value`.

valueComposite :: Value a -> Composite a #

Lift a non-nullable value `Value` into `Composite`.

nullableValueComposite :: Value a -> Composite (Maybe a) #

Lift a value `Value` into `Composite`.

## HStore

hstore :: (forall m. Monad m => Int -> m (k, Maybe v) -> m r) -> Value k -> Value v -> Value r #

A function for generic in place parsing of an HStore value.

Accepts:

- An implementation of the `replicateM` function (`Control.Monad.`replicateM``, `Data.Vector.`replicateM``), which determines how to produce the final datastructure from the rows.
- A decoder for keys.
- A decoder for values.

Here's how you can use it to produce a parser to list:

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

##

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

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