-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Binding between SQL database values and haskell records.
--   
--   This package contiains types to represent table constraints and
--   interfaces to bind between SQL database values and Haskell records.
@package persistable-record
@version 0.6.0.4


-- | This module provides proof object definitions of table constraint
--   specifiey by keys.
module Database.Record.KeyConstraint

-- | Proof object to specify table constraint for table record type
--   <tt>r</tt> and constraint <tt>c</tt> specified by a single column.
data ColumnConstraint c r

-- | Index of key which specifies table constraint.
index :: ColumnConstraint c r -> Int

-- | Unsafely generate <a>ColumnConstraint</a> proof object using specified
--   key index.
unsafeSpecifyColumnConstraint :: Int -> ColumnConstraint c r

-- | Constraint type. Unique key.
data Unique

-- | Specialized unique constraint.
type UniqueColumnConstraint = ColumnConstraint Unique

-- | Constraint type. Not-null key.
data NotNull

-- | Specialized not-null constraint.
type NotNullColumnConstraint = ColumnConstraint NotNull

-- | Constraint type. Primary key.
data Primary

-- | Specialized primary constraint.
type PrimaryColumnConstraint = ColumnConstraint Primary

-- | Proof object to specify table constraint for table record type
--   <tt>r</tt> and constraint <tt>c</tt>. Constraint is specified by
--   composite key.
data KeyConstraint c r

-- | Index of key which specifies table constraint.
indexes :: KeyConstraint c r -> [Int]

-- | Unsafely generate <a>KeyConstraint</a> proof object using specified
--   key indexes.
unsafeSpecifyKeyConstraint :: [Int] -> KeyConstraint c r

-- | Specialized unique constraint.
type UniqueConstraint = KeyConstraint Unique

-- | Specialized primary constraint.
type PrimaryConstraint = KeyConstraint Primary

-- | Derivation rule for <a>UniqueColumnConstraint</a>. Derive Unique from
--   Primary.
uniqueColumn :: PrimaryColumnConstraint r -> UniqueColumnConstraint r

-- | Derivation rule for <a>NotNullColumnConstraint</a>. Derive NotNull
--   from Primary.
notNullColumn :: PrimaryColumnConstraint r -> NotNullColumnConstraint r

-- | Derivation rule of <a>ColumnConstraint</a> <a>NotNull</a> for tuple
--   (,) type.
leftColumnConstraint :: ColumnConstraint NotNull a -> ColumnConstraint NotNull (a, b)

-- | Unsafely generate <a>NotNullColumnConstraint</a> proof object of
--   single column value.
unsafeSpecifyNotNullValue :: NotNullColumnConstraint a

-- | Derivation rule for <a>KeyConstraint</a>. Derive from
--   <a>ColumnConstraint</a>.
deriveComposite :: ColumnConstraint c r -> KeyConstraint c r

-- | Derivation rule for <a>UniqueConstraint</a>.
unique :: PrimaryConstraint r -> UniqueConstraint r

-- | Interface of inference rule for <a>ColumnConstraint</a> proof object.
class HasColumnConstraint c a

-- | Infer <a>ColumnConstraint</a> proof object.
columnConstraint :: HasColumnConstraint c a => ColumnConstraint c a

-- | Inferred <a>UniqueColumnConstraint</a> proof object. Record type
--   <tt>r</tt> has unique key which is derived <tt>r</tt> has primary key.
derivedUniqueColumnConstraint :: HasColumnConstraint Primary r => UniqueColumnConstraint r

-- | Inferred <a>NotNullColumnConstraint</a> proof object. Record type
--   <tt>r</tt> has not-null key which is derived <tt>r</tt> has primary
--   key.
derivedNotNullColumnConstraint :: HasColumnConstraint Primary r => NotNullColumnConstraint r

-- | Interface of inference rule for <a>KeyConstraint</a> proof object.
class HasKeyConstraint c a

-- | Infer <a>ColumnConstraint</a> proof object.
keyConstraint :: HasKeyConstraint c a => KeyConstraint c a

-- | Inferred <a>PrimaryConstraint</a> proof object. Record type <tt>r</tt>
--   has composite primary key which is derived <tt>r</tt> has single
--   column primary key.
derivedCompositePrimary :: HasColumnConstraint Primary r => PrimaryConstraint r

-- | Inferred <a>UniqueConstraint</a> proof object. Record type <tt>r</tt>
--   has unique key which is derived <tt>r</tt> has primary key.
derivedUniqueConstraint :: HasKeyConstraint Primary r => UniqueConstraint r
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull a => Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull (a, b)


-- | This module defines proposition interfaces for database value type and
--   record type width.
module Database.Record.Persistable

-- | Proposition to specify type <tt>q</tt> is database value type,
--   contains null value
data PersistableSqlType q

