persistable-record-0.1.0.0: Binding between SQL database values and haskell records.

Portabilityunknown
Stabilityexperimental
Maintainerex8k.hibino@gmail.com
Safe HaskellNone

Database.Record.TH

Contents

Description

This module defines templates for Haskell record type and type class instances to map between list of untyped SQL type and Haskell record type.

Synopsis

Generate all templates about record

defineRecordSource

Arguments

:: TypeQ

SQL value type

-> (VarName, VarName)

Constructor function name and decompose function name

-> ConName

Record type name

-> [(VarName, TypeQ)]

Column schema

-> [ConName]

Record derivings

-> Q [Dec]

Result declarations

All templates for record type.

defineRecordDefaultSource

Arguments

:: TypeQ

SQL value type

-> String

Table name

-> [(String, TypeQ)]

Column names and types

-> [ConName]

Record derivings

-> Q [Dec]

Result declarations

All templates for record type with default names.

Deriving class symbols

derivingEq :: ConNameSource

Name to specify deriving Eq

derivingShow :: ConNameSource

Name to specify deriving Show

derivingRead :: ConNameSource

Name to specify deriving Read

derivingData :: ConNameSource

Name to specify deriving Data

derivingTypable :: ConNameSource

Name to specify deriving Typable

Table constraint specified by key

defineHasColumnConstraintInstanceSource

Arguments

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

defineHasPrimaryConstraintInstanceDerivedSource

Arguments

:: TypeQ

Type constructor of record

-> Q [Dec]

Result declaration template

Template of HasKeyConstraint instance.

defineHasNotNullKeyInstanceSource

Arguments

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

defineHasPrimaryKeyInstanceSource

Arguments

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

defineHasPrimaryKeyInstanceDefaultSource

Arguments

:: String

Table name

-> [Int]

Key index which specifies this constraint

-> Q [Dec]

Declaration of primary key constraint instance

Template of HasColumnConstraint Primary instance from SQL table name String and key index.

defineHasNotNullKeyInstanceDefaultSource

Arguments

:: String

Table name

-> Int

Key index which specifies this constraint

-> Q [Dec]

Declaration of not null key constraint instance

Template of HasColumnConstraint NotNull instance from SQL table name String and key index.

Record type

defineRecordTypeSource

Arguments

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

-> [ConName]

Deriving type class names.

-> Q [Dec]

The data type record declaration.

Record type declaration template.

defineRecordTypeDefault :: String -> [(String, TypeQ)] -> [ConName] -> Q [Dec]Source

Record type declaration template from SQL table name String and column name String - type pairs, derivings.

Function declarations depending on SQL type

makeRecordPersistableWithSqlTypeSource

Arguments

:: TypeQ

SQL value type.

-> (VarName, VarName)

Constructor function name and decompose function name.

-> (TypeQ, ExpQ)

Record type constructor and data constructor.

-> Int

Count of record columns.

-> Q [Dec]

Result declarations.

All templates depending on SQL value type.

makeRecordPersistableWithSqlTypeDefaultSource

Arguments

:: TypeQ

SQL value type

-> String

Table name of database

-> Int

Count of record columns

-> Q [Dec]

Result declarations

All templates depending on SQL value type with default names.

Function declarations against defined record types

makeRecordPersistableWithSqlTypeFromDefinedSource

Arguments

:: TypeQ

SQL value type

-> (VarName, VarName)

Constructor function name and decompose function name

-> Name

Record type constructor name

-> Q [Dec]

Result declarations

All templates depending on SQL value type. Defined record type information is used.

makeRecordPersistableWithSqlTypeDefaultFromDefinedSource

Arguments

:: TypeQ

SQL value type

-> Name

Record type constructor name

-> Q [Dec]

Result declarations

All templates depending on SQL value type with default names. Defined record type information is used.

defineColumnOffsetsSource

Arguments

:: ConName

Record type constructor.

-> [TypeQ]

Types of record columns.

-> Q [Dec]

Declaration of PersistableWidth instance.

Column offset array and PersistableWidth instance declaration.

recordWidthTemplateSource

Arguments

:: TypeQ

Record type constructor.

-> ExpQ

Expression to get record width.

Record type width expression template.

defineRecordParserSource

Arguments

:: TypeQ

SQL value type.

-> VarName

Name of record parser.

-> (TypeQ, ExpQ)

Record type constructor and data constructor.

-> Int

Count of record columns.

-> Q [Dec]

Declaration of record construct function from SQL values.

Record parser template.

defineRecordPrinterSource

Arguments

:: TypeQ

SQL value type.

-> VarName

Name of record printer.

-> (TypeQ, ExpQ)

Record type constructor and data constructor.

-> Int

Count of record columns.

-> Q [Dec]

Declaration of record construct function from SQL values.

Record printer template.

definePersistableInstanceSource

Arguments

:: TypeQ

SQL value type.

-> TypeQ

Record type constructor.

-> VarName

Record parser name.

-> VarName

Record printer name.

-> Int

Count of record columns.

-> Q [Dec]

Instance declarations for Persistable.

Record parser and printer instance templates for converting between list of SQL type and Haskell record type.

Reify

reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))Source

Low-level reify interface for record type name.

Templates about record type name

recordTypeNameDefaultSource

Arguments

:: String

Table name in SQL

-> ConName

Result name

Generate default name of record type constructor from SQL table name String

recordTypeDefaultSource

Arguments

:: String

Table name in SQL

-> TypeQ

Result type template

Record type constructor template from SQL table name String. Type name is generated by recordTypeNameDefault.

columnOffsetsVarNameDefaultSource

Arguments

:: Name

Table type name

-> VarName

Result expression variable name

Variable expression of record column offset array.

persistableFunctionNamesDefault :: Name -> (VarName, VarName)Source

Generate persistable function symbol names using default rule.

Not nullable single column type

deriveNotNullType :: TypeQ -> Q [Dec]Source

Templates for single column value type.