Copyright | 2013-2017 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | ex8k.hibino@gmail.com |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
Database.Record.ToSql
Contents
Description
This module defines interfaces from Haskell type into list of database value type.
Synopsis
- type ToSqlM q a = Writer (DList q) a
- execToSqlM :: ToSqlM q a -> [q]
- data RecordToSql q a
- runFromRecord :: RecordToSql q a -> a -> [q]
- wrapToSql :: (a -> ToSqlM q ()) -> RecordToSql q a
- createRecordToSql :: (a -> [q]) -> RecordToSql q a
- (<&>) :: RecordToSql q a -> RecordToSql q b -> RecordToSql q (a, b)
- class PersistableWidth a => ToSql q a where
- recordToSql :: RecordToSql q a
- putRecord :: ToSql q a => a -> ToSqlM q ()
- putEmpty :: () -> ToSqlM q ()
- fromRecord :: ToSql q a => a -> [q]
- valueRecordToSql :: (a -> q) -> RecordToSql q a
- updateValuesByUnique :: ToSql q ra => KeyConstraint Unique ra -> ra -> [q]
- updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q]
- untypedUpdateValuesIndex :: [Int] -> Int -> [Int]
- unsafeUpdateValuesWithIndexes :: ToSql q ra => [Int] -> ra -> [q]
Conversion from record type into list of database value type
execToSqlM :: ToSqlM q a -> [q] Source #
extract appended print result of record.
data RecordToSql q a Source #
RecordToSql
q
a
is data-type wrapping function
to convert from Haskell type a
into list of database value type (to send to database) [q
].
This structure is similar to printer.
While running RecordToSql
behavior is the same as list printer.
which appends list of database value type [q
] stream.
Arguments
:: RecordToSql q a | printer function object which has capability to convert |
-> a | Haskell type |
-> [q] | list of database value |
Run RecordToSql
printer function object. Convert from Haskell type a
into list of database value type [q
].
wrapToSql :: (a -> ToSqlM q ()) -> RecordToSql q a Source #
Finalize RecordToSql
record printer.
Arguments
:: (a -> [q]) | Convert function body |
-> RecordToSql q a | Result printer function object |
Axiom of RecordToSql
for database value type q
and Haksell type a
.
(<&>) :: RecordToSql q a -> RecordToSql q b -> RecordToSql q (a, b) infixl 4 Source #
Derivation rule of RecordToSql
printer function object for Haskell tuple (,) type.
Derivation rules of RecordToSql
conversion
class PersistableWidth a => ToSql q a where Source #
ToSql
q
a
is implicit rule to derive RecordToSql
q
a
record printer function for type a
.
Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming)
with default signature is available for ToSql
class,
so you can make instance like below:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics (Generic) import Database.HDBC (SqlValue) -- data Foo = Foo { ... } deriving Generic instance ToSql SqlValue Foo
To make instances of ToSql
manually,
ToSql
q
a
and RecordToSql
'q a
are composable with monadic context.
When, you have data constructor and objects like below.
data MyRecord = MyRecord Foo Bar Baz
instance ToSql SqlValue Foo where ... instance ToSql SqlValue Bar where ... instance ToSql SqlValue Baz where ...
You can get composed ToSql
implicit rule like below.
instance ToSql SqlValue MyRecord where recordToSql = recordToSql = wrapToSql $ \ (MyRecord x y z) -> do putRecord x putRecord y putRecord z
Minimal complete definition
Nothing
Methods
recordToSql :: RecordToSql q a Source #
Derived RecordToSql
printer function object.
recordToSql :: (Generic a, GToSql q (Rep a)) => RecordToSql q a Source #
Derived RecordToSql
printer function object.
Instances
ToSql q () Source # | Implicit derivation rule of |
Defined in Database.Record.ToSql Methods recordToSql :: RecordToSql q () Source # | |
(PersistableType q, ToSql q a) => ToSql q (Maybe a) Source # | Implicit derivation rule of |
Defined in Database.Record.ToSql Methods recordToSql :: RecordToSql q (Maybe a) Source # | |
(ToSql q a, ToSql q b) => ToSql q (a, b) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b) Source # | |
(ToSql q a, ToSql q b, ToSql q c) => ToSql q (a, b, c) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b, c) Source # | |
(ToSql q a, ToSql q b, ToSql q c, ToSql q d) => ToSql q (a, b, c, d) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b, c, d) Source # | |
(ToSql q a, ToSql q b, ToSql q c, ToSql q d, ToSql q e) => ToSql q (a, b, c, d, e) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b, c, d, e) Source # | |
(ToSql q a, ToSql q b, ToSql q c, ToSql q d, ToSql q e, ToSql q f) => ToSql q (a, b, c, d, e, f) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b, c, d, e, f) Source # | |
(ToSql q a, ToSql q b, ToSql q c, ToSql q d, ToSql q e, ToSql q f, ToSql q g) => ToSql q (a, b, c, d, e, f, g) Source # | |
Defined in Database.Record.TupleInstances Methods recordToSql :: RecordToSql q (a, b, c, d, e, f, g) Source # |
putRecord :: ToSql q a => a -> ToSqlM q () Source #
Run implicit RecordToSql
printer function object.
Context to convert haskell record type a
into lib of database value type [q
].
putEmpty :: () -> ToSqlM q () Source #
Run RecordToSql
empty printer.
fromRecord :: ToSql q a => a -> [q] Source #
Run implicit RecordToSql
printer function object.
Convert from haskell type a
into list of database value type [q
].
valueRecordToSql :: (a -> q) -> RecordToSql q a Source #
Derivation rule of RecordToSql
printer function object for value convert function.
Make parameter list for updating with key
Arguments
:: ToSql q ra | |
=> KeyConstraint Unique ra | Unique key table constraint printer function object. |
-> ra | |
-> [q] |
Convert from Haskell type ra
into database value q
list expected by update form like
UPDATE table SET c0 = ?, c1 = ?, c2 = ? ... WHERE key0 = ? AND key1 = ? AND key2 = ? ...
using printer function object infered by ToSql ra q.
updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q] Source #
Convert like updateValuesByUnique'
using implicit RecordToSql
and ColumnConstraint
.
untypedUpdateValuesIndex Source #
Make untyped indexes to update column from key indexes and record width. Expected by update form like
UPDATE table SET c0 = ?, c1 = ?, c2 = ? ... WHERE key0 = ? AND key1 = ? AND key2 = ? ...
unsafeUpdateValuesWithIndexes :: ToSql q ra => [Int] -> ra -> [q] Source #
Unsafely specify key indexes to convert from Haskell type ra
into database value q
list expected by update form like
UPDATE table SET c0 = ?, c1 = ?, c2 = ? ... WHERE key0 = ? AND key1 = ? AND key2 = ? ...
using RecordToSql
printer function object.