-- | Null value of database value type <tt>q</tt>.
runPersistableNullValue :: PersistableSqlType q -> q

-- | Unsafely specify <a>PersistableSqlType</a> axiom from specified
--   database null value which type is <tt>q</tt>.
unsafePersistableSqlTypeFromNull :: q -> PersistableSqlType q

-- | Proposition to specify width of Haskell type <tt>a</tt>. The width is
--   length of database value list which is converted from Haskell type
--   <tt>a</tt>.
type PersistableRecordWidth a = ProductConst (Sum Int) a

-- | Get width <a>Int</a> value of record type <tt>a</tt>.
runPersistableRecordWidth :: PersistableRecordWidth a -> Int

-- | Unsafely specify <a>PersistableRecordWidth</a> axiom from specified
--   width of Haskell type <tt>a</tt>.
unsafePersistableRecordWidth :: Int -> PersistableRecordWidth a

-- | Unsafely specify <a>PersistableRecordWidth</a> axiom for Haskell type
--   <tt>a</tt> which is single column type.
unsafeValueWidth :: PersistableRecordWidth a

-- | Derivation rule of <a>PersistableRecordWidth</a> for tuple (,) type.
(<&>) :: PersistableRecordWidth a -> PersistableRecordWidth b -> PersistableRecordWidth (a, b)

-- | Derivation rule of <a>PersistableRecordWidth</a> from from Haskell
--   type <tt>a</tt> into for Haskell type <a>Maybe</a> <tt>a</tt>.
maybeWidth :: PersistableRecordWidth a -> PersistableRecordWidth (Maybe a)

-- | Interface of derivation rule for <a>PersistableSqlType</a>.
class Eq q => PersistableType q
persistableType :: PersistableType q => PersistableSqlType q

-- | Implicitly derived null value of database value type.
sqlNullValue :: PersistableType q => q

-- | <a>PersistableWidth</a> <tt>a</tt> is implicit rule to derive
--   <a>PersistableRecordWidth</a> <tt>a</tt> width proposition for type
--   <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>PersistableWidth</a> class,
--   so you can make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance PersistableWidth Foo
--   </pre>
class PersistableWidth a
persistableWidth :: PersistableWidth a => PersistableRecordWidth a
persistableWidth :: (PersistableWidth a, Generic a, GFieldWidthList (Rep a)) => PersistableRecordWidth a

-- | Pass type parameter and inferred width value.
derivedWidth :: PersistableWidth a => (PersistableRecordWidth a, Int)

-- | Generic width value list of record fields.
class GFieldWidthList f

-- | Restricted in product isomorphism record type b
data ProductConst a b

-- | extract constant value of <a>ProductConst</a>.
getProductConst :: ProductConst a b -> a

-- | Generic offset array of record fields.
genericFieldOffsets :: (Generic a, GFieldWidthList (Rep a)) => ProductConst (Array Int Int) a
instance GHC.Base.Monoid a => Data.Functor.ProductIsomorphic.Class.ProductIsoApplicative (Database.Record.Persistable.ProductConst a)
instance Data.Functor.ProductIsomorphic.Class.ProductIsoFunctor (Database.Record.Persistable.ProductConst a)
instance Database.Record.Persistable.PersistableWidth a => Database.Record.Persistable.GFieldWidthList (GHC.Generics.K1 i a)
instance Database.Record.Persistable.PersistableWidth a => Database.Record.Persistable.PersistableWidth (GHC.Maybe.Maybe a)
instance Database.Record.Persistable.PersistableWidth ()
instance Database.Record.Persistable.GFieldWidthList GHC.Generics.U1
instance (Database.Record.Persistable.GFieldWidthList a, Database.Record.Persistable.GFieldWidthList b) => Database.Record.Persistable.GFieldWidthList (a GHC.Generics.:*: b)
instance Database.Record.Persistable.GFieldWidthList a => Database.Record.Persistable.GFieldWidthList (GHC.Generics.M1 i c a)
instance GHC.Show.Show a => GHC.Show.Show (Database.Record.Persistable.ProductConst a b)


-- | This module defines interfaces from list of database value type into
--   Haskell type.
module Database.Record.FromSql

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> is data-type wrapping
--   function to convert from list of database value type (to receive from
--   database) [<tt>q</tt>] into Haskell type <tt>a</tt>
--   
--   This structure is similar to parser. While running
--   <a>RecordFromSql</a> behavior is the same as non-fail-able parser
--   which parse list of database value type [<tt>q</tt>] stream.
--   
--   So, <a>RecordFromSql</a> <tt>q</tt> is <a>Monad</a> and
--   <a>Applicative</a> instance like parser monad. When, you have data
--   constructor and objects like below.
--   
--   <pre>
--   data MyRecord = MyRecord Foo Bar Baz
--   </pre>
--   
--   <pre>
--   foo :: <a>RecordFromSql</a> SqlValue Foo
--   foo =  ...
--   bar :: <a>RecordFromSql</a> SqlValue Bar
--   bar =  ...
--   baz :: <a>RecordFromSql</a> SqlValue Baz
--   baz =  ...
--   </pre>
--   
--   You can get composed <a>RecordFromSql</a> like below.
--   
--   <pre>
--   myRecord :: RecordFromSql SqlValue MyRecord
--   myRecord =  MyRecord &lt;$&gt; foo &lt;*&gt; bar &lt;*&gt; baz
--   </pre>
data RecordFromSql q a

