persistable-record: apply and export generic tuple templates.

This commit is contained in:
Kei Hibino 2017-03-19 17:43:35 +09:00
parent 0c2506233d
commit 9b95f6a121
7 changed files with 20 additions and 12 deletions

View File

@ -27,6 +27,7 @@ library
Database.Record.FromSql
Database.Record.ToSql
Database.Record.Persistable
Database.Record.TupleInstances
Database.Record.Instances
Database.Record.KeyConstraint
Database.Record

View File

@ -48,6 +48,7 @@ import Database.Record.ToSql
(ToSqlM, RecordToSql, ToSql(..), valueRecordToSql,
runFromRecord, wrapToSql, putRecord, putEmpty, fromRecord,
updateValuesByUnique, updateValuesByPrimary)
import Database.Record.TupleInstances ()
{- $concepts
On most drivers for SQL database,

View File

@ -152,10 +152,6 @@ 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) -- default generic instance
-- | Inference rule of 'RecordFromSql' proof object which can convert
-- from list of SQL type ['q'] into Haskell 'Maybe' type.
instance (HasColumnConstraint NotNull a, FromSql q a, PersistableType q)

View File

@ -147,9 +147,6 @@ genericFieldOffsets :: (Generic a, GFieldWidthList (Rep a)) => ProductConst (Arr
genericFieldOffsets = pmapConst (offsets . DList.toList) $ to `pmap` gFieldWidthList
-- | Inference rule of 'PersistableRecordWidth' proof object for tuple ('a', 'b') type.
instance (PersistableWidth a, PersistableWidth b) => PersistableWidth (a, b) -- default generic instance
-- | Inference rule of 'PersistableRecordWidth' proof object for 'Maybe' type.
instance PersistableWidth a => PersistableWidth (Maybe a) where
persistableWidth = maybeWidth persistableWidth

View File

@ -56,7 +56,10 @@ module Database.Record.TH (
persistableFunctionNamesDefault,
-- * Not nullable single column type
deriveNotNullType
deriveNotNullType,
-- * Template for tuple types
defineTupleInstances,
) where
import GHC.Generics (Generic)
@ -87,6 +90,7 @@ import Database.Record.Persistable
(runPersistableRecordWidth,
ProductConst, getProductConst, genericFieldOffsets)
import qualified Database.Record.Persistable as Persistable
import Database.Record.InternalTH (defineTupleInstances)
-- | 'NameConfig' type to customize names of expanded record templates.

View File

@ -126,10 +126,6 @@ instance ToSql q a => GToSql q (K1 i a) where
gToSql = (\(K1 a) -> a) `mapToSql` recordToSql
-- | Inference rule of 'RecordToSql' proof object which can convert
-- from Haskell tuple ('a', 'b') type into list of SQL type ['q'].
instance (ToSql q a, ToSql q b) => ToSql q (a, b) -- default generic instance
-- | Inference rule of 'RecordToSql' proof object which can convert
-- from Haskell 'Maybe' type into list of SQL type ['q'].
instance (PersistableType q, PersistableWidth a, ToSql q a) => ToSql q (Maybe a) where

View File

@ -0,0 +1,13 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Database.Record.TupleInstances () where
import Control.Applicative ((<$>))
import Database.Record.InternalTH (defineTupleInstances)
$(concat <$> mapM defineTupleInstances [2..7])
-- Generic instances of tuple types are generated from 2 to 7 in GHC.Generics.