mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-02 08:12:49 +03:00
persistable-record: formatted.
This commit is contained in:
parent
5c9d931875
commit
34b90f02e9
@ -135,6 +135,23 @@ class FromSql q a where
|
||||
default recordFromSql :: (Generic a, GFromSql q (Rep a)) => RecordFromSql q a
|
||||
recordFromSql = to <$> gFromSql
|
||||
|
||||
|
||||
class GFromSql q f where
|
||||
gFromSql :: RecordFromSql q (f a)
|
||||
|
||||
instance GFromSql q U1 where
|
||||
gFromSql = createRecordFromSql $ (,) U1
|
||||
|
||||
instance (GFromSql q a, GFromSql q b) => GFromSql q (a :*: b) where
|
||||
gFromSql = (:*:) <$> gFromSql <*> gFromSql
|
||||
|
||||
instance GFromSql q a => GFromSql q (M1 i c a) where
|
||||
gFromSql = M1 <$> gFromSql
|
||||
|
||||
instance FromSql q a => GFromSql q (K1 i a) where
|
||||
gFromSql = K1 <$> recordFromSql
|
||||
|
||||
|
||||
-- | Inference rule of 'RecordFromSql' proof object which can convert
|
||||
-- from list of SQL type ['q'] into Haskell tuple ('a', 'b') type.
|
||||
instance (FromSql q a, FromSql q b) => FromSql q (a, b) where
|
||||
@ -164,19 +181,3 @@ toRecord = runToRecord recordFromSql
|
||||
-- | Derivation rule of 'RecordFromSql' proof object for value convert function.
|
||||
valueRecordFromSql :: (q -> a) -> RecordFromSql q a
|
||||
valueRecordFromSql d = createRecordFromSql $ \qs -> (d $ head qs, tail qs)
|
||||
|
||||
|
||||
class GFromSql q f where
|
||||
gFromSql :: RecordFromSql q (f a)
|
||||
|
||||
instance GFromSql q U1 where
|
||||
gFromSql = createRecordFromSql $ (,) U1
|
||||
|
||||
instance (GFromSql q a, GFromSql q b) => GFromSql q (a :*: b) where
|
||||
gFromSql = (:*:) <$> gFromSql <*> gFromSql
|
||||
|
||||
instance GFromSql q a => GFromSql q (M1 i c a) where
|
||||
gFromSql = M1 <$> gFromSql
|
||||
|
||||
instance FromSql q a => GFromSql q (K1 i a) where
|
||||
gFromSql = K1 <$> recordFromSql
|
||||
|
Loading…
Reference in New Issue
Block a user