-- | Run <a>RecordFromSql</a> parser function object. Convert from list of
--   database value type [<tt>q</tt>] into Haskell type <tt>a</tt> and rest
--   of list [<tt>q</tt>].
runTakeRecord :: RecordFromSql q a -> [q] -> (a, [q])

-- | Run <a>RecordFromSql</a> parser function object. Convert from list of
--   database value type [<tt>q</tt>] into Haskell type <tt>a</tt>.
runToRecord :: RecordFromSql q a -> [q] -> a

-- | Axiom of <a>RecordFromSql</a> for database value type <tt>q</tt> and
--   Haskell type <tt>a</tt>
createRecordFromSql :: ([q] -> (a, [q])) -> RecordFromSql q a

-- | Derivation rule of <a>RecordFromSql</a> parser function object for
--   Haskell tuple (,) type.
(<&>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q (a, b)
infixl 4 <&>

-- | Derivation rule of <a>RecordFromSql</a> parser function object for
--   Haskell <a>Maybe</a> type.
maybeRecord :: PersistableType q => RecordFromSql q a -> ColumnConstraint NotNull a -> RecordFromSql q (Maybe a)

-- | <a>FromSql</a> <tt>q</tt> <tt>a</tt> is implicit rule to derive
--   <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function
--   against type <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>FromSql</a> class, so you
--   can make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   import Database.HDBC (SqlValue)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance FromSql SqlValue Foo
--   </pre>
class FromSql q a

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function.
recordFromSql :: FromSql q a => RecordFromSql q a

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function.
recordFromSql :: (FromSql q a, Generic a, GFromSql q (Rep a)) => RecordFromSql q a

-- | Run implicit <a>RecordFromSql</a> parser function object. Convert from
--   list of database value type [<tt>q</tt>] into haskell type <tt>a</tt>
--   and rest of list [<tt>q</tt>].
takeRecord :: FromSql q a => [q] -> (a, [q])

-- | Run implicit <a>RecordFromSql</a> parser function object. Convert from
--   list of database value type [<tt>q</tt>] into haskell type <tt>a</tt>.
toRecord :: FromSql q a => [q] -> a

-- | Derivation rule of <a>RecordFromSql</a> parser function object for
--   value convert function.
valueRecordFromSql :: (q -> a) -> RecordFromSql q a
instance Database.Record.FromSql.FromSql q a => Database.Record.FromSql.GFromSql q (GHC.Generics.K1 i a)
instance (Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull a, Database.Record.FromSql.FromSql q a, Database.Record.Persistable.PersistableType q) => Database.Record.FromSql.FromSql q (GHC.Maybe.Maybe a)
instance Database.Record.FromSql.FromSql q ()
instance Database.Record.FromSql.GFromSql q GHC.Generics.U1
instance (Database.Record.FromSql.GFromSql q a, Database.Record.FromSql.GFromSql q b) => Database.Record.FromSql.GFromSql q (a GHC.Generics.:*: b)
instance Database.Record.FromSql.GFromSql q a => Database.Record.FromSql.GFromSql q (GHC.Generics.M1 i c a)
instance GHC.Base.Monad (Database.Record.FromSql.RecordFromSql q)
instance GHC.Base.Functor (Database.Record.FromSql.RecordFromSql q)
instance GHC.Base.Applicative (Database.Record.FromSql.RecordFromSql q)


-- | This module defines interfaces from Haskell type into list of database
--   value type.
module Database.Record.ToSql

-- | Context type to convert into database value list.
type ToSqlM q a = Writer (DList q) a

-- | extract appended print result of record.
execToSqlM :: ToSqlM q a -> [q]

-- | <a>RecordToSql</a> <tt>q</tt> <tt>a</tt> is data-type wrapping
--   function to convert from Haskell type <tt>a</tt> into list of database
--   value type (to send to database) [<tt>q</tt>].
--   
--   This structure is similar to printer. While running <a>RecordToSql</a>
--   behavior is the same as list printer. which appends list of database
--   value type [<tt>q</tt>] stream.
data RecordToSql q a

-- | Run <a>RecordToSql</a> printer function object. Convert from Haskell
--   type <tt>a</tt> into list of database value type [<tt>q</tt>].
runFromRecord :: RecordToSql q a -> a -> [q]

-- | Finalize <a>RecordToSql</a> record printer.
wrapToSql :: (a -> ToSqlM q ()) -> RecordToSql q a

-- | Axiom of <a>RecordToSql</a> for database value type <tt>q</tt> and
--   Haksell type <tt>a</tt>.
createRecordToSql :: (a -> [q]) -> RecordToSql q a

-- | Derivation rule of <a>RecordToSql</a> printer function object for
--   Haskell tuple (,) type.
(<&>) :: RecordToSql q a -> RecordToSql q b -> RecordToSql q (a, b)
infixl 4 <&>

-- | <a>ToSql</a> <tt>q</tt> <tt>a</tt> is implicit rule to derive
--   <a>RecordToSql</a> <tt>q</tt> <tt>a</tt> record printer function for
--   type <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>ToSql</a> class, so you can
--   make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   import Database.HDBC (SqlValue)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance ToSql SqlValue Foo
--   </pre>
--   
--   To make instances of <a>ToSql</a> manually, <a>ToSql</a> <tt>q</tt>
--   <tt>a</tt> and <a>RecordToSql</a> 'q <tt>a</tt> are composable with
--   monadic context. When, you have data constructor and objects like
--   below.
--   
--   <pre>
--   data MyRecord = MyRecord Foo Bar Baz
--   </pre>
--   
--   <pre>
--   instance ToSql SqlValue Foo where
--     ...
--   instance ToSql SqlValue Bar where
--     ...
--   instance ToSql SqlValue Baz where
--     ...
--   </pre>
--   
--   You can get composed <a>ToSql</a> implicit rule like below.
--   
--   <pre>
--   instance ToSql SqlValue MyRecord where
--     recordToSql =
--     recordToSql = wrapToSql $ \ (MyRecord x y z) -&gt; do
--       putRecord x
--       putRecord y
--       putRecord z
--   </pre>
class PersistableWidth a => ToSql q a

-- | Derived <a>RecordToSql</a> printer function object.
recordToSql :: ToSql q a => RecordToSql q a

-- | Derived <a>RecordToSql</a> printer function object.
recordToSql :: (ToSql q a, Generic a, GToSql q (Rep a)) => RecordToSql q a

-- | Run implicit <a>RecordToSql</a> printer function object. Context to
--   convert haskell record type <tt>a</tt> into lib of database value type
--   [<tt>q</tt>].
putRecord :: ToSql q a => a -> ToSqlM q ()

-- | Run <a>RecordToSql</a> empty printer.
putEmpty :: () -> ToSqlM q ()

-- | Run implicit <a>RecordToSql</a> printer function object. Convert from
--   haskell type <tt>a</tt> into list of database value type [<tt>q</tt>].
fromRecord :: ToSql q a => a -> [q]

-- | Derivation rule of <a>RecordToSql</a> printer function object for
--   value convert function.
valueRecordToSql :: (a -> q) -> RecordToSql q a

-- | Convert from Haskell type <tt>ra</tt> into database value <tt>q</tt>
--   list expected by update form like
--   
--   <pre>
--   UPDATE <i>table</i> SET <i>c0</i> = ?, <i>c1</i> = ?, <i>c2</i> = ? ... WHERE <i>key0</i> = ? AND <i>key1</i> = ? AND <i>key2</i> = ? ...
--   </pre>
--   
--   using printer function object infered by ToSql ra q.
updateValuesByUnique :: ToSql q ra => KeyConstraint Unique ra -> ra -> [q]

-- | Convert like <tt>updateValuesByUnique'</tt> using implicit
--   <a>RecordToSql</a> and <tt>ColumnConstraint</tt>.
updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q]

