hasql-class-0.0.0.1: Encodable and Decodable classes for hasql

Safe HaskellNone
LanguageHaskell2010

Hasql.Class

Contents

Synopsis

Query helpers

Utility functions for Querys. The ByteString argument is the SQL, and the Bool argument is whether to use prepared statements.

stmtList :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a [b] Source

Make a Query that returns a list of values

getPeople :: Query () Person
getPeople = stmtList "SELECT * FROM person" True

stmtUnit :: Encodable a => ByteString -> Bool -> Query a () Source

Make a Query that returns () (no result).

insertVal :: Query Text ()
insertVal = stmtUnit "INSERT INTO tbl VALUES ($1)" True

stmtVector :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a (Vector b) Source

Make a Query that returns a Vector of values

Faster than stmtList.

stmtMaybe :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a (Maybe b) Source

Make a Query that Maybe returns a value

Classes

class Encodable a where Source

Datatypes that can be encoded as hasql PostgreSQL parameters. This class can be generically derived.

Note that the number of parameters is not necessarily the number of Haskell values. For example

data MyData = MyData { aChar :: Char, aText :: Text }
 deriving (Eq, Show, Generic, Encodable)

aData :: MyData
aData = MyDate 'a' "ha!"

-- Will only insert the char, and a NULL for the text value
wrong = query aData stmtUnit "INSERT INTO myTable ($1)" True

-- Will insert both the char and the text values
right = query aData stmtUnit "INSERT INTO myTable ($1, $2)" True

Minimal complete definition

Nothing

Methods

encode :: Params a Source