relational-query-0.9.0.0: Typeful, Modular, Relational, algebraic query engine

Copyright2013-2017 Kei Hibino
LicenseBSD3
Maintainerex8k.hibino@gmail.com
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Database.Relational.Query.TH

Contents

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

All templates about table

defineTable Source #

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

unsafeInlineQuery Source #

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.

inlineQuery Source #

Arguments

:: Name

Top-level variable name which has Relation type

-> Relation p r

Object which has Relation type

-> 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 #

Arguments

:: TypeQ

Record type

-> Int

Column index

-> Q [Dec]

Result ColumnConstraint declaration

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

defineColumns Source #

Arguments

:: ConName

Record type name

-> [((VarName, TypeQ), Maybe (TypeQ, VarName))]

Column info list

-> Q [Dec]

Column projection path declarations

Column projection path Pi templates.

defineColumnsDefault Source #

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.

defineTuplePi :: Int -> Q [Dec] Source #

Make templates of projection paths for tuple types.

Table metadata type and basic Relation

defineTableTypes Source #

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

Table and Relation templates.

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.

Basic SQL templates generate rules

definePrimaryQuery Source #

Arguments

:: VarName

Variable name of result declaration

-> TypeQ

Parameter type of Query

-> TypeQ

Record type of Query

-> ExpQ

Relation expression

-> Q [Dec]

Result Query declaration

Template of derived primary Query.

definePrimaryUpdate Source #

Arguments

:: VarName

Variable name of result declaration

-> TypeQ

Parameter type of Update

-> TypeQ

Record type of Update

-> ExpQ

Table expression

-> Q [Dec]

Result Update declaration

Template of derived primary Update.

Var expression templates

derivationExpDefault Source #

Arguments

:: String

Table name string

-> ExpQ

Result var Exp

Make TableDerivation variable expression template from table name using default naming rule.

tableVarExpDefault Source #

Arguments

:: String

Table name string

-> ExpQ

Result var Exp

Make Table variable expression template from table name using default naming rule.

relationVarExp Source #

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.

Add type class instance against record type

defineProductConstructorInstance :: TypeQ -> ExpQ -> [TypeQ] -> Q [Dec] Source #

Make template for ProductConstructor instance.

Reify

makeRelationalRecordDefault Source #

Arguments

:: Name

Type constructor name

-> Q [Dec]

Result declaration

Generate all templates against defined record like type constructor other than depending on sql-value type.

reifyRelation Source #

Arguments

:: Name

Variable name which has Relation type

-> Q (Type, Type)

Extracted param type and result type from Relation type

Extract param type and result type from defined Relation