-- | Make untyped indexes to update column from key indexes and record
--   width. Expected by update form like
--   
--   <pre>
--   UPDATE <i>table</i> SET <i>c0</i> = ?, <i>c1</i> = ?, <i>c2</i> = ? ... WHERE <i>key0</i> = ? AND <i>key1</i> = ? AND key2 = ? ...
--   
--   </pre>
untypedUpdateValuesIndex :: [Int] -> Int -> [Int]

-- | Unsafely specify key indexes to convert from Haskell type <tt>ra</tt>
--   into database value <tt>q</tt> list expected by update form like
--   
--   <pre>
--   UPDATE <i>table</i> SET <i>c0</i> = ?, <i>c1</i> = ?, <i>c2</i> = ? ... WHERE <i>key0</i> = ? AND <i>key1</i> = ? AND <i>key2</i> = ? ...
--   </pre>
--   
--   using <a>RecordToSql</a> printer function object.
unsafeUpdateValuesWithIndexes :: ToSql q ra => [Int] -> ra -> [q]
instance Database.Record.ToSql.ToSql q a => Database.Record.ToSql.GToSql q (GHC.Generics.K1 i a)
instance (Database.Record.Persistable.PersistableType q, Database.Record.ToSql.ToSql q a) => Database.Record.ToSql.ToSql q (GHC.Maybe.Maybe a)
instance Database.Record.ToSql.ToSql q ()
instance Database.Record.ToSql.GToSql q GHC.Generics.U1
instance (Database.Record.ToSql.GToSql q a, Database.Record.ToSql.GToSql q b) => Database.Record.ToSql.GToSql q (a GHC.Generics.:*: b)
instance Database.Record.ToSql.GToSql q a => Database.Record.ToSql.GToSql q (GHC.Generics.M1 i c a)

