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

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

Database.Record.ToSql

Contents

Description

This module defines interfaces from Haskell type into list of SQL type.

Synopsis

Conversion from record type into list of SQL type

type ToSqlM q a = Writer (DList q) a Source #

Context type to convert SQL type list.

data RecordToSql q a Source #

Proof object type to convert from Haskell type a into list of SQL type [q].

runFromRecord Source #

Arguments

:: RecordToSql q a

Proof object which has capability to convert

-> a

Haskell type

-> [q]

list of SQL type

Run RecordToSql proof object. Convert from Haskell type a into list of SQL type [q].

createRecordToSql Source #

Arguments

:: (a -> [q])

Convert function body

-> RecordToSql q a

Result proof object

Axiom of RecordToSql for SQL type q and Haksell type a.

(<&>) :: RecordToSql q a -> RecordToSql q b -> RecordToSql q (a, b) infixl 4 Source #

Derivation rule of RecordToSql proof object for Haskell tuple (,) type.

Inference rules of RecordToSql conversion

class ToSql q a where Source #

Inference rule interface for RecordToSql proof object.

Minimal complete definition

recordToSql

Methods

recordToSql :: RecordToSql q a Source #

Infer RecordToSql proof object.

Instances

ToSql q () Source #

Inference rule of RecordToSql proof object which can convert from Haskell unit () type into empty list of SQL type [q].

(PersistableType q, PersistableWidth a, ToSql q a) => ToSql q (Maybe a) Source #

Inference rule of RecordToSql proof object which can convert from Haskell Maybe type into list of SQL type [q].

(ToSql q a, ToSql q b) => ToSql q (a, b) Source #

Inference rule of RecordToSql proof object which can convert from Haskell tuple (a, b) type into list of SQL type [q].

Methods

recordToSql :: RecordToSql q (a, b) Source #

putRecord :: ToSql q a => a -> ToSqlM q () Source #

Run inferred RecordToSql proof object. Context to convert haskell record type a into SQL type q list.

putEmpty :: () -> ToSqlM q () Source #

Run RecordToSql empty printer.

fromRecord :: ToSql q a => a -> [q] Source #

Run inferred RecordToSql proof object. Convert from haskell type a into list of SQL type [q].

wrapToSql :: (a -> ToSqlM q ()) -> RecordToSql q a Source #

Finalize RecordToSql record printer.

valueRecordToSql :: (a -> q) -> RecordToSql q a Source #

Derivation rule of RecordToSql proof object for value convert function.

Make parameter list for updating with key

updateValuesByUnique' Source #

Arguments

:: RecordToSql q ra 
-> KeyConstraint Unique ra

Unique key table constraint proof object.

-> ra 
-> [q] 

Convert from Haskell type ra into SQL value q list expected by update form like

UPDATE table SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ? AND key1 = ? AND key2 = ? ...

using RecordToSql proof object.

updateValuesByUnique Source #

Arguments

:: ToSql q ra 
=> KeyConstraint Unique ra

Unique key table constraint proof object.

-> ra 
-> [q] 

Convert like updateValuesByUnique' using inferred RecordToSql proof object.

updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q] Source #

Convert like updateValuesByUnique' using inferred RecordToSql and ColumnConstraint proof objects.

untypedUpdateValuesIndex Source #

Arguments

:: [Int]

Key indexes

-> Int

Record width

-> [Int]

Indexes to update other than key

Make untyped indexes to update column from key indexes and record width. Expected by update form like

UPDATE table SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ? AND key1 = ? AND key2 = ? ...

unsafeUpdateValuesWithIndexes :: RecordToSql q ra -> [Int] -> ra -> [q] Source #

Unsafely specify key indexes to convert from Haskell type ra into SQL value q list expected by update form like

UPDATE table SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ? AND key1 = ? AND key2 = ? ...

using RecordToSql proof object.