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

Portabilityunknown
Stabilityexperimental
Maintainerex8k.hibino@gmail.com
Safe HaskellNone

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

defineTableDefaultSource

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

-> [ConName]

derivings for Record type

-> [Int]

Primary key index

-> Maybe Int

Not null key index

-> Q [Dec]

Result declarations

Generate all templtes about table using default naming rule.

Inlining typed Query

unsafeInlineQuerySource

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.

inlineQuerySource

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

defineTableTypesAndRecordDefaultSource

Arguments

:: Config

Configuration to generate query with

-> String

Schema name

-> String

Table name

-> [(String, TypeQ)]

Column names and types

-> [ConName]

Record derivings

-> Q [Dec]

Result declarations

Make templates about table, column and haskell record using default naming rule.

Constraint key templates

defineHasPrimaryKeyInstanceSource

Arguments

:: TypeQ

Record type

-> TypeQ

Key type

-> [Int]

Indexes specifies key

-> Q [Dec]

Result constraint key declarations

Rule template to infer primary key.

defineHasPrimaryKeyInstanceDefaultSource

Arguments

:: String

Table name

-> TypeQ

Column type

-> [Int]

Primary key index

-> Q [Dec]

Declarations of primary constraint key

Rule template to infer primary key.

defineHasNotNullKeyInstanceSource

Arguments

:: TypeQ

Record type

-> Int

Column index

-> Q [Dec]

Result ColumnConstraint declaration

Rule template to infer not-null key.

defineHasNotNullKeyInstanceDefaultSource

Arguments

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

defineColumnsSource

Arguments

:: ConName

Record type name

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

Column info list

-> Q [Dec]

Column projection path declarations

Column projection path Pi templates.

defineColumnsDefaultSource

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

defineTableTypesSource

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.

defineTableTypesDefaultSource

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 default naming rule.

Basic SQL templates generate rules

definePrimaryQuerySource

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.

definePrimaryUpdateSource

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

derivationExpDefaultSource

Arguments

:: String

Table name string

-> ExpQ

Result var Exp

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

tableVarExpDefaultSource

Arguments

:: String

Table name string

-> ExpQ

Result var Exp

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

relationVarExpDefaultSource

Arguments

:: String

Table name string

-> ExpQ

Result var Exp

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

Derived SQL templates from table definitions

defineSqlsWithPrimaryKeySource

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.

defineSqlsWithPrimaryKeyDefaultSource

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

makeRelationalRecordDefaultSource

Arguments

:: Name

Type constructor name

-> Q [Dec]

Resutl declaration

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

reifyRelationSource

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