Copyright | 2013-2019 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Database.Relational.TH
Description
This module defines templates for Haskell record type and type class instances to define column projection on SQL query like Haskell records. Templates are generated by also using functions of Database.Record.TH module, so mapping between list of untyped SQL type and Haskell record type will be done too.
Synopsis
- defineTable :: Config -> String -> String -> [(String, TypeQ)] -> [Name] -> [Int] -> Maybe Int -> Q [Dec]
- unsafeInlineQuery :: TypeQ -> TypeQ -> String -> VarName -> Q [Dec]
- inlineQuery :: Name -> Relation p r -> Config -> QuerySuffix -> String -> Q [Dec]
- defineTableTypesAndRecord :: Config -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]
- defineHasPrimaryKeyInstance :: TypeQ -> TypeQ -> [Int] -> Q [Dec]
- defineHasPrimaryKeyInstanceWithConfig :: Config -> String -> String -> TypeQ -> [Int] -> Q [Dec]
- defineHasNotNullKeyInstance :: TypeQ -> Int -> Q [Dec]
- defineHasNotNullKeyInstanceWithConfig :: Config -> String -> String -> Int -> Q [Dec]
- defineScalarDegree :: TypeQ -> Q [Dec]
- defineColumnsDefault :: ConName -> [(String, TypeQ)] -> Q [Dec]
- defineOverloadedColumnsDefault :: ConName -> [(String, TypeQ)] -> Q [Dec]
- defineColumns :: ConName -> [(VarName, TypeQ)] -> Q [Dec]
- defineOverloadedColumns :: ConName -> [(String, TypeQ)] -> Q [Dec]
- defineTuplePi :: Int -> Q [Dec]
- defineTableTypes :: VarName -> VarName -> VarName -> VarName -> TypeQ -> String -> [String] -> Q [Dec]
- defineTableTypesWithConfig :: Config -> String -> String -> [(String, TypeQ)] -> Q [Dec]
- definePrimaryQuery :: VarName -> TypeQ -> TypeQ -> ExpQ -> Q [Dec]
- definePrimaryUpdate :: VarName -> TypeQ -> TypeQ -> ExpQ -> Q [Dec]
- derivationExpDefault :: String -> ExpQ
- tableVarExpDefault :: String -> ExpQ
- relationVarExp :: Config -> String -> String -> ExpQ
- defineSqlsWithPrimaryKey :: VarName -> VarName -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> Q [Dec]
- defineSqlsWithPrimaryKeyDefault :: String -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> Q [Dec]
- makeRelationalRecordDefault :: Name -> Q [Dec]
- makeRelationalRecordDefault' :: Config -> Name -> Q [Dec]
- reifyRelation :: Name -> Q (Type, Type)
All templates about table
Arguments
:: Config | Configuration to generate query with |
-> String | Schema name string of Database |
-> String | Table name string of Database |
-> [(String, TypeQ)] | Column names and types |
-> [Name] | derivings for Record type |
-> [Int] | Primary key index |
-> Maybe Int | Not null key index |
-> Q [Dec] | Result declarations |
Generate all templtes about table using specified naming rule.
Inlining typed Query
Arguments
:: TypeQ | Query parameter type |
-> TypeQ | Query result type |
-> String | SQL string query to inline |
-> VarName | Variable name for inlined query |
-> Q [Dec] | Result declarations |
Unsafely inlining SQL string Query
in compile type.
Arguments
:: Name | Top-level variable name which has |
-> Relation p r | Object which has |
-> Config | Configuration to generate SQL |
-> QuerySuffix | suffix SQL words |
-> String | Variable name to define as inlined query |
-> Q [Dec] | Result declarations |
Inlining composed Query
in compile type.
Column projections and basic Relation
for Haskell record
defineTableTypesAndRecord Source #
Arguments
:: Config | Configuration to generate query with |
-> String | Schema name |
-> String | Table name |
-> [(String, TypeQ)] | Column names and types |
-> [Name] | Record derivings |
-> Q [Dec] | Result declarations |
Make templates about table, column and haskell record using specified naming rule.
Constraint key templates
defineHasPrimaryKeyInstance Source #
Arguments
:: TypeQ | Record type |
-> TypeQ | Key type |
-> [Int] | Indexes specifies key |
-> Q [Dec] | Result constraint key declarations |
Rule template to infer primary key.
defineHasPrimaryKeyInstanceWithConfig Source #
Arguments
:: Config | configuration parameters |
-> String | Schema name |
-> String | Table name |
-> TypeQ | Column type |
-> [Int] | Primary key index |
-> Q [Dec] | Declarations of primary constraint key |
Rule template to infer primary key.
defineHasNotNullKeyInstance Source #
Rule template to infer not-null key.
defineHasNotNullKeyInstanceWithConfig Source #
Arguments
:: Config | configuration parameters |
-> String | Schema name |
-> String | Table name |
-> Int | NotNull key index |
-> Q [Dec] | Declaration of not-null constraint key |
Rule template to infer not-null key.
defineScalarDegree :: TypeQ -> Q [Dec] Source #
ScalarDegree
instance templates.
Column projections
Arguments
:: ConName | Record type name |
-> [(String, TypeQ)] | Column info list |
-> Q [Dec] | Column projection path declarations |
Make projection path templates using default naming rule.
defineOverloadedColumnsDefault Source #
Arguments
:: ConName | Record type name |
-> [(String, TypeQ)] | Column info list |
-> Q [Dec] | Column projection path declarations |
Make overloaded projection path templates using default naming rule.
Arguments
:: ConName | Record type name |
-> [(VarName, TypeQ)] | Column info list |
-> Q [Dec] | Column projection path declarations |
Projection path Pi
templates.
defineOverloadedColumns Source #
Arguments
:: ConName | Record type name |
-> [(String, TypeQ)] | Column info list |
-> Q [Dec] | Column projection path declarations |
Overloaded projection path Pi
templates.
Table metadata type and basic Relation
Arguments
:: VarName | Table declaration variable name |
-> VarName | Relation declaration variable name |
-> VarName | Insert statement declaration variable name |
-> VarName | InsertQuery statement declaration variable name |
-> TypeQ | Record type |
-> String | Table name in SQL ex. FOO_SCHEMA.table0 |
-> [String] | Column names |
-> Q [Dec] | Table and Relation declaration |
defineTableTypesWithConfig Source #
Arguments
:: Config | Configuration to generate query with |
-> String | Schema name |
-> String | Table name |
-> [(String, TypeQ)] | Column names and types and constraint type |
-> Q [Dec] | Result declarations |
Make templates about table and column metadatas using specified naming rule.
Basic SQL templates generate rules
Arguments
:: VarName | Variable name of result declaration |
-> TypeQ | Parameter type of |
-> TypeQ | Record type of |
-> ExpQ |
|
-> Q [Dec] | Result |
Template of derived primary Query
.
Arguments
:: VarName | Variable name of result declaration |
-> TypeQ | Parameter type of |
-> TypeQ | Record type of |
-> ExpQ |
|
-> Q [Dec] | Result |
Template of derived primary Update
.
Var expression templates
Make TableDerivation
variable expression template from table name using default naming rule.
Make Table
variable expression template from table name using default naming rule.
Arguments
:: Config | Configuration which has naming rules of templates |
-> String | Schema name string |
-> String | Table name string |
-> ExpQ | Result var Exp |
Make Relation
variable expression template from table name using specified naming rule.
Derived SQL templates from table definitions
defineSqlsWithPrimaryKey Source #
Arguments
:: VarName | Variable name of select query definition from primary key |
-> VarName | Variable name of update statement definition from primary key |
-> TypeQ | Primary key type |
-> TypeQ | Record type |
-> ExpQ | Relation expression |
-> ExpQ | Table expression |
-> Q [Dec] | Result declarations |
SQL templates derived from primary key.
defineSqlsWithPrimaryKeyDefault Source #
Arguments
:: String | Table name of Database |
-> TypeQ | Primary key type |
-> TypeQ | Record type |
-> ExpQ | Relation expression |
-> ExpQ | Table expression |
-> Q [Dec] | Result declarations |
SQL templates derived from primary key using default naming rule.
Reify
makeRelationalRecordDefault Source #
Generate all templates against defined record like type constructor other than depending on sql-value type.
makeRelationalRecordDefault' Source #
Generate all templates against defined record like type constructor other than depending on sql-value type.