Copyright | 2013-2016 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
Database.Relational.Query.TH
Contents
- All templates about table
- Inlining typed
Query
- Column projections and basic
Relation
for Haskell record - Constraint key templates
- Column projections
- Table metadata type and basic
Relation
- Basic SQL templates generate rules
- Var expression templates
- Derived SQL templates from table definitions
- Add type class instance against record type
- Reify
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.
- defineTable :: Config -> String -> String -> [(String, TypeQ)] -> [Name] -> [Int] -> Maybe Int -> Q [Dec]
- defineTableDefault :: 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]
- defineTableTypesAndRecordDefault :: Config -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]
- defineHasPrimaryKeyInstance :: TypeQ -> TypeQ -> [Int] -> Q [Dec]
- defineHasPrimaryKeyInstanceWithConfig :: Config -> String -> String -> TypeQ -> [Int] -> Q [Dec]
- defineHasPrimaryKeyInstanceDefault :: String -> String -> TypeQ -> [Int] -> Q [Dec]
- defineHasNotNullKeyInstance :: TypeQ -> Int -> Q [Dec]
- defineHasNotNullKeyInstanceWithConfig :: Config -> String -> String -> Int -> Q [Dec]
- defineHasNotNullKeyInstanceDefault :: String -> String -> Int -> Q [Dec]
- defineScalarDegree :: TypeQ -> Q [Dec]
- defineColumns :: ConName -> [((VarName, TypeQ), Maybe (TypeQ, VarName))] -> Q [Dec]
- defineColumnsDefault :: ConName -> [((String, TypeQ), Maybe TypeQ)] -> Q [Dec]
- defineTableTypes :: VarName -> VarName -> VarName -> VarName -> TypeQ -> String -> [String] -> Q [Dec]
- defineTableTypesWithConfig :: Config -> String -> String -> [((String, TypeQ), Maybe TypeQ)] -> Q [Dec]
- defineTableTypesDefault :: Config -> String -> String -> [((String, TypeQ), Maybe 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
- relationVarExpDefault :: String -> String -> ExpQ
- defineSqlsWithPrimaryKey :: VarName -> VarName -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> Q [Dec]
- defineSqlsWithPrimaryKeyDefault :: String -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> Q [Dec]
- defineProductConstructorInstance :: TypeQ -> ExpQ -> [TypeQ] -> Q [Dec]
- makeRelationalRecordDefault :: 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.
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 |
Deprecated: Use defineTable instead of this.
Generate all templtes about table using default 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.
defineTableTypesAndRecordDefault 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 |
Deprecated: Use defineTableTypesAndRecord instead of this.
Make templates about table, column and haskell record using default 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.
defineHasPrimaryKeyInstanceDefault Source
Arguments
:: String | Schema name |
-> String | Table name |
-> TypeQ | Column type |
-> [Int] | Primary key index |
-> Q [Dec] | Declarations of primary constraint key |
Deprecated: Use ' defineHasPrimaryKeyInstanceWithConfig defaultConfig ' instead of this.
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.
defineHasNotNullKeyInstanceDefault Source
Arguments
:: String | Schema name |
-> String | Table name |
-> Int | NotNull key index |
-> Q [Dec] | Declaration of not-null constraint key |
Deprecated: Use ' defineHasNotNullKeyInstanceWithConfig defaultConfig ' instead of this.
Rule template to infer not-null key.
defineScalarDegree :: TypeQ -> Q [Dec] Source
ScalarDegree
instance templates.
Column projections
Arguments
:: ConName | Record type name |
-> [((VarName, TypeQ), Maybe (TypeQ, VarName))] | Column info list |
-> Q [Dec] | Column projection path declarations |
Column projection path Pi
templates.
Arguments
:: ConName | Record type name |
-> [((String, TypeQ), Maybe TypeQ)] | Column info list |
-> Q [Dec] | Column projection path declarations |
Make column projection path and constraint key templates using default naming rule.
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), Maybe TypeQ)] | Column names and types and constraint type |
-> Q [Dec] | Result declarations |
Make templates about table and column metadatas using specified naming rule.
defineTableTypesDefault Source
Arguments
:: Config | Configuration to generate query with |
-> String | Schema name |
-> String | Table name |
-> [((String, TypeQ), Maybe TypeQ)] | Column names and types and constraint type |
-> Q [Dec] | Result declarations |
Deprecated: Use defineTableTypesWithConfig instead of this.
Make templates about table and column metadatas using default 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.
Deprecated: Use ' relationVarExp defaultConfig ' instead of this.
Make Relation
variable expression template from table name using default 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.
Add type class instance against record type
defineProductConstructorInstance :: TypeQ -> ExpQ -> [TypeQ] -> Q [Dec] Source
Make template for ProductConstructor
instance.
Reify
makeRelationalRecordDefault Source
Generate all templates against defined record like type constructor other than depending on sql-value type.