Copyright | 2013-2017 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | ex8k.hibino@gmail.com |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
This module defines templates for Haskell record type and type class instances to map between list of untyped SQL type and Haskell record type.
- defineRecord :: TypeQ -> ConName -> [(VarName, TypeQ)] -> [Name] -> Q [Dec]
- defineRecordWithConfig :: TypeQ -> NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]
- defineHasColumnConstraintInstance :: TypeQ -> TypeQ -> Int -> Q [Dec]
- defineHasPrimaryConstraintInstanceDerived :: TypeQ -> Q [Dec]
- defineHasPrimaryKeyInstance :: TypeQ -> [Int] -> Q [Dec]
- defineHasNotNullKeyInstance :: TypeQ -> Int -> Q [Dec]
- defineRecordType :: ConName -> [(VarName, TypeQ)] -> [Name] -> Q [Dec]
- defineRecordTypeWithConfig :: NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]
- defineColumnOffsets :: ConName -> [TypeQ] -> Q [Dec]
- recordWidthTemplate :: TypeQ -> ExpQ
- reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))
- data NameConfig
- defaultNameConfig :: NameConfig
- recordTypeName :: NameConfig -> String -> String -> ConName
- columnName :: NameConfig -> String -> String -> VarName
- recordTemplate :: NameConfig -> String -> String -> (TypeQ, ExpQ)
- columnOffsetsVarNameDefault :: Name -> VarName
- deriveNotNullType :: TypeQ -> Q [Dec]
- defineTupleInstances :: Int -> Q [Dec]
Generate all templates about record
:: TypeQ | SQL value type |
-> ConName | Record type name |
-> [(VarName, TypeQ)] | Column schema |
-> [Name] | Record derivings |
-> Q [Dec] | Result declarations |
All templates for record type.
defineRecordWithConfig Source #
:: TypeQ | SQL value type |
-> NameConfig | name rule config |
-> String | Schema name |
-> String | Table name |
-> [(String, TypeQ)] | Column names and types |
-> [Name] | Record derivings |
-> Q [Dec] | Result declarations |
All templates for record type with configured names.
Table constraint specified by key
defineHasColumnConstraintInstance Source #
:: TypeQ | Type which represent constraint type |
-> TypeQ | Type constructor of record |
-> Int | Key index which specifies this constraint |
-> Q [Dec] | Result declaration template |
Template of HasColumnConstraint
instance.
defineHasPrimaryConstraintInstanceDerived Source #
Template of HasKeyConstraint
instance.
defineHasPrimaryKeyInstance Source #
:: TypeQ | Type constructor of record |
-> [Int] | Key index which specifies this constraint |
-> Q [Dec] | Declaration of primary key constraint instance |
Template of HasColumnConstraint
Primary
instance.
defineHasNotNullKeyInstance Source #
:: TypeQ | Type constructor of record |
-> Int | Key index which specifies this constraint |
-> Q [Dec] | Declaration of not null key constraint instance |
Template of HasColumnConstraint
NotNull
instance.
Record type
:: ConName | Name of the data type of table record type. |
-> [(VarName, TypeQ)] | List of columns in the table. Must be legal, properly cased record columns. |
-> [Name] | Deriving type class names. |
-> Q [Dec] | The data type record declaration. |
Record type declaration template.
defineRecordTypeWithConfig :: NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec] Source #
Record type declaration template with configured names.
Function declarations against defined record types
:: ConName | Record type constructor. |
-> [TypeQ] | Types of record columns. |
-> Q [Dec] | Declaration of |
Column offset array and PersistableWidth
instance declaration.
Record type width expression template.
Reify
reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ])) Source #
Low-level reify interface for record type name.
Templates about record name
data NameConfig Source #
NameConfig
type to customize names of expanded record templates.
Show NameConfig Source # | Dummy show instance. Handy to define show instance recursively. |
defaultNameConfig :: NameConfig Source #
Default implementation of NameConfig
type.
To customize this, use record update syntax.
recordTypeName :: NameConfig -> String -> String -> ConName Source #
Make record type symbol name from schema name and table name in SQL
columnName :: NameConfig -> String -> String -> VarName Source #
Make column variable symbol name from table name and column name in SQL
:: NameConfig | name rule config |
-> String | Schema name string in SQL |
-> String | Table name string in SQL |
-> (TypeQ, ExpQ) | Record type and data constructor |
Record constructor templates from SQL table name String
.
columnOffsetsVarNameDefault Source #
Variable expression of record column offset array.