module Database.Record.TupleInstances
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b) => Database.Record.Persistable.PersistableWidth (a, b)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b) => Database.Record.FromSql.FromSql q (a, b)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b) => Database.Record.ToSql.ToSql q (a, b)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b, Database.Record.Persistable.PersistableWidth c) => Database.Record.Persistable.PersistableWidth (a, b, c)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b, Database.Record.FromSql.FromSql q c) => Database.Record.FromSql.FromSql q (a, b, c)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b, Database.Record.ToSql.ToSql q c) => Database.Record.ToSql.ToSql q (a, b, c)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b, Database.Record.Persistable.PersistableWidth c, Database.Record.Persistable.PersistableWidth d) => Database.Record.Persistable.PersistableWidth (a, b, c, d)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b, Database.Record.FromSql.FromSql q c, Database.Record.FromSql.FromSql q d) => Database.Record.FromSql.FromSql q (a, b, c, d)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b, Database.Record.ToSql.ToSql q c, Database.Record.ToSql.ToSql q d) => Database.Record.ToSql.ToSql q (a, b, c, d)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b, Database.Record.Persistable.PersistableWidth c, Database.Record.Persistable.PersistableWidth d, Database.Record.Persistable.PersistableWidth e) => Database.Record.Persistable.PersistableWidth (a, b, c, d, e)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b, Database.Record.FromSql.FromSql q c, Database.Record.FromSql.FromSql q d, Database.Record.FromSql.FromSql q e) => Database.Record.FromSql.FromSql q (a, b, c, d, e)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b, Database.Record.ToSql.ToSql q c, Database.Record.ToSql.ToSql q d, Database.Record.ToSql.ToSql q e) => Database.Record.ToSql.ToSql q (a, b, c, d, e)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b, Database.Record.Persistable.PersistableWidth c, Database.Record.Persistable.PersistableWidth d, Database.Record.Persistable.PersistableWidth e, Database.Record.Persistable.PersistableWidth f) => Database.Record.Persistable.PersistableWidth (a, b, c, d, e, f)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b, Database.Record.FromSql.FromSql q c, Database.Record.FromSql.FromSql q d, Database.Record.FromSql.FromSql q e, Database.Record.FromSql.FromSql q f) => Database.Record.FromSql.FromSql q (a, b, c, d, e, f)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b, Database.Record.ToSql.ToSql q c, Database.Record.ToSql.ToSql q d, Database.Record.ToSql.ToSql q e, Database.Record.ToSql.ToSql q f) => Database.Record.ToSql.ToSql q (a, b, c, d, e, f)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b, Database.Record.Persistable.PersistableWidth c, Database.Record.Persistable.PersistableWidth d, Database.Record.Persistable.PersistableWidth e, Database.Record.Persistable.PersistableWidth f, Database.Record.Persistable.PersistableWidth g) => Database.Record.Persistable.PersistableWidth (a, b, c, d, e, f, g)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b, Database.Record.FromSql.FromSql q c, Database.Record.FromSql.FromSql q d, Database.Record.FromSql.FromSql q e, Database.Record.FromSql.FromSql q f, Database.Record.FromSql.FromSql q g) => Database.Record.FromSql.FromSql q (a, b, c, d, e, f, g)
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b, Database.Record.ToSql.ToSql q c, Database.Record.ToSql.ToSql q d, Database.Record.ToSql.ToSql q e, Database.Record.ToSql.ToSql q f, Database.Record.ToSql.ToSql q g) => Database.Record.ToSql.ToSql q (a, b, c, d, e, f, g)


-- | This is integrated module which contains types to represent table
--   constraints and interfaces to bind between SQL database values and
--   Haskell records.
module Database.Record

-- | Interface of inference rule for <a>KeyConstraint</a> proof object.
class HasKeyConstraint c a

-- | Infer <a>ColumnConstraint</a> proof object.
keyConstraint :: HasKeyConstraint c a => KeyConstraint c a

-- | Specialized primary constraint.
type PrimaryConstraint = KeyConstraint Primary

-- | Specialized unique constraint.
type UniqueConstraint = KeyConstraint Unique

-- | Proof object to specify table constraint for table record type
--   <tt>r</tt> and constraint <tt>c</tt>. Constraint is specified by
--   composite key.
data KeyConstraint c r

