-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Encoders and decoders for the PostgreSQL's binary format
--   
--   An API for dealing with PostgreSQL's binary data format.
--   
--   It can be used to implement performant bindings to Postgres. E.g.,
--   <a>"hasql"</a> is based on this library.
--   
--   It supports all Postgres versions starting from 8.3 and is tested
--   against 8.3, 9.3 and 9.5 with the <tt>integer_datetimes</tt> setting
--   off and on.
@package postgresql-binary
@version 0.12.1


-- | Reexports of all the data-types that this API supports. Useful for the
--   reduction of dependencies in the "postgresql-binary" dependent
--   libraries.
module PostgreSQL.Binary.Data

module PostgreSQL.Binary.Encoding
type Encoding = Builder
encodingBytes :: Encoding -> ByteString

-- | Turn an array builder into final value. The first parameter is OID of
--   the element type.
array :: Word32 -> Array -> Encoding

-- | A helper for encoding of arrays of single dimension from foldables.
--   The first parameter is OID of the element type.
array_foldable :: Foldable foldable => Word32 -> (element -> Maybe Encoding) -> foldable element -> Encoding

-- | A helper for encoding of arrays of single dimension from vectors. The
--   first parameter is OID of the element type.
array_vector :: Word32 -> (element -> Encoding) -> Vector element -> Encoding

-- | A helper for encoding of arrays of single dimension from vectors. The
--   first parameter is OID of the element type.
nullableArray_vector :: Word32 -> (element -> Encoding) -> Vector (Maybe element) -> Encoding

-- | A polymorphic <tt>HSTORE</tt> encoder.
hStore_foldable :: Foldable foldable => foldable (Text, Maybe Text) -> Encoding

-- | <tt>HSTORE</tt> encoder from HashMap.
hStore_hashMap :: HashMap Text (Maybe Text) -> Encoding

-- | <tt>HSTORE</tt> encoder from Map.
hStore_map :: Map Text (Maybe Text) -> Encoding
bool :: Bool -> Encoding
int2_int16 :: Int16 -> Encoding
int2_word16 :: Word16 -> Encoding
int4_int32 :: Int32 -> Encoding
int4_word32 :: Word32 -> Encoding
int8_int64 :: Int64 -> Encoding
int8_word64 :: Word64 -> Encoding
float4 :: Float -> Encoding
float8 :: Double -> Encoding
numeric :: Scientific -> Encoding
uuid :: UUID -> Encoding
inet :: NetAddr IP -> Encoding
char_utf8 :: Char -> Encoding
text_strict :: Text -> Encoding
text_lazy :: Text -> Encoding
bytea_strict :: ByteString -> Encoding
bytea_lazy :: ByteString -> Encoding
date :: Day -> Encoding
time_int :: TimeOfDay -> Encoding
time_float :: TimeOfDay -> Encoding
timetz_int :: (TimeOfDay, TimeZone) -> Encoding
timetz_float :: (TimeOfDay, TimeZone) -> Encoding
timestamp_int :: LocalTime -> Encoding
timestamp_float :: LocalTime -> Encoding
timestamptz_int :: UTCTime -> Encoding
timestamptz_float :: UTCTime -> Encoding
interval_int :: DiffTime -> Encoding
interval_float :: DiffTime -> Encoding
json_bytes :: ByteString -> Encoding
json_ast :: Value -> Encoding
jsonb_bytes :: ByteString -> Encoding
jsonb_ast :: Value -> Encoding

-- | Abstraction for encoding into multidimensional array.
data Array
encodingArray :: Encoding -> Array
nullArray :: Array
dimensionArray :: (forall b. (b -> a -> b) -> b -> c -> b) -> (a -> Array) -> c -> Array

module PostgreSQL.Binary.Decoding
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 or any other type in its undecoded form.
bytea_strict :: Value ByteString

-- | BYTEA or any other type in its undecoded form.
bytea_lazy :: Value LazyByteString

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

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

-- | A UTF-8-decoded char.
char :: Value Char

-- | Lifts a custom decoder implementation.
fn :: (ByteString -> Either Text a) -> Value a
numeric :: Value Scientific
uuid :: Value UUID
inet :: Value (NetAddr IP)
json_ast :: Value Value

-- | Given a function, which parses a plain UTF-8 JSON string encoded as a
--   byte-array, produces a decoder.
json_bytes :: (ByteString -> Either Text a) -> Value a
jsonb_ast :: Value Value

-- | 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.
jsonb_bytes :: (ByteString -> Either Text a) -> Value a

-- | <tt>DATE</tt> values decoding.
date :: Value Day

