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

Portabilityunknown
Stabilityexperimental
Maintainerex8k.hibino@gmail.com
Safe HaskellSafe-Inferred

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) aSource

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

runFromRecordSource

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

createRecordToSqlSource

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)Source

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

Inference rules of RecordToSql conversion

class ToSql q a whereSource

Inference rule interface for RecordToSql proof object.

Methods

recordToSql :: RecordToSql q aSource

Infer RecordToSql proof object.

Instances

ToSql q ()

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)

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)

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

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 aSource

Finalize RecordToSql record printer.

valueToSql :: PersistableValue q a => RecordToSql q aSource

Derived RecordToSql from persistable value.

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.

updateValuesByUniqueSource

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.

untypedUpdateValuesIndexSource

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.