-- | Interface of inference rule for <a>ColumnConstraint</a> proof object.
class HasColumnConstraint c a

-- | Infer <a>ColumnConstraint</a> proof object.
columnConstraint :: HasColumnConstraint c a => ColumnConstraint c a

-- | Specialized primary constraint.
type PrimaryColumnConstraint = ColumnConstraint Primary

-- | Specialized not-null constraint.
type NotNullColumnConstraint = ColumnConstraint NotNull

-- | Specialized unique constraint.
type UniqueColumnConstraint = ColumnConstraint Unique

-- | Constraint type. Primary key.
data Primary

-- | Constraint type. Not-null key.
data NotNull

-- | Constraint type. Unique key.
data Unique

-- | Proof object to specify table constraint for table record type
--   <tt>r</tt> and constraint <tt>c</tt> specified by a single column.
data ColumnConstraint c r

-- | Derivation rule for <a>UniqueColumnConstraint</a>. Derive Unique from
--   Primary.
uniqueColumn :: PrimaryColumnConstraint r -> UniqueColumnConstraint r

-- | Derivation rule for <a>NotNullColumnConstraint</a>. Derive NotNull
--   from Primary.
notNullColumn :: PrimaryColumnConstraint r -> NotNullColumnConstraint r

-- | Inferred <a>UniqueColumnConstraint</a> proof object. Record type
--   <tt>r</tt> has unique key which is derived <tt>r</tt> has primary key.
derivedUniqueColumnConstraint :: HasColumnConstraint Primary r => UniqueColumnConstraint r

-- | Inferred <a>NotNullColumnConstraint</a> proof object. Record type
--   <tt>r</tt> has not-null key which is derived <tt>r</tt> has primary
--   key.
derivedNotNullColumnConstraint :: HasColumnConstraint Primary r => NotNullColumnConstraint r

-- | Derivation rule for <a>KeyConstraint</a>. Derive from
--   <a>ColumnConstraint</a>.
deriveComposite :: ColumnConstraint c r -> KeyConstraint c r

-- | Derivation rule for <a>UniqueConstraint</a>.
unique :: PrimaryConstraint r -> UniqueConstraint r

-- | Inferred <a>PrimaryConstraint</a> proof object. Record type <tt>r</tt>
--   has composite primary key which is derived <tt>r</tt> has single
--   column primary key.
derivedCompositePrimary :: HasColumnConstraint Primary r => PrimaryConstraint r

-- | Inferred <a>UniqueConstraint</a> proof object. Record type <tt>r</tt>
--   has unique key which is derived <tt>r</tt> has primary key.
derivedUniqueConstraint :: HasKeyConstraint Primary r => UniqueConstraint r

-- | <a>PersistableWidth</a> <tt>a</tt> is implicit rule to derive
--   <a>PersistableRecordWidth</a> <tt>a</tt> width proposition for type
--   <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>PersistableWidth</a> class,
--   so you can make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance PersistableWidth Foo
--   </pre>
class PersistableWidth a
persistableWidth :: PersistableWidth a => PersistableRecordWidth a
persistableWidth :: (PersistableWidth a, Generic a, GFieldWidthList (Rep a)) => PersistableRecordWidth a

-- | Interface of derivation rule for <a>PersistableSqlType</a>.
class Eq q => PersistableType q
persistableType :: PersistableType q => PersistableSqlType q

-- | Proposition to specify width of Haskell type <tt>a</tt>. The width is
--   length of database value list which is converted from Haskell type
--   <tt>a</tt>.
type PersistableRecordWidth a = ProductConst (Sum Int) a

-- | Proposition to specify type <tt>q</tt> is database value type,
--   contains null value
data PersistableSqlType q

-- | Implicitly derived null value of database value type.
sqlNullValue :: PersistableType q => q

-- | Pass type parameter and inferred width value.
derivedWidth :: PersistableWidth a => (PersistableRecordWidth a, Int)

-- | <a>FromSql</a> <tt>q</tt> <tt>a</tt> is implicit rule to derive
--   <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function
--   against type <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>FromSql</a> class, so you
--   can make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   import Database.HDBC (SqlValue)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance FromSql SqlValue Foo
--   </pre>
class FromSql q a

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function.
recordFromSql :: FromSql q a => RecordFromSql q a

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> record parser function.
recordFromSql :: (FromSql q a, Generic a, GFromSql q (Rep a)) => RecordFromSql q a

