| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Class
Contents
- stmtList :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a [b]
- stmtUnit :: Encodable a => ByteString -> Bool -> Query a ()
- stmtVector :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a (Vector b)
- stmtMaybe :: (Encodable a, Decodable b) => ByteString -> Bool -> Query a (Maybe b)
- class Encodable a where
- class Decodable a where
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
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)" TrueMinimal complete definition
Nothing
Instances
class Decodable a where Source
Datatypes that can be encoded as hasql PostgreSQL parameters. This
class can be generically derived.
Minimal complete definition
Nothing
Instances