-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An efficient PostgreSQL driver and a flexible mapping API -- -- This package is the root of the "hasql" ecosystem. -- -- The API is completely disinfected from exceptions. All error-reporting -- is explicit and is presented using the Either type. -- -- The version 1 is completely backward-compatible with 0.19. @package hasql @version 1 module Hasql.Session -- | A batch of actions to be executed in the context of a database -- connection. data Session a -- | Possibly a multi-statement query, which however cannot be -- parameterized or prepared, nor can any results of it be collected. sql :: ByteString -> Session () -- | Parameters and a specification of the parametric query to apply them -- to. query :: a -> Query a b -> Session b -- | An error of some command in the session. data Error -- | An error on the client-side, with a message generated by the "libpq" -- library. Usually indicates problems with connection. ClientError :: !(Maybe ByteString) -> Error -- | Some error with a command result. ResultError :: !ResultError -> Error -- | An error with a command result. data ResultError -- | An error reported by the DB. Consists of the following: Code, message, -- details, hint. -- -- ServerError :: !ByteString -> !ByteString -> !(Maybe ByteString) -> !(Maybe ByteString) -> ResultError -- | The database returned an unexpected result. Indicates an improper -- statement or a schema mismatch. UnexpectedResult :: !Text -> ResultError -- | An error of the row reader, preceded by the index of the row. RowError :: !Int -> !RowError -> ResultError -- | An unexpected amount of rows. UnexpectedAmountOfRows :: !Int -> ResultError -- | An error during the decoding of a specific row. data RowError -- | Appears on the attempt to parse more columns than there are in the -- result. EndOfInput :: RowError -- | Appears on the attempt to parse a NULL as some value. UnexpectedNull :: RowError -- | Appears when a wrong value parser is used. Comes with the error -- details. ValueError :: !Text -> RowError -- | Executes a bunch of commands on the provided connection. run :: Session a -> Connection -> IO (Either Error a) -- | A DSL for declaration of query parameter encoders. module Hasql.Encoders -- | Encoder of some representation of the parameters product. -- -- Has instances of Contravariant, Divisible and -- Monoid, which you can use to compose multiple parameters -- together. E.g., -- --
--   someParamsEncoder :: Params (Int64, Maybe Text)
--   someParamsEncoder =
--     contramap fst (value int8) <>
--     contramap snd (nullableValue text)
--   
-- -- As a general solution for tuples of any arity, instead of fst -- and snd, consider the functions of the contrazip -- family from the "contravariant-extras" package. E.g., here's how you -- can achieve the same as the above: -- --
--   someParamsEncoder :: Params (Int64, Maybe Text)
--   someParamsEncoder =
--     contrazip2 (value int8) (nullableValue text)
--   
-- -- Here's how you can implement encoders for custom composite types: -- --
--   data Person =
--     Person { name :: Text, gender :: Gender, age :: Int }
--   
--   data Gender =
--     Male | Female
--   
--   personParams :: Params Person
--   personParams =
--     contramap name (value text) <>
--     contramap gender (value genderValue) <>
--     contramap (fromIntegral . age) (value int8)
--   
--   genderValue :: Value Gender
--   genderValue =
--     contramap genderText text
--     where
--       genderText gender =
--         case gender of
--           Male -> "male"
--           Female -> "female"
--   
data Params a -- | Encode no parameters. unit :: Params () -- | Lift an individual value encoder to a parameters encoder. value :: Value a -> Params a -- | Lift an individual nullable value encoder to a parameters encoder. nullableValue :: Value a -> Params (Maybe a) -- | An individual value encoder. Will be mapped to a single placeholder in -- the query. data Value a -- | Encoder of BOOL values. bool :: Value Bool -- | Encoder of INT2 values. int2 :: Value Int16 -- | Encoder of INT4 values. int4 :: Value Int32 -- | Encoder of INT8 values. int8 :: Value Int64 -- | Encoder of FLOAT4 values. float4 :: Value Float -- | Encoder of FLOAT8 values. float8 :: Value Double -- | Encoder of NUMERIC values. numeric :: Value Scientific -- | Encoder of CHAR values. Note that it supports UTF-8 values -- and identifies itself under the TEXT OID because of that. char :: Value Char -- | Encoder of TEXT values. text :: Value Text -- | Encoder of BYTEA values. bytea :: Value ByteString -- | Encoder of DATE values. date :: Value Day -- | Encoder of TIMESTAMP values. timestamp :: Value LocalTime -- | Encoder of TIMESTAMPTZ values. timestamptz :: Value UTCTime -- | Encoder of TIME values. time :: Value TimeOfDay -- | Encoder of TIMETZ values. timetz :: Value (TimeOfDay, TimeZone) -- | Encoder of INTERVAL values. interval :: Value DiffTime -- | Encoder of UUID values. uuid :: Value UUID -- | Encoder of INET values. inet :: Value (NetAddr IP) -- | Encoder of JSON values from JSON AST. json :: Value Value -- | Encoder of JSON values from raw JSON. jsonBytes :: Value ByteString -- | Encoder of JSONB values from JSON AST. jsonb :: Value Value -- | Encoder of JSONB values from raw JSON. jsonbBytes :: Value ByteString -- | Unlifts the Array encoder to the plain Value encoder. array :: Array a -> Value a -- | Given a function, which maps the value into the textual enum label -- from the DB side, produces a encoder of that value. enum :: (a -> Text) -> Value a -- | Identifies the value with the PostgreSQL's "unknown" type, thus -- leaving it up to Postgres to infer the actual type of the value. -- -- The bytestring needs to be encoded according to the Postgres' binary -- format of the type it expects. -- -- Essentially this is a low-level hook for encoding of values with -- custom codecs. The "postgresql-binary" library will provide you -- with the toolchain. unknown :: Value ByteString -- | A generic array encoder. -- -- Here's an example of its usage: -- --
--   x :: Value [[Int64]]
--   x =
--     array (arrayDimension foldl' (arrayDimension foldl' (arrayValue int8)))
--   
-- -- Please note that the PostgreSQL IN keyword does not "accept" an -- array, but rather a syntactical list of values, thus this encoder is -- not suited for that. Use a **field** = ANY($1) query instead. data Array a -- | Lifts the Value encoder into the Array encoder of a -- non-nullable value. arrayValue :: Value a -> Array a -- | Lifts the Value encoder into the Array encoder of a -- nullable value. arrayNullableValue :: Value a -> Array (Maybe a) -- | An encoder of an array dimension, which thus provides support for -- multidimensional arrays. -- -- Accepts: -- -- arrayDimension :: (forall a. (a -> b -> a) -> a -> c -> a) -> Array b -> Array c instance Data.Functor.Contravariant.Contravariant Hasql.Encoders.Value instance Data.Semigroup.Semigroup (Hasql.Encoders.Params a) instance GHC.Base.Monoid (Hasql.Encoders.Params a) instance Data.Functor.Contravariant.Divisible.Decidable Hasql.Encoders.Params instance Data.Functor.Contravariant.Divisible.Divisible Hasql.Encoders.Params instance Data.Functor.Contravariant.Contravariant Hasql.Encoders.Params instance Data.Default.Class.Default (Hasql.Encoders.Params ()) instance Data.Default.Class.Default (Hasql.Encoders.Value a) => Data.Default.Class.Default (Hasql.Encoders.Params (Data.Functor.Identity.Identity a)) instance (Data.Default.Class.Default (Hasql.Encoders.Value a1), Data.Default.Class.Default (Hasql.Encoders.Value a2)) => Data.Default.Class.Default (Hasql.Encoders.Params (a1, a2)) instance (Data.Default.Class.Default (Hasql.Encoders.Value a1), Data.Default.Class.Default (Hasql.Encoders.Value a2), Data.Default.Class.Default (Hasql.Encoders.Value a3)) => Data.Default.Class.Default (Hasql.Encoders.Params (a1, a2, a3)) instance (Data.Default.Class.Default (Hasql.Encoders.Value a1), Data.Default.Class.Default (Hasql.Encoders.Value a2), Data.Default.Class.Default (Hasql.Encoders.Value a3), Data.Default.Class.Default (Hasql.Encoders.Value a4)) => Data.Default.Class.Default (Hasql.Encoders.Params (a1, a2, a3, a4)) instance (Data.Default.Class.Default (Hasql.Encoders.Value a1), Data.Default.Class.Default (Hasql.Encoders.Value a2), Data.Default.Class.Default (Hasql.Encoders.Value a3), Data.Default.Class.Default (Hasql.Encoders.Value a4), Data.Default.Class.Default (Hasql.Encoders.Value a5)) => Data.Default.Class.Default (Hasql.Encoders.Params (a1, a2, a3, a4, a5)) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Types.Bool) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Int.Int16) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Int.Int32) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Int.Int64) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Types.Float) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Types.Double) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Scientific.Scientific) instance Data.Default.Class.Default (Hasql.Encoders.Value GHC.Types.Char) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Text.Internal.Text) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.ByteString.Internal.ByteString) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Time.Calendar.Days.Day) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Time.LocalTime.LocalTime.LocalTime) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Time.Clock.UTC.UTCTime) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Time.LocalTime.TimeOfDay.TimeOfDay) instance Data.Default.Class.Default (Hasql.Encoders.Value (Data.Time.LocalTime.TimeOfDay.TimeOfDay, Data.Time.LocalTime.TimeZone.TimeZone)) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Time.Clock.Scale.DiffTime) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.UUID.Types.Internal.UUID) instance Data.Default.Class.Default (Hasql.Encoders.Value Data.Aeson.Types.Internal.Value) -- | A DSL for declaration of result decoders. module Hasql.Decoders -- | Decoder of a query result. data Result a -- | Decode no value from the result. -- -- Useful for statements like INSERT or CREATE. unit :: Result () -- | Get the amount of rows affected by such statements as UPDATE -- or DELETE. rowsAffected :: Result Int64 -- | Exactly one row. Will raise the UnexpectedAmountOfRows error if -- it's any other. singleRow :: Row a -> Result a -- | Maybe one row or none. maybeRow :: Row a -> Result (Maybe a) -- | Zero or more rows packed into the vector. -- -- It's recommended to prefer this function to rowsList, since it -- performs notably better. rowsVector :: Row a -> Result (Vector a) -- | Zero or more rows packed into the list. rowsList :: Row a -> Result [a] -- | Foldl multiple rows. foldlRows :: (a -> b -> a) -> a -> Row b -> Result a -- | Foldr multiple rows. foldrRows :: (b -> a -> a) -> a -> Row b -> Result a -- | 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
--   
data Row a -- | Lift an individual non-nullable value decoder to a composable row -- decoder. value :: Value a -> Row a -- | Lift an individual nullable value decoder to a composable row decoder. nullableValue :: Value a -> Row (Maybe a) -- | Decoder of an individual value. data Value a -- | Decoder of the BOOL values. bool :: Value Bool -- | Decoder of the INT2 values. int2 :: Value Int16 -- | Decoder of the INT4 values. int4 :: Value Int32 -- | Decoder of the INT8 values. int8 :: Value Int64 -- | Decoder of the FLOAT4 values. float4 :: Value Float -- | Decoder of the FLOAT8 values. float8 :: Value Double -- | Decoder of the NUMERIC values. numeric :: Value Scientific -- | Decoder of the CHAR values. Note that it supports UTF-8 -- values. char :: Value Char -- | Decoder of the TEXT values. text :: Value Text -- | Decoder of the BYTEA values. bytea :: Value ByteString -- | Decoder of the DATE values. date :: Value Day -- | Decoder of the TIMESTAMP values. timestamp :: Value LocalTime -- | 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. timestamptz :: Value UTCTime -- | Decoder of the TIME values. time :: Value TimeOfDay -- | 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. timetz :: Value (TimeOfDay, TimeZone) -- | Decoder of the INTERVAL values. interval :: Value DiffTime -- | Decoder of the UUID values. uuid :: Value UUID -- | Decoder of the INET values. inet :: Value (NetAddr IP) -- | Decoder of the JSON values into a JSON AST. json :: Value Value -- | Decoder of the JSON values into a raw JSON ByteString. jsonBytes :: (ByteString -> Either Text a) -> Value a -- | Decoder of the JSONB values into a JSON AST. jsonb :: Value Value -- | Decoder of the JSONB values into a raw JSON -- ByteString. jsonbBytes :: (ByteString -> Either Text a) -> Value a -- | Lifts the Array decoder to the Value decoder. array :: Array a -> Value a -- | Lifts the Composite decoder to the Value decoder. composite :: Composite a -> Value a -- | 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
--   
hstore :: (forall m. Monad m => Int -> m (Text, Maybe Text) -> m a) -> Value a -- | Given a partial mapping from text to value, produces a decoder of that -- value. enum :: (Text -> Maybe a) -> Value a -- | Lifts a custom value decoder function to a Value decoder. custom :: (Bool -> ByteString -> Either Text a) -> Value a -- | 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)))
--   
data Array a -- | A function for parsing a dimension of an array. Provides support for -- multi-dimensional arrays. -- -- Accepts: -- -- arrayDimension :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b -- | Lift a Value decoder into an Array decoder for parsing -- of non-nullable leaf values. arrayValue :: Value a -> Array a -- | Lift a Value decoder into an Array decoder for parsing -- of nullable leaf values. arrayNullableValue :: Value a -> Array (Maybe a) -- | Composable decoder of composite values (rows, records). data Composite a -- | Lift a Value decoder into a Composite decoder for -- parsing of non-nullable leaf values. compositeValue :: Value a -> Composite a -- | Lift a Value decoder into a Composite decoder for -- parsing of nullable leaf values. compositeNullableValue :: Value a -> Composite (Maybe a) instance GHC.Base.Monad Hasql.Decoders.Composite instance GHC.Base.Applicative Hasql.Decoders.Composite instance GHC.Base.Functor Hasql.Decoders.Composite instance GHC.Base.Functor Hasql.Decoders.Array instance GHC.Base.Functor Hasql.Decoders.Value instance GHC.Base.Monad Hasql.Decoders.Row instance GHC.Base.Applicative Hasql.Decoders.Row instance GHC.Base.Functor Hasql.Decoders.Row instance GHC.Base.Functor Hasql.Decoders.Result instance Data.Default.Class.Default (Hasql.Decoders.Result ()) instance Data.Default.Class.Default (Hasql.Decoders.Result GHC.Int.Int64) instance Data.Default.Class.Default (Hasql.Decoders.Row a) => Data.Default.Class.Default (Hasql.Decoders.Result (GHC.Base.Maybe a)) instance Data.Default.Class.Default (Hasql.Decoders.Row a) => Data.Default.Class.Default (Hasql.Decoders.Result (Data.Vector.Vector a)) instance Data.Default.Class.Default (Hasql.Decoders.Row a) => Data.Default.Class.Default (Hasql.Decoders.Result [a]) instance Data.Default.Class.Default (Hasql.Decoders.Row a) => Data.Default.Class.Default (Hasql.Decoders.Result (Data.Functor.Identity.Identity a)) instance Data.Default.Class.Default (Hasql.Decoders.Value a) => Data.Default.Class.Default (Hasql.Decoders.Row (Data.Functor.Identity.Identity a)) instance Data.Default.Class.Default (Hasql.Decoders.Value a) => Data.Default.Class.Default (Hasql.Decoders.Row (GHC.Base.Maybe a)) instance (Data.Default.Class.Default (Hasql.Decoders.Value a1), Data.Default.Class.Default (Hasql.Decoders.Value a2)) => Data.Default.Class.Default (Hasql.Decoders.Row (a1, a2)) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Types.Bool) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Int.Int16) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Int.Int32) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Int.Int64) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Types.Float) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Types.Double) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Scientific.Scientific) instance Data.Default.Class.Default (Hasql.Decoders.Value GHC.Types.Char) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Text.Internal.Text) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.ByteString.Internal.ByteString) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Time.Calendar.Days.Day) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Time.LocalTime.LocalTime.LocalTime) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Time.Clock.UTC.UTCTime) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Time.LocalTime.TimeOfDay.TimeOfDay) instance Data.Default.Class.Default (Hasql.Decoders.Value (Data.Time.LocalTime.TimeOfDay.TimeOfDay, Data.Time.LocalTime.TimeZone.TimeZone)) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Time.Clock.Scale.DiffTime) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.UUID.Types.Internal.UUID) instance Data.Default.Class.Default (Hasql.Decoders.Value Data.Aeson.Types.Internal.Value) module Hasql.Query -- | An abstraction over parametric queries. -- -- It is composable using the standard interfaces of the category theory, -- which it has instances of. E.g., here's how you can compose queries -- using the Arrow notation: -- --
--   -- |
--   -- Given an Update query,
--   -- which uses the @fmap (> 0) rowsAffected@ decoder
--   -- to detect, whether it had any effect,
--   -- and an Insert query,
--   -- produces a query which performs Upsert.
--   composeUpsert :: Query a Bool -> Query a () -> Query a ()
--   composeUpsert update insert =
--     proc params -> do
--       updated <- update -< params
--       if updated
--         then returnA -< ()
--         else insert -< params
--   
data Query a b -- | A specification of a strictly single-statement query, which can be -- parameterized and prepared. -- -- Consists of the following: -- -- -- -- The SQL template must be formatted according to Postgres' standard, -- with any non-ASCII characters of the template encoded using UTF-8. -- According to the format, parameters must be referred to using the -- positional notation, as in the following: $1, $2, -- $3 and etc. Those references must be used to refer to the -- values of the Params encoder. -- -- Following is an example of the declaration of a prepared statement -- with its associated codecs. -- --
--   selectSum :: Hasql.Query.Query (Int64, Int64) Int64
--   selectSum =
--     Hasql.Query.statement sql encoder decoder True
--     where
--       sql =
--         "select ($1 + $2)"
--       encoder =
--         contramap fst (Hasql.Encoders.value Hasql.Encoders.int8) <>
--         contramap snd (Hasql.Encoders.value Hasql.Encoders.int8)
--       decoder =
--         Hasql.Decoders.singleRow (Hasql.Decoders.value Hasql.Decoders.int8)
--   
-- -- The statement above accepts a product of two parameters of type -- Int64 and produces a single result of type Int64. statement :: ByteString -> Params a -> Result b -> Bool -> Query a b -- | This module provides a low-level effectful API dealing with the -- connections to the database. module Hasql.Connection -- | A single connection to the database. data Connection -- | Possible details of the connection acquistion error. type ConnectionError = Maybe ByteString -- | Acquire a connection using the provided settings encoded according to -- the PostgreSQL format. acquire :: Settings -> IO (Either ConnectionError Connection) -- | Release the connection. release :: Connection -> IO () -- | All settings encoded in a single byte-string according to the -- PostgreSQL format. type Settings = ByteString -- | Encode a host, a port, a user, a password and a database into the -- PostgreSQL settings byte-string. settings :: ByteString -> Word16 -> ByteString -> ByteString -> ByteString -> Settings -- | Execute an operation on the raw libpq Connection. -- -- The access to the connection is exclusive. withLibPQConnection :: Connection -> (Connection -> IO a) -> IO a