-- 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.4.1.1


-- | This module defines interfaces between Haskell type and list of SQL
--   type.
module Database.Record.Persistable

-- | Proof object to specify type <tt>q</tt> is SQL type
data PersistableSqlType q

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

-- | Unsafely generate <a>PersistableSqlType</a> proof object from
--   specified SQL null value which type is <tt>q</tt>.
unsafePersistableSqlTypeFromNull :: q -> PersistableSqlType q

-- | Proof object to specify width of Haskell type <tt>a</tt> when
--   converting to SQL type list.
data PersistableRecordWidth a

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

-- | Unsafely generate <a>PersistableRecordWidth</a> proof object from
--   specified width of Haskell type <tt>a</tt>.
unsafePersistableRecordWidth :: Int -> PersistableRecordWidth a

-- | Unsafely generate <a>PersistableRecordWidth</a> proof object 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 inference rule for <a>PersistableSqlType</a> proof object
class Eq q => PersistableType q
persistableType :: PersistableType q => PersistableSqlType q

-- | Inferred Null value of SQL type.
sqlNullValue :: PersistableType q => q

-- | Interface of inference rule for <a>PersistableRecordWidth</a> proof
--   object
class PersistableWidth a
persistableWidth :: PersistableWidth a => PersistableRecordWidth a

-- | Pass type parameter and inferred width value.
derivedWidth :: PersistableWidth a => (PersistableRecordWidth a, Int)
instance (Database.Record.Persistable.PersistableWidth a, Database.Record.Persistable.PersistableWidth b) => Database.Record.Persistable.PersistableWidth (a, b)
instance Database.Record.Persistable.PersistableWidth a => Database.Record.Persistable.PersistableWidth (GHC.Base.Maybe a)
instance Database.Record.Persistable.PersistableWidth ()


-- | 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 interfaces from Haskell type into list of SQL
--   type.
module Database.Record.ToSql

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

-- | Proof object type to convert from Haskell type <tt>a</tt> into list of
--   SQL type [<tt>q</tt>].
data RecordToSql q a

-- | Run <a>RecordToSql</a> proof object. Convert from Haskell type
--   <tt>a</tt> into list of SQL type [<tt>q</tt>].
runFromRecord :: RecordToSql q a -> a -> [q]

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

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

-- | Inference rule interface for <a>RecordToSql</a> proof object.
class ToSql q a

-- | Infer <a>RecordToSql</a> proof object.
recordToSql :: ToSql q a => RecordToSql q a

-- | Run inferred <a>RecordToSql</a> proof object. Context to convert
--   haskell record type <tt>a</tt> into SQL type <tt>q</tt> list.
putRecord :: ToSql q a => a -> ToSqlM q ()

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

-- | Run inferred <a>RecordToSql</a> proof object. Convert from haskell
--   type <tt>a</tt> into list of SQL type [<tt>q</tt>].
fromRecord :: ToSql q a => a -> [q]

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

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

-- | Convert from Haskell type <tt>ra</tt> into SQL value <tt>q</tt> list
--   expected by update form like
--   
--   <i>UPDATE <a>table</a> SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ?
--   AND key1 = ? AND key2 = ? ... </i>
--   
--   using <a>RecordToSql</a> proof object.
updateValuesByUnique' :: RecordToSql q ra -> KeyConstraint Unique ra -> ra -> [q]

-- | Convert like <a>updateValuesByUnique'</a> using inferred
--   <a>RecordToSql</a> proof object.
updateValuesByUnique :: ToSql q ra => KeyConstraint Unique ra -> ra -> [q]

-- | Convert like <a>updateValuesByUnique'</a> using inferred
--   <a>RecordToSql</a> and <tt>ColumnConstraint</tt> proof objects.
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
--   
--   <i>UPDATE <a>table</a> SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ?
--   AND key1 = ? AND key2 = ? ... </i>
untypedUpdateValuesIndex :: [Int] -> Int -> [Int]

-- | Unsafely specify key indexes to convert from Haskell type <tt>ra</tt>
--   into SQL value <tt>q</tt> list expected by update form like
--   
--   <i>UPDATE <a>table</a> SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ?
--   AND key1 = ? AND key2 = ? ... </i>
--   
--   using <a>RecordToSql</a> proof object.
unsafeUpdateValuesWithIndexes :: RecordToSql q ra -> [Int] -> ra -> [q]
instance (Database.Record.ToSql.ToSql q a, Database.Record.ToSql.ToSql q b) => Database.Record.ToSql.ToSql q (a, b)
instance (Database.Record.Persistable.PersistableType q, Database.Record.Persistable.PersistableWidth a, Database.Record.ToSql.ToSql q a) => Database.Record.ToSql.ToSql q (GHC.Base.Maybe a)
instance Database.Record.ToSql.ToSql q ()


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

-- | Proof object type to convert from sql value type <tt>q</tt> list into
--   Haskell type <tt>a</tt>.
data RecordFromSql q a