-- | <tt>TIME</tt> values decoding for servers, which have
--   <tt>integer_datetimes</tt> enabled.
time_int :: Value TimeOfDay

-- | <tt>TIME</tt> values decoding for servers, which don't have
--   <tt>integer_datetimes</tt> enabled.
time_float :: Value TimeOfDay

-- | <tt>TIMETZ</tt> values decoding for servers, which have
--   <tt>integer_datetimes</tt> enabled.
timetz_int :: Value (TimeOfDay, TimeZone)

-- | <tt>TIMETZ</tt> values decoding for servers, which don't have
--   <tt>integer_datetimes</tt> enabled.
timetz_float :: Value (TimeOfDay, TimeZone)

-- | <tt>TIMESTAMP</tt> values decoding for servers, which have
--   <tt>integer_datetimes</tt> enabled.
timestamp_int :: Value LocalTime

-- | <tt>TIMESTAMP</tt> values decoding for servers, which don't have
--   <tt>integer_datetimes</tt> enabled.
timestamp_float :: Value LocalTime

-- | <tt>TIMESTAMP</tt> values decoding for servers, which have
--   <tt>integer_datetimes</tt> enabled.
timestamptz_int :: Value UTCTime

-- | <tt>TIMESTAMP</tt> values decoding for servers, which don't have
--   <tt>integer_datetimes</tt> enabled.
timestamptz_float :: Value UTCTime

-- | <tt>INTERVAL</tt> values decoding for servers, which don't have
--   <tt>integer_datetimes</tt> enabled.
interval_int :: Value DiffTime

-- | <tt>INTERVAL</tt> values decoding for servers, which have
--   <tt>integer_datetimes</tt> enabled.
interval_float :: Value DiffTime

-- | 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:
--   
--   <pre>
--   x :: Value [ [ Text ] ]
--   x =
--     array (dimensionArray replicateM (fmap catMaybes (dimensionArray replicateM (nullableValueArray text))))
--   </pre>
data Array a

-- | Unlift an <a>Array</a> to a value <a>Value</a>.
array :: Array a -> Value a

-- | Lift a value <a>Value</a> into <a>Array</a> for parsing of
--   non-nullable leaf values.
valueArray :: Value a -> Array a

-- | Lift a value <a>Value</a> into <a>Array</a> for parsing of nullable
--   leaf values.
nullableValueArray :: Value a -> Array (Maybe a)

-- | A function for parsing a dimension of an array. Provides support for
--   multi-dimensional arrays.
--   
--   Accepts:
--   
--   <ul>
--   <li>An implementation of the <tt>replicateM</tt> function
--   (<tt>Control.Monad.<a>replicateM</a></tt>,
--   <tt>Data.Vector.<a>replicateM</a></tt>), which determines the output
--   value.</li>
--   <li>A decoder of its components, which can be either another
--   <a>dimensionArray</a> or <a>nullableValueArray</a>.</li>
--   </ul>
dimensionArray :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b
data Composite a

-- | Unlift a <a>Composite</a> to a value <a>Value</a>.
composite :: Composite a -> Value a

-- | Lift a non-nullable value <a>Value</a> into <a>Composite</a>.
valueComposite :: Value a -> Composite a

-- | Lift a value <a>Value</a> into <a>Composite</a>.
nullableValueComposite :: Value a -> Composite (Maybe a)

-- | A function for generic in place parsing of an HStore value.
--   
--   Accepts:
--   
--   <ul>
--   <li>An implementation of the <tt>replicateM</tt> function
--   (<tt>Control.Monad.<a>replicateM</a></tt>,
--   <tt>Data.Vector.<a>replicateM</a></tt>), which determines how to
--   produce the final datastructure from the rows.</li>
--   <li>A decoder for keys.</li>
--   <li>A decoder for values.</li>
--   </ul>
--   
--   Here's how you can use it to produce a parser to list:
--   
--   <pre>
--   hstoreAsList :: Value [ ( Text , Maybe Text ) ]
--   hstoreAsList =
--     hstore replicateM text text
--   </pre>
hstore :: (forall m. Monad m => Int -> m (k, Maybe v) -> m r) -> Value k -> Value v -> Value r

-- | Given a partial mapping from text to value, produces a decoder of that
--   value.
enum :: (Text -> Maybe a) -> Value a
instance GHC.Base.Functor PostgreSQL.Binary.Decoding.Array
instance GHC.Base.Monad PostgreSQL.Binary.Decoding.Composite
instance GHC.Base.Applicative PostgreSQL.Binary.Decoding.Composite
instance GHC.Base.Functor PostgreSQL.Binary.Decoding.Composite