-- | <a>RecordFromSql</a> <tt>q</tt> <tt>a</tt> is data-type wrapping
--   function to convert from list of database value type (to receive from
--   database) [<tt>q</tt>] into Haskell type <tt>a</tt>
--   
--   This structure is similar to parser. While running
--   <a>RecordFromSql</a> behavior is the same as non-fail-able parser
--   which parse list of database value type [<tt>q</tt>] stream.
--   
--   So, <a>RecordFromSql</a> <tt>q</tt> is <a>Monad</a> and
--   <a>Applicative</a> instance like parser monad. When, you have data
--   constructor and objects like below.
--   
--   <pre>
--   data MyRecord = MyRecord Foo Bar Baz
--   </pre>
--   
--   <pre>
--   foo :: <a>RecordFromSql</a> SqlValue Foo
--   foo =  ...
--   bar :: <a>RecordFromSql</a> SqlValue Bar
--   bar =  ...
--   baz :: <a>RecordFromSql</a> SqlValue Baz
--   baz =  ...
--   </pre>
--   
--   You can get composed <a>RecordFromSql</a> like below.
--   
--   <pre>
--   myRecord :: RecordFromSql SqlValue MyRecord
--   myRecord =  MyRecord &lt;$&gt; foo &lt;*&gt; bar &lt;*&gt; baz
--   </pre>
data RecordFromSql q a

-- | Run implicit <a>RecordFromSql</a> parser function object. Convert from
--   list of database value type [<tt>q</tt>] into haskell type <tt>a</tt>
--   and rest of list [<tt>q</tt>].
takeRecord :: FromSql q a => [q] -> (a, [q])

-- | Run implicit <a>RecordFromSql</a> parser function object. Convert from
--   list of database value type [<tt>q</tt>] into haskell type <tt>a</tt>.
toRecord :: FromSql q a => [q] -> a

-- | Derivation rule of <a>RecordFromSql</a> parser function object for
--   value convert function.
valueRecordFromSql :: (q -> a) -> RecordFromSql q a

-- | <a>ToSql</a> <tt>q</tt> <tt>a</tt> is implicit rule to derive
--   <a>RecordToSql</a> <tt>q</tt> <tt>a</tt> record printer function for
--   type <tt>a</tt>.
--   
--   Generic programming
--   (<a>https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming</a>)
--   with default signature is available for <a>ToSql</a> class, so you can
--   make instance like below:
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   import GHC.Generics (Generic)
--   import Database.HDBC (SqlValue)
--   --
--   data Foo = Foo { ... } deriving Generic
--   instance ToSql SqlValue Foo
--   </pre>
--   
--   To make instances of <a>ToSql</a> manually, <a>ToSql</a> <tt>q</tt>
--   <tt>a</tt> and <a>RecordToSql</a> 'q <tt>a</tt> are composable with
--   monadic context. When, you have data constructor and objects like
--   below.
--   
--   <pre>
--   data MyRecord = MyRecord Foo Bar Baz
--   </pre>
--   
--   <pre>
--   instance ToSql SqlValue Foo where
--     ...
--   instance ToSql SqlValue Bar where
--     ...
--   instance ToSql SqlValue Baz where
--     ...
--   </pre>
--   
--   You can get composed <a>ToSql</a> implicit rule like below.
--   
--   <pre>
--   instance ToSql SqlValue MyRecord where
--     recordToSql =
--     recordToSql = wrapToSql $ \ (MyRecord x y z) -&gt; do
--       putRecord x
--       putRecord y
--       putRecord z
--   </pre>
class PersistableWidth a => ToSql q a

-- | Derived <a>RecordToSql</a> printer function object.
recordToSql :: ToSql q a => RecordToSql q a

-- | Derived <a>RecordToSql</a> printer function object.
recordToSql :: (ToSql q a, Generic a, GToSql q (Rep a)) => RecordToSql q a

-- | <a>RecordToSql</a> <tt>q</tt> <tt>a</tt> is data-type wrapping
--   function to convert from Haskell type <tt>a</tt> into list of database
--   value type (to send to database) [<tt>q</tt>].
--   
--   This structure is similar to printer. While running <a>RecordToSql</a>
--   behavior is the same as list printer. which appends list of database
--   value type [<tt>q</tt>] stream.
data RecordToSql q a

-- | Context type to convert into database value list.
type ToSqlM q a = Writer (DList q) a

-- | Run implicit <a>RecordToSql</a> printer function object. Context to
--   convert haskell record type <tt>a</tt> into lib of database value type
--   [<tt>q</tt>].
putRecord :: ToSql q a => a -> ToSqlM q ()

-- | Run <a>RecordToSql</a> empty printer.
putEmpty :: () -> ToSqlM q ()

-- | Run implicit <a>RecordToSql</a> printer function object. Convert from
--   haskell type <tt>a</tt> into list of database value type [<tt>q</tt>].
fromRecord :: ToSql q a => a -> [q]

-- | Derivation rule of <a>RecordToSql</a> printer function object for
--   value convert function.
valueRecordToSql :: (a -> q) -> RecordToSql q a