-- | Run <a>RecordFromSql</a> proof object. Convert from list of SQL 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> proof object. Convert from list of SQL type
--   [<tt>q</tt>] into Haskell type <tt>a</tt>.
runToRecord :: RecordFromSql q a -> [q] -> a

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

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

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

-- | Inference rule interface for <a>RecordFromSql</a> proof object.
class FromSql q a

-- | <a>RecordFromSql</a> proof object.
recordFromSql :: FromSql q a => RecordFromSql q a

-- | Run inferred <a>RecordFromSql</a> proof object. Convert from list of
--   SQL 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 inferred <a>RecordFromSql</a> proof object. Convert from list of
--   SQL type [<tt>q</tt>] into haskell type <tt>a</tt>.
toRecord :: FromSql q a => [q] -> a

-- | Derivation rule of <a>RecordFromSql</a> proof object for value convert
--   function.
valueRecordFromSql :: (q -> a) -> RecordFromSql q 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)
instance (Database.Record.FromSql.FromSql q a, Database.Record.FromSql.FromSql q b) => Database.Record.FromSql.FromSql q (a, b)
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.Base.Maybe a)
instance Database.Record.FromSql.FromSql q ()


-- | 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


-- | 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

-- | All templates for record type.
defineRecord :: TypeQ -> (VarName, VarName) -> ConName -> [(VarName, TypeQ)] -> [Name] -> Q [Dec]

-- | All templates for record type with configured names.
defineRecordWithConfig :: TypeQ -> NameConfig -> String -> String -> [(String, TypeQ)] -> [Name] -> Q [Dec]

-- | Name to specify deriving <a>Eq</a>

-- | <i>Deprecated: Use TH quasi-quotation like ''Eq instead of this.</i>
derivingEq :: Name

-- | Name to specify deriving <a>Show</a>

-- | <i>Deprecated: Use TH quasi-quotation like ''Show instead of this.</i>
derivingShow :: Name

-- | Name to specify deriving <a>Read</a>

-- | <i>Deprecated: Use TH quasi-quotation like ''Read instead of this.</i>
derivingRead :: Name

-- | Name to specify deriving <a>Data</a>

-- | <i>Deprecated: Use TH quasi-quotation like ''Data instead of this.</i>
derivingData :: Name

-- | Name to specify deriving <a>Typeable</a>

-- | <i>Deprecated: Use TH quasi-quotation like ''Typeable instead of
--   this.</i>
derivingTypeable :: Name

-- | 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 declaration template.
defineRecordType :: ConName -> [(VarName, TypeQ)] -> [Name] -> Q [Dec]

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

-- | All templates depending on SQL value type.
makeRecordPersistableWithSqlType :: TypeQ -> (VarName, VarName) -> (TypeQ, ExpQ) -> Int -> Q [Dec]

-- | All templates depending on SQL value type with configured names.
makeRecordPersistableWithSqlTypeWithConfig :: TypeQ -> NameConfig -> String -> String -> Int -> Q [Dec]

-- | All templates depending on SQL value type with default names.
makeRecordPersistableWithSqlTypeDefault :: TypeQ -> String -> String -> Int -> Q [Dec]

-- | All templates depending on SQL value type. Defined record type
--   information is used.
makeRecordPersistableWithSqlTypeFromDefined :: TypeQ -> (VarName, VarName) -> Name -> Q [Dec]

-- | All templates depending on SQL value type with default names. Defined
--   record type information is used.
makeRecordPersistableWithSqlTypeDefaultFromDefined :: TypeQ -> Name -> Q [Dec]

-- | Column offset array and <a>PersistableWidth</a> instance declaration.
defineColumnOffsets :: ConName -> [TypeQ] -> Q [Dec]

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

-- | Record parser template.
defineRecordParser :: TypeQ -> VarName -> (TypeQ, ExpQ) -> Int -> Q [Dec]

-- | Record printer template.
defineRecordPrinter :: TypeQ -> VarName -> (TypeQ, ExpQ) -> Int -> Q [Dec]

-- | Record parser and printer instance templates for converting between
--   list of SQL type and Haskell record type.
definePersistableInstance :: TypeQ -> TypeQ -> VarName -> VarName -> Int -> Q [Dec]

-- | Low-level reify interface for record type name.
reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))

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

-- | Default implementation of <a>NameConfig</a> type. To customize this,
--   use record update syntax.
defaultNameConfig :: NameConfig

-- | Make record type symbol name from schema name and table name in SQL
recordTypeName :: NameConfig -> String -> String -> ConName

-- | Make column variable symbol name from table name and column name in
--   SQL
columnName :: NameConfig -> String -> String -> VarName

-- | Record type constructor template from SQL table name <a>String</a>.
recordType :: NameConfig -> String -> String -> TypeQ

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

-- | Generate persistable function symbol names using default rule.
persistableFunctionNamesDefault :: Name -> (VarName, VarName)

-- | Templates for single column value type.
deriveNotNullType :: TypeQ -> 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
