Copyright | 2013 Kei Hibino |
---|---|

License | BSD3 |

Maintainer | ex8k.hibino@gmail.com |

Stability | experimental |

Portability | unknown |

Safe Haskell | Safe |

Language | Haskell2010 |

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

- data RecordFromSql q a
- runTakeRecord :: RecordFromSql q a -> [q] -> (a, [q])
- runToRecord :: RecordFromSql q a -> [q] -> a
- createRecordFromSql :: ([q] -> (a, [q])) -> RecordFromSql q a
- (<&>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q (a, b)
- maybeRecord :: PersistableType q => RecordFromSql q a -> ColumnConstraint NotNull a -> RecordFromSql q (Maybe a)
- class FromSql q a where
- takeRecord :: FromSql q a => [q] -> (a, [q])
- toRecord :: FromSql q a => [q] -> a
- valueRecordFromSql :: (q -> a) -> RecordFromSql q a

# Conversion from list of SQL type into record type

Structure of `RecordFromSql`

`q`

`a`

is similar to parser.
While running `RecordFromSql`

behavior is the same as parser
which parse list of SQL type [`q`

] stream.

So, `RecordFromSql`

`q`

is `Monad`

and `Applicative`

instance like parser monad.
When, you have data constructor and objects like below.

data MyRecord = MyRecord Foo Bar Baz

foo ::`RecordFromSql`

SqlValue Foo foo = ... bar ::`RecordFromSql`

SqlValue Bar bar = ... baz ::`RecordFromSql`

SqlValue Bar baz = ...

You can get composed `RecordFromSql`

like below.

myRecord :: RecordFromSql SqlValue MyRecord myRecord = MyRecord <$> foo <*> bar <*> baz

data RecordFromSql q a Source #

Proof object type to convert from sql value type `q`

list into Haskell type `a`

.

Monad (RecordFromSql q) Source # | |

Functor (RecordFromSql q) Source # | |

Applicative (RecordFromSql q) Source # | Derived |

:: RecordFromSql q a | Proof object which has capability to convert |

-> [q] | list of SQL type |

-> (a, [q]) | Haskell type and rest of list |

Run `RecordFromSql`

proof object.
Convert from list of SQL type [`q`

] into Haskell type `a`

and rest of list [`q`

].

:: RecordFromSql q a | Proof object which has capability to convert |

-> [q] | list of SQL type |

-> a | Haskell type |

Run `RecordFromSql`

proof object. Convert from list of SQL type [`q`

] into Haskell type `a`

.

:: ([q] -> (a, [q])) | Convert function body |

-> RecordFromSql q a | Result proof object |

Axiom of `RecordFromSql`

for SQL type `q`

and Haskell type `a`

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

Derivation rule of `RecordFromSql`

proof object for Haskell tuple (,) type.

maybeRecord :: PersistableType q => RecordFromSql q a -> ColumnConstraint NotNull a -> RecordFromSql q (Maybe a) Source #

Derivation rule of `RecordFromSql`

proof object for Haskell `Maybe`

type.

# Inference rules of `RecordFromSql`

conversion

class FromSql q a where Source #

Inference rule interface for `RecordFromSql`

proof object.

recordFromSql :: RecordFromSql q a Source #

`RecordFromSql`

proof object.

FromSql q () Source # | Inference rule of |

(HasColumnConstraint NotNull a, FromSql q a, PersistableType q) => FromSql q (Maybe a) Source # | Inference rule of |

(FromSql q a, FromSql q b) => FromSql q (a, b) Source # | Inference rule of |

takeRecord :: FromSql q a => [q] -> (a, [q]) Source #

Run inferred `RecordFromSql`

proof object.
Convert from list of SQL type [`q`

] into haskell type `a`

and rest of list [`q`

].

toRecord :: FromSql q a => [q] -> a Source #

Run inferred `RecordFromSql`

proof object.
Convert from list of SQL type [`q`

] into haskell type `a`

.

valueRecordFromSql :: (q -> a) -> RecordFromSql q a Source #

Derivation rule of `RecordFromSql`

proof object for value convert function.