-- | Convert from Haskell type <tt>ra</tt> into database value <tt>q</tt>
--   list expected by update form like
--   
--   <pre>
--   UPDATE <i>table</i> SET <i>c0</i> = ?, <i>c1</i> = ?, <i>c2</i> = ? ... WHERE <i>key0</i> = ? AND <i>key1</i> = ? AND <i>key2</i> = ? ...
--   </pre>
--   
--   using printer function object infered by ToSql ra q.
updateValuesByUnique :: ToSql q ra => KeyConstraint Unique ra -> ra -> [q]

-- | Convert like <tt>updateValuesByUnique'</tt> using implicit
--   <a>RecordToSql</a> and <tt>ColumnConstraint</tt>.
updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q]


-- | This module defines templates for Haskell record type and type class
--   instances to map between list of untyped SQL type and Haskell record
--   type.
module Database.Record.TH

-- | Template of <a>HasColumnConstraint</a> instance.
defineHasColumnConstraintInstance :: TypeQ -> TypeQ -> Int -> Q [Dec]

-- | Template of <a>HasKeyConstraint</a> instance.
defineHasPrimaryConstraintInstanceDerived :: TypeQ -> Q [Dec]

-- | Template of <a>HasColumnConstraint</a> <a>Primary</a> instance.
defineHasPrimaryKeyInstance :: TypeQ -> [Int] -> Q [Dec]

-- | Template of <a>HasColumnConstraint</a> <a>NotNull</a> instance.
defineHasNotNullKeyInstance :: TypeQ -> Int -> Q [Dec]

-- | Record type definition template.
defineRecordType :: ConName -> [(VarName, TypeQ)] -> [Name] -> Q [Dec]

-- | Record type definition template with configured names.
defineRecordTypeWithConfig :: NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]

-- | Column offset array definition.
defineColumnOffsets :: ConName -> Q [Dec]

-- | Record type width expression template.
recordWidthTemplate :: TypeQ -> ExpQ

-- | Polymorphic <a>PersistableWidth</a> instance template.
definePersistableWidthInstance :: TypeQ -> [Name] -> Q [Dec]

-- | Polymorphic record parser and printer instance templates for
--   converting between list of SQL type and Haskell record type.
defineSqlPersistableInstances :: TypeQ -> TypeQ -> [Name] -> Q [Dec]

-- | <a>NameConfig</a> type to customize names of expanded record
--   templates.
data NameConfig

-- | Default implementation of <a>NameConfig</a> type. To change how
--   generated record types and their columns are named, use record update
--   syntax:
--   
--   <pre>
--   defaultNameConfig
--     { recordTypeName = \schema table -&gt; <a>varCamelcaseName</a> $ schema ++ "_" ++ table
--     -- ^ append the table name after the schema name. e.g. <a>SchemaTable</a>
--     , columnName = \table column -&gt; <a>varCamelcaseName</a> $ table ++ "_" ++ column
--     -- ^ append the column name after the table name. e.g. "tableColumn"
--     }
--   </pre>
defaultNameConfig :: NameConfig

-- | Make record type name generated from the table's definition. The first
--   argument is the schema name of the table, and the second argument is
--   the table name.
recordTypeName :: NameConfig -> String -> String -> ConName

-- | Make each field label of the record type generated from the table's
--   definition. The first argument is the table name, and the second
--   argument is the column name.
columnName :: NameConfig -> String -> String -> VarName

-- | Record constructor templates from SQL table name <a>String</a>.
recordTemplate :: NameConfig -> String -> String -> (TypeQ, ExpQ)

-- | Variable expression of record column offset array.
columnOffsetsVarNameDefault :: Name -> VarName

-- | Templates for single column value type.
deriveNotNullType :: TypeQ -> Q [Dec]

-- | Template to define tuple instances of persistable-record classes.
defineTupleInstances :: Int -> Q [Dec]
instance GHC.Show.Show Database.Record.TH.NameConfig


-- | Single column instances for example to load schema of system catalogs.
module Database.Record.Instances
instance Database.Record.Persistable.PersistableWidth GHC.Types.Bool
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Types.Bool
instance Database.Record.Persistable.PersistableWidth GHC.Types.Char
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Types.Char
instance Database.Record.Persistable.PersistableWidth GHC.Base.String
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Base.String
instance Database.Record.Persistable.PersistableWidth GHC.Int.Int8
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Int.Int8
instance Database.Record.Persistable.PersistableWidth GHC.Int.Int16
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Int.Int16
instance Database.Record.Persistable.PersistableWidth GHC.Int.Int32
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Int.Int32
instance Database.Record.Persistable.PersistableWidth GHC.Int.Int64
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Int.Int64
instance Database.Record.Persistable.PersistableWidth GHC.Types.Int
instance Database.Record.KeyConstraint.HasColumnConstraint Database.Record.KeyConstraint.NotNull GHC.Types.Int
