servant-postgresql-0.1: Useful functions and instances for using servant with a PostgreSQL context

Stabilityexperimental
MaintainerAlp Mestanogullari <alp@zalora.com>
Safe HaskellNone

Servant.PostgreSQL.Prelude

Description

An helpful wrapper around Int64 that you can tie to the standard response types in Servant.Response.Prelude with the instances defined in this module.

Synopsis

Documentation

data PGResult o Source

A wrapper around Int64, which is what PG hands us back when running execute.

The o type parameter lets us tag the result with the operation that we're running. This lets us turn results into a proper response (response body + status) differently for Add and Update for example.

Instances

Eq (PGResult o) 
Num (PGResult o) 
Ord (PGResult o) 
Show (PGResult o) 
Response (UpdateResponse Add) (PGResult Add)

If the Int64 is smaller than 1, status 400 and a suitable error message. Status 201 and empty message otherwise.

Response (UpdateResponse Delete) (PGResult Delete)

If the Int64 is smaller than 1, status 400 and a suitable error message. Status200 and empty message otherwise.

Response (UpdateResponse Update) (PGResult Update)

If the Int64 is smaller than 1, status 400 and a suitable error message. Status200 and empty message otherwise.

class ToPGResult r whereSource

Class of types that can be converted to a PGResult.

This package provides instances for Int64 and [Only Int]

Methods

fromRes :: r -> PGResult oSource

toPGResult :: ToPGResult r => IO r -> IO (PGResult o)Source

Run a database action and convert its result to a PGResult.

This will only typecheck on queries that return Int64 or [Only Int], or a custom type of yours for which you provide a ToPGResult instance.

pgresultOfInts :: IO [Only Int] -> IO (PGResult o)Source

Run an IO action that returns [Only Int] and convert the result to a PGResult.

pgresultOfInt64 :: IO Int64 -> IO (PGResult o)Source

Run an IO action that returns Int64 and convert the result to a PGResult.