hasql-0.19.18: An efficient PostgreSQL driver and a flexible mapping API

Safe Haskell | None
Language | Haskell2010

Hasql.Session

Contents

- Execution

Synopsis

- data Session a
- sql :: ByteString -> Session ()
- query :: a -> Query a b -> Session b
- data Error
  - = ClientError !(Maybe ByteString)
  - | ResultError !ResultError
- data ResultError
  - = ServerError !ByteString !ByteString !(Maybe ByteString) !(Maybe ByteString)
  - | UnexpectedResult !Text
  - | RowError !Int !RowError
  - | UnexpectedAmountOfRows !Int
- data RowError
  - = EndOfInput
  - | UnexpectedNull
  - | ValueError !Text
- run :: Session a -> Connection -> IO (Either Error a)

# Documentation

data Session a #

A batch of actions to be executed in the context of a database connection.

Instances

Monad Session # |
Methods (>>=) :: Session a -> (a -> Session b) -> Session b # (>>) :: Session a -> Session b -> Session b # return :: a -> Session a # fail :: String -> Session a #
Functor Session # |
Methods fmap :: (a -> b) -> Session a -> Session b # (<$) :: a -> Session b -> Session a #
Applicative Session # |
Methods pure :: a -> Session a # (<*>) :: Session (a -> b) -> Session a -> Session b # (*>) :: Session a -> Session b -> Session b # (<*) :: Session a -> Session b -> Session a #
MonadIO Session # |
Methods liftIO :: IO a -> Session a #
MonadError Error Session # |
Methods throwError :: Error -> Session a # catchError :: Session a -> (Error -> Session a) -> Session a #

sql :: ByteString -> Session () #

Possibly a multi-statement query, which however cannot be parameterized or prepared, nor can any results of it be collected.

query :: a -> Query a b -> Session b #

Parameters and a specification of the parametric query to apply them to.

# Execution

data Error #

An error of some command in the session.

Constructors

ClientError !(Maybe ByteString) | An error on the client-side, with a message generated by the "libpq" library. Usually indicates problems with connection.
ResultError !ResultError | Some error with a command result.

Instances

Eq Error # |
Methods (==) :: Error -> Error -> Bool # (/=) :: Error -> Error -> Bool #
Show Error # |
Methods showsPrec :: Int -> Error -> ShowS # show :: Error -> String # showList :: [Error] -> ShowS #
MonadError Error Session # |
Methods throwError :: Error -> Session a # catchError :: Session a -> (Error -> Session a) -> Session a #

data ResultError #

An error with a command result.

Constructors

ServerError !ByteString !ByteString !(Maybe ByteString) !(Maybe ByteString) | An error reported by the DB. Consists of the following: Code, message, details, hint. Code. The SQLSTATE code for the error. It's recommended to use the "postgresql-error-codes" package to work with those. Message. The primary human-readable error message (typically one line). Always present. Details. An optional secondary error message carrying more detail about the problem. Might run to multiple lines. Hint. An optional suggestion on what to do about the problem. This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts. Might run to multiple lines.
UnexpectedResult !Text | The database returned an unexpected result. Indicates an improper statement or a schema mismatch.
RowError !Int !RowError | An error of the row reader, preceded by the index of the row.
UnexpectedAmountOfRows !Int | An unexpected amount of rows.

Instances

Eq ResultError # |
Methods (==) :: ResultError -> ResultError -> Bool # (/=) :: ResultError -> ResultError -> Bool #
Show ResultError # |
Methods showsPrec :: Int -> ResultError -> ShowS # show :: ResultError -> String # showList :: [ResultError] -> ShowS #

data RowError #

An error during the decoding of a specific row.

Constructors

EndOfInput | Appears on the attempt to parse more columns than there are in the result.
UnexpectedNull | Appears on the attempt to parse a `NULL` as some value.
ValueError !Text | Appears when a wrong value parser is used. Comes with the error details.

Instances

Eq RowError # |
Methods (==) :: RowError -> RowError -> Bool # (/=) :: RowError -> RowError -> Bool #
Show RowError # |
Methods showsPrec :: Int -> RowError -> ShowS # show :: RowError -> String # showList :: [RowError] -> ShowS #

run :: Session a -> Connection -> IO (Either Error a) #

Executes a bunch of commands on the provided connection.