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

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

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

Table constraint specified by key

defineHasColumnConstraintInstance Source #

Arguments

:: TypeQ

Type which represent constraint type

-> TypeQ

Type constructor of record

-> Int

Key index which specifies this constraint

-> Q [Dec]

Result definition template

Template of HasColumnConstraint instance.

defineHasPrimaryConstraintInstanceDerived Source #

Arguments

:: TypeQ

Type constructor of record

-> Q [Dec]

Result definition template

Template of HasKeyConstraint instance.

defineHasPrimaryKeyInstance Source #

Arguments

:: TypeQ

Type constructor of record

-> [Int]

Key index which specifies this constraint

-> Q [Dec]

Definition of primary key constraint instance

Template of HasColumnConstraint Primary instance.

defineHasNotNullKeyInstance Source #

Arguments

:: TypeQ

Type constructor of record

-> Int

Key index which specifies this constraint

-> Q [Dec]

Definition of not null key constraint instance

Template of HasColumnConstraint NotNull instance.

Record type

defineRecordType Source #

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.

-> [Name]

Deriving type class names.

-> Q [Dec]

The data type record definition

Record type definition template.

defineRecordTypeWithConfig :: NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec] Source #

Record type definition template with configured names.

Function declarations against defined record types

defineColumnOffsets Source #

Arguments

:: ConName

Record type constructor.

-> Q [Dec]

Result column offset array declaration.

Column offset array definition.

recordWidthTemplate Source #

Arguments

:: TypeQ

Record type constructor.

-> ExpQ

Expression to get record width.

Record type width expression template.

Instance definitions against defined record types

definePersistableWidthInstance Source #

Arguments

:: TypeQ

Record type construct expression.

-> [Name]

Record type construct argument variables.

-> Q [Dec]

Definition of PersistableWidth instance.

Polymorphic PersistableWidth instance template.

defineSqlPersistableInstances :: TypeQ -> TypeQ -> [Name] -> Q [Dec] Source #

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

Templates about record name

data NameConfig Source #

NameConfig type to customize names of expanded record templates.

Instances

Show NameConfig Source #

Dummy show instance. Handy to define show instance recursively.

defaultNameConfig :: NameConfig Source #

Default implementation of NameConfig type. To change how generated record types and their columns are named, use record update syntax:

  defaultNameConfig
    { recordTypeName = \schema table -> varCamelcaseName $ schema ++ "_" ++ table
    -- ^ append the table name after the schema name. e.g. SchemaTable
    , columnName = \table column -> varCamelcaseName $ table ++ "_" ++ column
    -- ^ append the column name after the table name. e.g. "tableColumn"
    }

recordTypeName :: NameConfig -> String -> String -> ConName Source #

Make record type name generated from the table's definition. The first argument is the schema name of the table, and the second argument is the table name.

columnName :: NameConfig -> String -> String -> VarName Source #

Make each field label of the record type generated from the table's definition. The first argument is the table name, and the second argument is the column name.

recordTemplate Source #

Arguments

:: NameConfig

name rule config

-> String

Schema name string in SQL

-> String

Table name string in SQL

-> (TypeQ, ExpQ)

Record type and data constructor

Record constructor templates from SQL table name String.

columnOffsetsVarNameDefault Source #

Arguments

:: Name

Table type name

-> VarName

Result expression variable name

Variable expression of record column offset array.

Not nullable single column type

deriveNotNullType :: TypeQ -> Q [Dec] Source #

Templates for single column value type.

Template for tuple types

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

Template to define tuple instances of persistable-record classes.