Copyright | (c) Ole Krüger 2015-2016 |
---|---|
License | BSD3 |
Maintainer | Ole Krüger <ole@vprsm.de> |
Safe Haskell | None |
Language | Haskell2010 |
- data TableDescription = TableDescription {}
- class DescribableTable a => Table a where
- insert :: a -> Errand (Reference a)
- find :: HasID i => i a -> Errand (Row a)
- update :: HasID i => i a -> a -> Errand ()
- delete :: HasID i => i a -> Errand ()
- createQuery :: Proxy a -> Query
- tableResultProcessor :: ResultProcessor [Row a]
- tableRefResultProcessor :: ResultProcessor [Reference a]
- data Row a = Row {}
- newtype Reference a = Reference Int64
- class HasID a where
- referenceID :: a b -> Int64
- data TableConstraint
- mkTable :: Name -> [TableConstraint] -> Q [Dec]
- mkCreateQuery :: Name -> Q Exp
Documentation
data TableDescription Source
Description of a table type
TableDescription | |
|
class DescribableTable a => Table a where Source
insert :: a -> Errand (Reference a) Source
Insert a row into the table and return a Reference
to the inserted row.
find :: HasID i => i a -> Errand (Row a) Source
Find the row identified by the given reference.
update :: HasID i => i a -> a -> Errand () Source
Update an existing row.
delete :: HasID i => i a -> Errand () Source
Delete a row from the table.
createQuery :: Proxy a -> Query Source
Generate the query which creates this table inside the database.
Use mkCreateQuery
for convenience.
tableResultProcessor :: ResultProcessor [Row a] Source
Extract rows from a result set.
tableRefResultProcessor :: ResultProcessor [Reference a] Source
Extract only a Reference
to each row.
Resolved row
Reference to a row
A value of that type contains an ID.
referenceID :: a b -> Int64 Source
Retrieve the underlying ID.
data TableConstraint Source
Options to mkTable
.
Unique [Name] | A combination of fields must be unique.
|
ForeignKey [Name] Name [Name] | A combination of fields references another combination of fields from a different table.
|
mkTable :: Name -> [TableConstraint] -> Q [Dec] Source
Implement Table
for a data type. The given type must fulfill these requirements:
- Data type
- No type context
- No type variables
- One record constructor with 1 or more fields
- All field types must have an instance of
Column
Example:
{-# LANGUAGE TemplateHaskell #-} module Movies where ... data Movie = Movie { movieTitle :: String, movieYear :: Int } deriving ShowmkTable
''Movie [] data Actor = Actor { actorName :: String, actorAge :: Int } deriving ShowmkTable
''Actor [] data MovieCast = MovieCast { movieCastMovie ::Reference
Movie, movieCastActor ::Reference
Actor } deriving ShowmkTable
''MovieCast []
mkCreateQuery :: Name -> Q Exp Source
Generate a Query
which will create the table described my the given type.
Example:
data Table = Table { myField :: Int }mkTable
''Table [] ...query_
$(mkCreateQuery
''Table)