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


-- | Type-safe datatype-database mapping library.
--   
--   This library maps your datatypes to a relational model, in a way
--   similar to what ORM libraries do in object-oriented programming. The
--   mapping can be configured to work with almost any schema. Groundhog
--   supports schema migrations, composite keys, advanced expressions in
--   queries, and much more. See tutorial
--   <a>https://www.fpcomplete.com/user/lykahb/groundhog</a> and examples
--   <a>https://github.com/lykahb/groundhog/tree/master/examples</a> on
--   GitHub.
@package groundhog
@version 0.10.0


-- | This module defines the functions and datatypes used throughout the
--   framework. Most of them are for the internal use
module Database.Groundhog.Core

-- | Only instances of this class can be persisted in a database
class (PurePersistField (AutoKey v), PurePersistField (DefaultKey v)) => PersistEntity v where {
    
    -- | This type is used for typesafe manipulation of separate fields of
    --   datatype v. Each constructor in <a>Field</a> corresponds to its field
    --   in a datatype v. It is parametrised by constructor phantom type and
    --   field value type.
    data family Field v :: ((* -> *) -> *) -> * -> *;
    
    -- | A unique identifier of a value stored in a database. This may be a
    --   primary key, a constraint or unique indices. The second parameter is
    --   the key description.
    data family Key v :: * -> *;
    
    -- | This type is the default autoincremented key for the entity. If entity
    --   does not have such key, AutoKey v = ().
    type family AutoKey v;
    
    -- | This type is the default key for the entity.
    type family DefaultKey v;
    
    -- | It is HFalse for entity with one constructor and HTrue for sum types.
    type family IsSumType v;
}

-- | Returns a complete description of the type
entityDef :: (PersistEntity v, DbDescriptor db) => proxy db -> v -> EntityDef

-- | Marshalls value to a list of <a>PersistValue</a> ready for insert to a
--   database
toEntityPersistValues :: (PersistEntity v, PersistBackend m) => v -> m ([PersistValue] -> [PersistValue])

-- | Constructs the value from the list of <a>PersistValue</a>
fromEntityPersistValues :: (PersistEntity v, PersistBackend m) => [PersistValue] -> m (v, [PersistValue])

-- | Returns constructor number and a list of uniques names and
--   corresponding field values
getUniques :: PersistEntity v => v -> (Int, [(String, [PersistValue] -> [PersistValue])])

-- | Is internally used by FieldLike Field instance We could avoid this
--   function if class FieldLike allowed FieldLike Fields Data or FieldLike
--   (Fields Data). However that would require additional extensions in
--   user-space code
entityFieldChain :: (PersistEntity v, DbDescriptor db) => proxy db -> Field v c a -> FieldChain

-- | A raw value which can be stored in any backend and can be marshalled
--   to and from a <a>PersistField</a>.
data PersistValue
PersistString :: String -> PersistValue
PersistText :: Text -> PersistValue
PersistByteString :: ByteString -> PersistValue
PersistInt64 :: Int64 -> PersistValue
PersistDouble :: Double -> PersistValue
PersistBool :: Bool -> PersistValue
PersistDay :: Day -> PersistValue
PersistTimeOfDay :: TimeOfDay -> PersistValue
PersistUTCTime :: UTCTime -> PersistValue
PersistZonedTime :: ZT -> PersistValue
PersistNull :: PersistValue

-- | Creating some datatypes may require calling a function, using a
--   special constructor, or other syntax. The string (which can have
--   placeholders) is included into query without escaping. The recursive
--   constructions are not allowed, i.e., [PersistValue] cannot contain
--   PersistCustom values.
PersistCustom :: Utf8 -> [PersistValue] -> PersistValue

-- | Represents everything which can be put into a database. This data can
--   be stored in multiple columns and tables. To get value of those
--   columns we might need to access another table. That is why the result
--   type is monadic.
class PersistField a

-- | Return name of the type. If it is polymorphic, the names of parameter
--   types are separated with <a>delim</a> symbol
persistName :: PersistField a => a -> String

-- | Convert a value into something which can be stored in a database
--   column. Note that for complex datatypes it may insert them to return
--   identifier
toPersistValues :: (PersistField a, PersistBackend m) => a -> m ([PersistValue] -> [PersistValue])

-- | Constructs a value from a <a>PersistValue</a>. For complex datatypes
--   it may query the database
fromPersistValues :: (PersistField a, PersistBackend m) => [PersistValue] -> m (a, [PersistValue])

-- | Description of value type. It depends on database so that we can have,
--   for example, xml column type in Postgres and varchar type in other
--   databases
dbType :: (PersistField a, DbDescriptor db) => proxy db -> a -> DbType

-- | Represents all datatypes that map into a single column. Getting value
--   for that column might require monadic actions to access other tables.
class PersistField a => SinglePersistField a
toSinglePersistValue :: (SinglePersistField a, PersistBackend m) => a -> m PersistValue
fromSinglePersistValue :: (SinglePersistField a, PersistBackend m) => PersistValue -> m a

-- | Represents all datatypes that map into several columns. Getting values
--   for those columns is pure.
class PersistField a => PurePersistField a
toPurePersistValues :: PurePersistField a => a -> [PersistValue] -> [PersistValue]
fromPurePersistValues :: PurePersistField a => [PersistValue] -> (a, [PersistValue])

-- | Datatypes which can be converted directly to <a>PersistValue</a>
class PersistField a => PrimitivePersistField a
toPrimitivePersistValue :: PrimitivePersistField a => a -> PersistValue
fromPrimitivePersistValue :: PrimitivePersistField a => PersistValue -> a
class PersistField v => Embedded v where {
    data family Selector v :: * -> *;
}
selectorNum :: Embedded v => Selector v a -> Int

-- | Any data that can be fetched from a database
class Projection p a | p -> a where {
    type family ProjectionDb p db :: Constraint;
    type family ProjectionRestriction p r :: Constraint;
}

-- | It returns multiple expressions that can be transformed into values
--   which can be selected. Difflist is used for concatenation efficiency.
projectionExprs :: (Projection p a, DbDescriptor db, ProjectionDb p db, ProjectionRestriction p r) => p -> [UntypedExpr db r] -> [UntypedExpr db r]

-- | It is like <a>fromPersistValues</a>. However, we cannot use it for
--   projections in all cases. For the <a>PersistEntity</a> instances
--   <a>fromPersistValues</a> expects entity id instead of the entity
--   values.
projectionResult :: (Projection p a, PersistBackend m) => p -> [PersistValue] -> m (a, [PersistValue])
class (Projection p a, ProjectionDb p db, ProjectionRestriction p r) => Projection' p db r a
data RestrictionHolder v (c :: (* -> *) -> *)

-- | A holder for Unique constraints
data Unique (u :: (* -> *) -> *)

-- | It allows to store autogenerated keys of one database in another if
--   they have different datatype.
data KeyForBackend db v
KeyForBackend :: AutoKeyType db -> KeyForBackend db v

-- | Key marked with this type can have value for any backend
data BackendSpecific

-- | A phantom datatype to make instance head different <tt>c
--   (ConstructorMarker v)</tt>
data ConstructorMarker v a

-- | A phantom datatype to make instance head different <tt>u (UniqueMarker
--   v)</tt>
data UniqueMarker v a
data HFalse
data HTrue

-- | Avoid orphan instances.
newtype ZT
ZT :: ZonedTime -> ZT

-- | Datatype for incremental building SQL queries
newtype Utf8
Utf8 :: Builder -> Utf8
fromUtf8 :: Utf8 -> ByteString
delim :: Char

-- | Represents condition for a query.
data Cond db r
And :: Cond db r -> Cond db r -> Cond db r
Or :: Cond db r -> Cond db r -> Cond db r
Not :: Cond db r -> Cond db r
Compare :: ExprRelation -> UntypedExpr db r -> UntypedExpr db r -> Cond db r
CondRaw :: QueryRaw db r -> Cond db r
CondEmpty :: Cond db r
data ExprRelation
Eq :: ExprRelation
Ne :: ExprRelation
Gt :: ExprRelation
Lt :: ExprRelation
Ge :: ExprRelation
Le :: ExprRelation
data Update db r
Update :: f -> UntypedExpr db r -> Update db r

-- | Accesses fields of the embedded datatypes. For example, <tt>SomeField
--   ==. ("abc", "def") ||. SomeField ~&gt; Tuple2_0Selector ==. "def"</tt>
(~>) :: (EntityConstr v c, FieldLike f a, DbDescriptor db, Projection' f db (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField db v c a'
infixl 5 ~>

-- | This subset of Assignable is for plain database fields.
class Assignable f a => FieldLike f a | f -> a
fieldChain :: (FieldLike f a, DbDescriptor db, ProjectionDb f db) => proxy db -> f -> FieldChain

-- | This subset of Projection instances is for things that behave like
--   fields. Namely, they can occur in condition expressions (for example,
--   Field and SubField) and on the left side of update statements. For
--   example "lower(field)" is a valid Projection, but not Field like
--   because it cannot be on the left side. Datatypes that index PostgreSQL
--   arrays "arr[5]" or access composites "(comp).subfield" are valid
--   instances of Assignable.
class Projection f a => Assignable f a | f -> a
newtype SubField db v (c :: (* -> *) -> *) a
SubField :: FieldChain -> SubField db v a

-- | It can be used in expressions like a regular field. For example,
--   <tt>delete (AutoKeyField ==. k)</tt> or <tt>delete (AutoKeyField ==. k
--   ||. SomeField ==. "DUPLICATE")</tt>
data AutoKeyField v (c :: (* -> *) -> *)
[AutoKeyField] :: AutoKeyField v c

-- | It is used to map field to column names. It can be either a column
--   name for a regular field of non-embedded type or a list of this field
--   and the outer fields in reverse order. Eg, fieldChain $ SomeField
--   ~&gt; Tuple2_0Selector may result in [("val0", DbString), ("some",
--   DbEmbedded False [dbType "", dbType True])].
type FieldChain = ((String, DbType), [(String, EmbeddedDef)])

-- | Types which are never NULL when converted to <a>PersistValue</a>.
--   Consider the type <tt>Maybe (Maybe a)</tt>. Now Nothing is stored as
--   NULL, so we cannot distinguish between Just Nothing and Nothing which
--   is a problem. The purpose of this class is to ban the inner Maybe's.
--   Maybe this class can be removed when support for inner Maybe's
--   appears.
class NeverNull a

-- | Used to uniformly represent fields, constants and more complex things,
--   e.g., arithmetic expressions. A value should be converted to
--   <a>UntypedExpr</a> for usage in expressions
data UntypedExpr db r
[ExprRaw] :: DbType -> QueryRaw db r -> UntypedExpr db r
[ExprField] :: FieldChain -> UntypedExpr db r
[ExprPure] :: forall db r a. PurePersistField a => a -> UntypedExpr db r
[ExprCond] :: Cond db r -> UntypedExpr db r

-- | Expr with phantom type helps to keep type safety in complex
--   expressions
newtype Expr db r a
Expr :: UntypedExpr db r -> Expr db r a

-- | Defines sort order of a result-set
data Order db r
Asc :: f -> Order db r
Desc :: f -> Order db r

-- | This class helps to check that limit, offset, or order clauses are
--   added to condition only once.
class HasSelectOptions a db r | a -> db r where {
    type family HasLimit a;
    type family HasOffset a;
    type family HasOrder a;
    type family HasDistinct a;
}
getSelectOptions :: HasSelectOptions a db r => a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
data SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
SelectOptions :: Cond db r -> Maybe Int -> Maybe Int -> [Order db r] -> Bool -> [(String, QueryRaw db r)] -> SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
[condOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> Cond db r
[limitOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> Maybe Int
[offsetOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> Maybe Int

-- | False - no DISTINCT, True - DISTINCT
[orderOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> [Order db r]

-- | The name of the option and part of the SQL which will be put later
[distinctOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> Bool
[dbSpecificOptions] :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> [(String, QueryRaw db r)]
limitTo :: (HasSelectOptions a db r, HasLimit a ~ HFalse) => a -> Int -> SelectOptions db r HTrue (HasOffset a) (HasOrder a) (HasDistinct a)
offsetBy :: (HasSelectOptions a db r, HasOffset a ~ HFalse) => a -> Int -> SelectOptions db r (HasLimit a) HTrue (HasOrder a) (HasDistinct a)
orderBy :: (HasSelectOptions a db r, HasOrder a ~ HFalse) => a -> [Order db r] -> SelectOptions db r (HasLimit a) (HasOffset a) HTrue (HasDistinct a)

-- | Select DISTINCT rows. <tt>select $ distinct CondEmpty</tt>
distinct :: (HasSelectOptions a db r, HasDistinct a ~ HFalse) => a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) HTrue

-- | A DB data type. Naming attempts to reflect the underlying Haskell
--   datatypes, eg DbString instead of DbVarchar. Different databases may
--   have different representations for these types.
data DbTypePrimitive' str
DbString :: DbTypePrimitive' str
DbInt32 :: DbTypePrimitive' str
DbInt64 :: DbTypePrimitive' str
DbReal :: DbTypePrimitive' str
DbBool :: DbTypePrimitive' str
DbDay :: DbTypePrimitive' str
DbTime :: DbTypePrimitive' str
DbDayTime :: DbTypePrimitive' str
DbDayTimeZoned :: DbTypePrimitive' str

-- | ByteString
DbBlob :: DbTypePrimitive' str
DbOther :: OtherTypeDef' str -> DbTypePrimitive' str
type DbTypePrimitive = DbTypePrimitive' String
data DbType

-- | type, nullable, default value, reference
DbTypePrimitive :: DbTypePrimitive -> Bool -> Maybe String -> Maybe ParentTableReference -> DbType
DbEmbedded :: EmbeddedDef -> Maybe ParentTableReference -> DbType

-- | List table name and type of its argument
DbList :: String -> DbType -> DbType

-- | Describes an ADT.
data EntityDef' str dbType
EntityDef :: str -> Maybe str -> [dbType] -> [ConstructorDef' str dbType] -> EntityDef' str dbType

-- | Entity name. <tt>entityName (entityDef v) == persistName v</tt>
[entityName] :: EntityDef' str dbType -> str

-- | Database schema for the entity table and tables of its constructors
[entitySchema] :: EntityDef' str dbType -> Maybe str

-- | Named types of the instantiated polymorphic type parameters
[typeParams] :: EntityDef' str dbType -> [dbType]

-- | List of entity constructors definitions
[constructors] :: EntityDef' str dbType -> [ConstructorDef' str dbType]
type EntityDef = EntityDef' String DbType

-- | The first argument is a flag which defines if the field names should
--   be concatenated with the outer field name (False) or used as is which
--   provides full control over table column names (True). Value False
--   should be the default value so that a datatype can be embedded without
--   name conflict concern. The second argument list of field names and
--   field types.
data EmbeddedDef' str dbType
EmbeddedDef :: Bool -> [(str, dbType)] -> EmbeddedDef' str dbType
type EmbeddedDef = EmbeddedDef' String DbType

-- | Stores a database type. The list contains two kinds of tokens for the
--   type string. Backend will choose a string representation for
--   DbTypePrimitive's, and the string literals will go to the type as-is.
--   As the final step, these tokens are concatenated. For example,
--   <tt>[Left "varchar(50)"]</tt> will become a string with max length and
--   <tt>[Right DbInt64, Left "[]"]</tt> will become integer[] in
--   PostgreSQL.
newtype OtherTypeDef' str
OtherTypeDef :: [Either str (DbTypePrimitive' str)] -> OtherTypeDef' str
type OtherTypeDef = OtherTypeDef' String

-- | Describes an entity constructor
data ConstructorDef' str dbType
ConstructorDef :: str -> Maybe str -> [(str, dbType)] -> [UniqueDef' str (Either (str, dbType) str)] -> ConstructorDef' str dbType

-- | Constructor name
[constrName] :: ConstructorDef' str dbType -> str

-- | Autokey name if any
[constrAutoKeyName] :: ConstructorDef' str dbType -> Maybe str

-- | Parameter names with their named type
[constrParams] :: ConstructorDef' str dbType -> [(str, dbType)]

-- | Uniqueness constraints on the constructor fiels
[constrUniques] :: ConstructorDef' str dbType -> [UniqueDef' str (Either (str, dbType) str)]
type ConstructorDef = ConstructorDef' String DbType

-- | Phantom constructors are made instances of this class. This class
--   should be used only by Template Haskell codegen
class Constructor c

-- | Returns constructor index which can be used to get ConstructorDef from
--   EntityDef
phantomConstrNum :: Constructor c => c (a :: * -> *) -> Int

-- | This class helps type inference in cases when query does not contain
--   any fields which define the constructor, but the entity has only one.
--   For example, in <tt>select $ AutoKeyField ==. k</tt> the condition
--   would need type annotation with constructor name only if we select a
--   sum type.
class PersistEntity v => EntityConstr v c
entityConstrNum :: EntityConstr v c => proxy v -> c (a :: * -> *) -> Int
class PurePersistField uKey => IsUniqueKey uKey

-- | Creates value of unique key using the data extracted from the passed
--   value
extractUnique :: (IsUniqueKey uKey, uKey ~ Key v u) => v -> uKey

-- | Ordinal number of the unique constraint in the list returned by
--   <a>constrUniques</a>
uniqueNum :: IsUniqueKey uKey => uKey -> Int

-- | Unique name and list of the fields that form a unique combination. The
--   fields are parametrized to reuse this datatype both with field and
--   DbType and with column name
data UniqueDef' str field
UniqueDef :: Maybe str -> UniqueType -> [field] -> UniqueDef' str field
[uniqueDefName] :: UniqueDef' str field -> Maybe str
[uniqueDefType] :: UniqueDef' str field -> UniqueType
[uniqueDefFields] :: UniqueDef' str field -> [field]

-- | Field is either a pair of entity field name and its type or an
--   expression which will be used in query as-is.
type UniqueDef = UniqueDef' String (Either (String, DbType) String)

-- | Defines how to treat the unique set of fields for a datatype
data UniqueType
UniqueConstraint :: UniqueType
UniqueIndex :: UniqueType

-- | is autoincremented
UniquePrimary :: Bool -> UniqueType
data ReferenceActionType
NoAction :: ReferenceActionType
Restrict :: ReferenceActionType
Cascade :: ReferenceActionType
SetNull :: ReferenceActionType
SetDefault :: ReferenceActionType

-- | The reference contains either EntityDef of the parent table and name
--   of the unique constraint. Or for tables not mapped by Groundhog schema
--   name, table name, and list of columns Reference to the autogenerated
--   key of a mapped entity = (Left (entityDef, Nothing), onDelete,
--   onUpdate) Reference to a unique key of a mapped entity = (Left
--   (entityDef, Just uniqueKeyName), onDelete, onUpdate) Reference to a
--   table that is not mapped = (Right ((schema, tableName), columns),
--   onDelete, onUpdate)
type ParentTableReference = (Either (EntityDef, Maybe String) ((Maybe String, String), [String]), Maybe ReferenceActionType, Maybe ReferenceActionType)

-- | Either error messages or migration queries with safety flag and
--   execution order
type SingleMigration = Either [String] [(Bool, Int, String)]

-- | Datatype names and corresponding migrations
type NamedMigrations = Map String SingleMigration
type Migration m = StateT NamedMigrations m ()

-- | This class helps to shorten the type signatures of user monadic code.
--   If your monad has several connections, e.g., for main and audit
--   databases, create run*Db function runAuditDb :: Action conn a -&gt; m
--   a
class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {
    type family Conn m;
}
getConnection :: PersistBackend m => m (Conn m)
class (DbDescriptor conn, ConnectionManager conn) => PersistBackendConn conn

-- | Insert a new record to a database and return its autogenerated key or
--   ()
insert :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (AutoKey v)

-- | Insert a new record to a database. For some backends it may be faster
--   than <a>insert</a>.
insert_ :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()

-- | Try to insert a record and return Right newkey. If there is a
--   constraint violation for the given constraint, Left oldkey is returned
--   , where oldkey is an identifier of the record with the matching
--   values.
insertBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m (Either (AutoKey v) (AutoKey v))

-- | Try to insert a record and return Right newkey. If there is a
--   constraint violation for any constraint, Left oldkey is returned ,
--   where oldkey is an identifier of the record with the matching values.
--   Note that if several constraints are violated, a key of an arbitrary
--   matching record is returned.
insertByAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (Either (AutoKey v) (AutoKey v))

-- | Replace a record with the given autogenerated key. Result is undefined
--   if the record does not exist.
replace :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> v -> m ()

-- | Replace a record. The unique key marker defines what unique key of the
--   entity is used.
replaceBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m ()

-- | Return a list of the records satisfying the condition. Example:
--   <tt>select $ (FirstField ==. "abc" &amp;&amp;. SecondField &gt;.
--   "def") `orderBy` [Asc ThirdField] `limitTo` 100</tt>
select :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => opts -> m [v]

-- | Return a list of the records satisfying the condition. Example:
--   <tt>select $ (FirstField ==. "abc" &amp;&amp;. SecondField &gt;.
--   "def") `orderBy` [Asc ThirdField] `limitTo` 100</tt>
selectStream :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => opts -> m (RowStream v)

-- | Return a list of all records. Order is undefined. It can be useful for
--   datatypes with multiple constructors.
selectAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => m [(AutoKey v, v)]

-- | Return a list of all records. Order is undefined. It can be useful for
--   datatypes with multiple constructors.
selectAllStream :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => m (RowStream (AutoKey v, v))

-- | Fetch an entity from a database
get :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m (Maybe v)

-- | Fetch an entity from a database by its unique key
getBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => Key v (Unique u) -> m (Maybe v)

-- | Update the records satisfying the condition. Example: <tt>update
--   [FirstField =. "abc"] $ FirstField ==. "def"</tt>
update :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => [Update conn (RestrictionHolder v c)] -> Cond conn (RestrictionHolder v c) -> m ()

-- | Remove the records satisfying the condition
delete :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m ()

-- | Remove the record with given key. No-op if the record does not exist
deleteBy :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m ()

-- | Remove all records. The entity parameter is used only for type
--   inference.
deleteAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()

-- | Count total number of records satisfying the condition
count :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m Int

-- | Count total number of records with all constructors. The entity
--   parameter is used only for type inference
countAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m Int

-- | Fetch projection of some fields. Example: <tt>project (SecondField,
--   ThirdField) $ (FirstField ==. "abc" &amp;&amp;. SecondField &gt;.
--   "def") `orderBy` [Asc ThirdField] `offsetBy` 100</tt>
project :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => p -> opts -> m [a]
projectStream :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => p -> opts -> m (RowStream a)

-- | Check database schema and create migrations for the entity and the
--   entities it contains
migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m

-- | Execute raw query
executeRaw :: (PersistBackendConn conn, PersistBackend m, Conn m ~ conn) => Bool -> String -> [PersistValue] -> m ()

-- | Execute raw query with results
queryRaw :: (PersistBackendConn conn, PersistBackend m, Conn m ~ conn) => Bool -> String -> [PersistValue] -> m (RowStream [PersistValue])
insertList :: (PersistBackendConn conn, PersistField a, PersistBackend m, Conn m ~ conn) => [a] -> m Int64
getList :: (PersistBackendConn conn, PersistField a, PersistBackend m, Conn m ~ conn) => Int64 -> m [a]
type Action conn = ReaderT conn IO
type TryAction e m conn = ReaderT conn (ExceptT e m)
type RowStream a = Acquire (IO (Maybe a))
class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where {
    
    -- | Type of the database default auto-incremented key. For example, Sqlite
    --   has Int64
    type family AutoKeyType db;
    
    -- | Value of this type can be used as a part of a query. For example, it
    --   can be RenderS for relational databases, or BSON for MongoDB.
    type family QueryRaw db :: * -> *;
}

-- | Name of backend
backendName :: DbDescriptor db => proxy db -> String

-- | <i>Deprecated: Use <a>PersistBackend</a> constraint instead. If you
--   need to specify a backend, add (PersistBackend m, Conn m ~ Postgresql)
--   </i>
type DbPersist = ReaderT

-- | <i>Deprecated: Use <a>PersistBackend</a> constraint instead. If you
--   need to specify a backend, add (PersistBackend m, Conn m ~ Postgresql)
--   </i>
runDbPersist :: Monad m => DbPersist conn m a -> conn -> m a
class ExtractConnection cm conn | cm -> conn

-- | Extracts the connection. The connection manager can be a pool or the
--   connection itself
extractConn :: (ExtractConnection cm conn, MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> cm -> m a

-- | Connection manager provides connection to the passed function handles
--   transations. Manager can be a connection itself, a pool, Snaplet in
--   Snap, foundation datatype in Yesod, etc.
class ConnectionManager conn

-- | Opens the transaction.
withConn :: (ConnectionManager conn, MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> conn -> m a
class TryConnectionManager conn

-- | Tries the transaction, using a provided function which evaluates to an
--   Either. Any Left result will cause transaction rollback.
tryWithConn :: (TryConnectionManager conn, MonadBaseControl IO m, MonadIO m, MonadCatch m) => (conn -> n a) -> (n a -> m (Either SomeException a)) -> conn -> m (Either SomeException a)
class Savepoint conn

-- | Wraps the passed action into a named savepoint
withConnSavepoint :: (Savepoint conn, MonadBaseControl IO m, MonadIO m) => String -> m a -> conn -> m a

-- | It helps to run <a>withConnSavepoint</a> within a monad. Make sure
--   that transaction is open
withSavepoint :: (PersistBackend m, MonadBaseControl IO m, MonadIO m, Savepoint (Conn m)) => String -> m a -> m a

-- | It helps to run database operations within an application monad.
runDb :: PersistBackend m => Action (Conn m) a -> m a

-- | Runs action within connection. It can handle a simple connection, a
--   pool of them, etc.
runDbConn :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a

-- | Runs TryAction within connection.
runTryDbConn :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn, Exception e) => TryAction e m conn a -> cm -> m (Either SomeException a)

-- | Tries Action within connection.
runTryDbConn' :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m (Either SomeException a)

-- | It helps to run database operations within an application monad.
--   Unlike <a>runDb</a> it does not wrap action in transaction
runDb' :: PersistBackend m => Action (Conn m) a -> m a

-- | It is similar to <a>runDbConn</a> but runs action without transaction.
--   
--   <pre>
--   flip withConn conn $ \conn -&gt; liftIO $ do
--     -- transaction is already opened by withConn at this point
--     someIOAction
--     runDbConn' (insert_ value) conn
--   </pre>
runDbConn' :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a
instance GHC.Read.Read Database.Groundhog.Core.PersistValue
instance GHC.Show.Show Database.Groundhog.Core.PersistValue
instance GHC.Classes.Eq Database.Groundhog.Core.PersistValue
instance GHC.Read.Read Database.Groundhog.Core.ZT
instance GHC.Show.Show Database.Groundhog.Core.ZT
instance GHC.Show.Show Database.Groundhog.Core.DbType
instance GHC.Classes.Eq Database.Groundhog.Core.DbType
instance (GHC.Show.Show str, GHC.Show.Show dbType) => GHC.Show.Show (Database.Groundhog.Core.EmbeddedDef' str dbType)
instance (GHC.Classes.Eq str, GHC.Classes.Eq dbType) => GHC.Classes.Eq (Database.Groundhog.Core.EmbeddedDef' str dbType)
instance GHC.Show.Show str => GHC.Show.Show (Database.Groundhog.Core.DbTypePrimitive' str)
instance GHC.Classes.Eq str => GHC.Classes.Eq (Database.Groundhog.Core.DbTypePrimitive' str)
instance GHC.Show.Show str => GHC.Show.Show (Database.Groundhog.Core.OtherTypeDef' str)
instance GHC.Classes.Eq str => GHC.Classes.Eq (Database.Groundhog.Core.OtherTypeDef' str)
instance GHC.Show.Show Database.Groundhog.Core.ReferenceActionType
instance GHC.Classes.Eq Database.Groundhog.Core.ReferenceActionType
instance (GHC.Classes.Eq str, GHC.Classes.Eq dbType) => GHC.Classes.Eq (Database.Groundhog.Core.EntityDef' str dbType)
instance (GHC.Show.Show str, GHC.Show.Show dbType) => GHC.Show.Show (Database.Groundhog.Core.EntityDef' str dbType)
instance (GHC.Classes.Eq str, GHC.Classes.Eq dbType) => GHC.Classes.Eq (Database.Groundhog.Core.ConstructorDef' str dbType)
instance (GHC.Show.Show str, GHC.Show.Show dbType) => GHC.Show.Show (Database.Groundhog.Core.ConstructorDef' str dbType)
instance (GHC.Classes.Eq str, GHC.Classes.Eq field) => GHC.Classes.Eq (Database.Groundhog.Core.UniqueDef' str field)
instance (GHC.Show.Show str, GHC.Show.Show field) => GHC.Show.Show (Database.Groundhog.Core.UniqueDef' str field)
instance GHC.Classes.Ord Database.Groundhog.Core.UniqueType
instance GHC.Classes.Eq Database.Groundhog.Core.UniqueType
instance GHC.Show.Show Database.Groundhog.Core.UniqueType
instance GHC.Show.Show Database.Groundhog.Core.ExprRelation
instance GHC.Show.Show (Database.Groundhog.Core.Expr db r a)
instance GHC.Classes.Eq (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Core.Projection p a, Database.Groundhog.Core.ProjectionDb p db, Database.Groundhog.Core.ProjectionRestriction p r) => Database.Groundhog.Core.Projection' p db r a
instance (db' Data.Type.Equality.~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.Cond db r) db' r
instance (db' Data.Type.Equality.~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r
instance (GHC.Base.Monad m, GHC.Base.Applicative m, GHC.Base.Functor m, Control.Monad.IO.Class.MonadIO m, Database.Groundhog.Core.PersistBackendConn conn) => Database.Groundhog.Core.PersistBackend (Control.Monad.Trans.Reader.ReaderT conn m)
instance GHC.Classes.Eq Database.Groundhog.Core.ZT
instance GHC.Classes.Ord Database.Groundhog.Core.ZT
instance GHC.Classes.Eq Database.Groundhog.Core.Utf8
instance GHC.Show.Show Database.Groundhog.Core.Utf8
instance GHC.Read.Read Database.Groundhog.Core.Utf8


-- | This helper module is intended for use by the backend creators
module Database.Groundhog.Generic

-- | Produce the migrations but not execute them. Fails when an unsafe
--   migration occurs.
createMigration :: Monad m => Migration m -> m NamedMigrations

-- | Execute the migrations with printing to stderr. Fails when an unsafe
--   migration occurs.
executeMigration :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()

-- | Execute the migrations. Fails when an unsafe migration occurs.
executeMigrationSilent :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()

-- | Execute migrations. Executes the unsafe migrations without warnings
--   and prints them to stderr
executeMigrationUnsafe :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()

-- | Creates migrations and executes them with printing to stderr. Fails
--   when an unsafe migration occurs. &gt; runMigration m = createMigration
--   m &gt;&gt;= executeMigration
runMigration :: (PersistBackend m, MonadIO m) => Migration m -> m ()

-- | Creates migrations and silently executes them. Fails when an unsafe
--   migration occurs. &gt; runMigration m = createMigration m &gt;&gt;=
--   executeMigrationSilent
runMigrationSilent :: (PersistBackend m, MonadIO m) => Migration m -> m ()

-- | Creates migrations and executes them with printing to stderr. Executes
--   the unsafe migrations without warnings &gt; runMigrationUnsafe m =
--   createMigration m &gt;&gt;= executeMigrationUnsafe
runMigrationUnsafe :: (PersistBackend m, MonadIO m) => Migration m -> m ()

-- | Returns either a list of errors in migration or a list of queries
getQueries :: Bool -> SingleMigration -> Either [String] [String]

-- | Pretty print the migrations
printMigration :: MonadIO m => NamedMigrations -> m ()

-- | Joins the migrations. The result is either all error messages or all
--   queries
mergeMigrations :: [SingleMigration] -> SingleMigration
primToPersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m ([PersistValue] -> [PersistValue])
primFromPersistValue :: (PersistBackend m, PrimitivePersistField a) => [PersistValue] -> m (a, [PersistValue])
primToPurePersistValues :: PrimitivePersistField a => a -> [PersistValue] -> [PersistValue]
primFromPurePersistValues :: PrimitivePersistField a => [PersistValue] -> (a, [PersistValue])
primToSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m PersistValue
primFromSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => PersistValue -> m a
pureToPersistValue :: (PersistBackend m, PurePersistField a) => a -> m ([PersistValue] -> [PersistValue])
pureFromPersistValue :: (PersistBackend m, PurePersistField a) => [PersistValue] -> m (a, [PersistValue])
singleToPersistValue :: (PersistBackend m, SinglePersistField a) => a -> m ([PersistValue] -> [PersistValue])
singleFromPersistValue :: (PersistBackend m, SinglePersistField a) => [PersistValue] -> m (a, [PersistValue])
toSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> v -> m PersistValue
fromSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> PersistValue -> m v
toPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m ([PersistValue] -> [PersistValue])
fromPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> [PersistValue] -> m (v, [PersistValue])
toSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (AutoKey v)) => v -> m PersistValue
fromSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => PersistValue -> m v
failMessage :: PersistField a => a -> [PersistValue] -> String
failMessageNamed :: String -> [PersistValue] -> String
bracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
finally :: MonadBaseControl IO m => m a -> m b -> m a
onException :: MonadBaseControl IO m => m a -> m b -> m a
data PSFieldDef str
PSFieldDef :: str -> Maybe str -> Maybe str -> Maybe str -> Maybe [PSFieldDef str] -> Maybe str -> Maybe (Maybe ((Maybe str, str), [str]), Maybe ReferenceActionType, Maybe ReferenceActionType) -> Maybe str -> PSFieldDef str

-- | name in the record, bar
[psFieldName] :: PSFieldDef str -> str

-- | column name, SQLbar
[psDbFieldName] :: PSFieldDef str -> Maybe str

-- | column type, inet, NUMERIC(5, 2), VARCHAR(50), etc.
[psDbTypeName] :: PSFieldDef str -> Maybe str

-- | name of constructor in the Field GADT, BarField
[psExprName] :: PSFieldDef str -> Maybe str
[psEmbeddedDef] :: PSFieldDef str -> Maybe [PSFieldDef str]

-- | default value in the database
[psDefaultValue] :: PSFieldDef str -> Maybe str
[psReferenceParent] :: PSFieldDef str -> Maybe (Maybe ((Maybe str, str), [str]), Maybe ReferenceActionType, Maybe ReferenceActionType)

-- | name of a pair of functions
[psFieldConverter] :: PSFieldDef str -> Maybe str
applyDbTypeSettings :: PSFieldDef String -> DbType -> DbType
findOne :: (Eq x, Show x) => String -> (a -> x) -> x -> [a] -> a
replaceOne :: (Eq x, Show x) => String -> (a -> x) -> (b -> x) -> (a -> b -> b) -> a -> [b] -> [b]

-- | Returns only old elements, only new elements, and matched pairs (old,
--   new). The new ones exist only in datatype, the old are present only in
--   DB, match is typically by name (the properties of the matched elements
--   may differ).
matchElements :: Show a => (a -> b -> Bool) -> [a] -> [b] -> ([a], [b], [(a, b)])
haveSameElems :: Show a => (a -> b -> Bool) -> [a] -> [b] -> Bool
phantomDb :: PersistBackend m => m (proxy (Conn m))
getDefaultAutoKeyType :: DbDescriptor db => proxy db -> DbTypePrimitive
getUniqueFields :: UniqueDef' str (Either field str) -> [field]
isSimple :: [ConstructorDef] -> Bool
firstRow :: MonadIO m => RowStream a -> m (Maybe a)
streamToList :: MonadIO m => RowStream a -> m [a]
mapStream :: PersistBackendConn conn => (a -> Action conn b) -> RowStream a -> Action conn (RowStream b)
joinStreams :: [Action conn (RowStream a)] -> Action conn (RowStream a)

-- | <i>Deprecated: Use deleteBy instead</i>
deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()
instance GHC.Show.Show str => GHC.Show.Show (Database.Groundhog.Generic.PSFieldDef str)
instance GHC.Classes.Eq str => GHC.Classes.Eq (Database.Groundhog.Generic.PSFieldDef str)

module Database.Groundhog.Instances
data family Selector v :: * -> *
instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Instances.EntityConstr' (Database.Groundhog.Core.IsSumType v) c) => Database.Groundhog.Core.EntityConstr v c
instance Database.Groundhog.Instances.EntityConstr' Database.Groundhog.Core.HFalse c
instance Database.Groundhog.Core.Constructor c => Database.Groundhog.Instances.EntityConstr' Database.Groundhog.Core.HTrue c
instance (Database.Groundhog.Core.PersistField a', Database.Groundhog.Core.PersistField b') => Database.Groundhog.Core.Embedded (a', b')
instance (Database.Groundhog.Core.PersistField a', Database.Groundhog.Core.PersistField b', Database.Groundhog.Core.PersistField c') => Database.Groundhog.Core.Embedded (a', b', c')
instance (Database.Groundhog.Core.PersistField a', Database.Groundhog.Core.PersistField b', Database.Groundhog.Core.PersistField c', Database.Groundhog.Core.PersistField d') => Database.Groundhog.Core.Embedded (a', b', c', d')
instance (Database.Groundhog.Core.PersistField a', Database.Groundhog.Core.PersistField b', Database.Groundhog.Core.PersistField c', Database.Groundhog.Core.PersistField d', Database.Groundhog.Core.PersistField e') => Database.Groundhog.Core.Embedded (a', b', c', d', e')
instance Database.Groundhog.Core.PurePersistField ()
instance (Database.Groundhog.Core.PurePersistField a, Database.Groundhog.Core.PurePersistField b) => Database.Groundhog.Core.PurePersistField (a, b)
instance (Database.Groundhog.Core.PurePersistField a, Database.Groundhog.Core.PurePersistField b, Database.Groundhog.Core.PurePersistField c) => Database.Groundhog.Core.PurePersistField (a, b, c)
instance (Database.Groundhog.Core.PurePersistField a, Database.Groundhog.Core.PurePersistField b, Database.Groundhog.Core.PurePersistField c, Database.Groundhog.Core.PurePersistField d) => Database.Groundhog.Core.PurePersistField (a, b, c, d)
instance (Database.Groundhog.Core.PurePersistField a, Database.Groundhog.Core.PurePersistField b, Database.Groundhog.Core.PurePersistField c, Database.Groundhog.Core.PurePersistField d, Database.Groundhog.Core.PurePersistField e) => Database.Groundhog.Core.PurePersistField (a, b, c, d, e)
instance Database.Groundhog.Core.PrimitivePersistField GHC.Base.String
instance Database.Groundhog.Core.PrimitivePersistField Data.Text.Internal.Text
instance Database.Groundhog.Core.PrimitivePersistField Data.Text.Internal.Lazy.Text
instance Database.Groundhog.Core.PrimitivePersistField Data.ByteString.Internal.ByteString
instance Database.Groundhog.Core.PrimitivePersistField Data.ByteString.Lazy.Internal.ByteString
instance Database.Groundhog.Core.PrimitivePersistField GHC.Types.Int
instance Database.Groundhog.Core.PrimitivePersistField GHC.Int.Int8
instance Database.Groundhog.Core.PrimitivePersistField GHC.Int.Int16
instance Database.Groundhog.Core.PrimitivePersistField GHC.Int.Int32
instance Database.Groundhog.Core.PrimitivePersistField GHC.Int.Int64
instance Database.Groundhog.Core.PrimitivePersistField GHC.Word.Word8
instance Database.Groundhog.Core.PrimitivePersistField GHC.Word.Word16
instance Database.Groundhog.Core.PrimitivePersistField GHC.Word.Word32
instance Database.Groundhog.Core.PrimitivePersistField GHC.Word.Word64
instance Database.Groundhog.Core.PrimitivePersistField GHC.Types.Double
instance Database.Groundhog.Core.PrimitivePersistField GHC.Types.Bool
instance Database.Groundhog.Core.PrimitivePersistField Data.Time.Calendar.Days.Day
instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
instance Database.Groundhog.Core.PrimitivePersistField Data.Time.Clock.Internal.UTCTime.UTCTime
instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
instance Database.Groundhog.Core.PrimitivePersistField Data.Aeson.Types.Internal.Value
instance (Database.Groundhog.Core.PrimitivePersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PrimitivePersistField (GHC.Maybe.Maybe a)
instance (Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.PersistField v) => Database.Groundhog.Core.PrimitivePersistField (Database.Groundhog.Core.KeyForBackend db v)
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PrimitivePersistField a) => Database.Groundhog.Core.PurePersistField a
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PrimitivePersistField a) => Database.Groundhog.Core.SinglePersistField a
instance Database.Groundhog.Core.NeverNull GHC.Base.String
instance Database.Groundhog.Core.NeverNull Data.Text.Internal.Text
instance Database.Groundhog.Core.NeverNull Data.Text.Internal.Lazy.Text
instance Database.Groundhog.Core.NeverNull Data.ByteString.Internal.ByteString
instance Database.Groundhog.Core.NeverNull Data.ByteString.Lazy.Internal.ByteString
instance Database.Groundhog.Core.NeverNull GHC.Types.Int
instance Database.Groundhog.Core.NeverNull GHC.Int.Int8
instance Database.Groundhog.Core.NeverNull GHC.Int.Int16
instance Database.Groundhog.Core.NeverNull GHC.Int.Int32
instance Database.Groundhog.Core.NeverNull GHC.Int.Int64
instance Database.Groundhog.Core.NeverNull GHC.Word.Word8
instance Database.Groundhog.Core.NeverNull GHC.Word.Word16
instance Database.Groundhog.Core.NeverNull GHC.Word.Word32
instance Database.Groundhog.Core.NeverNull GHC.Word.Word64
instance Database.Groundhog.Core.NeverNull GHC.Types.Double
instance Database.Groundhog.Core.NeverNull GHC.Types.Bool
instance Database.Groundhog.Core.NeverNull Data.Time.Calendar.Days.Day
instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
instance Database.Groundhog.Core.NeverNull Data.Time.Clock.Internal.UTCTime.UTCTime
instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
instance Database.Groundhog.Core.NeverNull Data.Aeson.Types.Internal.Value
instance Database.Groundhog.Core.PrimitivePersistField (Database.Groundhog.Core.Key v u) => Database.Groundhog.Core.NeverNull (Database.Groundhog.Core.Key v u)
instance Database.Groundhog.Core.NeverNull (Database.Groundhog.Core.KeyForBackend db v)
instance Database.Groundhog.Core.PersistField Data.ByteString.Internal.ByteString
instance Database.Groundhog.Core.PersistField Data.ByteString.Lazy.Internal.ByteString
instance Database.Groundhog.Core.PersistField Data.Aeson.Types.Internal.Value
instance Database.Groundhog.Core.PersistField GHC.Base.String
instance Database.Groundhog.Core.PersistField Data.Text.Internal.Text
instance Database.Groundhog.Core.PersistField Data.Text.Internal.Lazy.Text
instance Database.Groundhog.Core.PersistField GHC.Types.Int
instance Database.Groundhog.Core.PersistField GHC.Int.Int8
instance Database.Groundhog.Core.PersistField GHC.Int.Int16
instance Database.Groundhog.Core.PersistField GHC.Int.Int32
instance Database.Groundhog.Core.PersistField GHC.Int.Int64
instance Database.Groundhog.Core.PersistField GHC.Word.Word8
instance Database.Groundhog.Core.PersistField GHC.Word.Word16
instance Database.Groundhog.Core.PersistField GHC.Word.Word32
instance Database.Groundhog.Core.PersistField GHC.Word.Word64
instance Database.Groundhog.Core.PersistField GHC.Types.Double
instance Database.Groundhog.Core.PersistField GHC.Types.Bool
instance Database.Groundhog.Core.PersistField Data.Time.Calendar.Days.Day
instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
instance Database.Groundhog.Core.PersistField Data.Time.Clock.Internal.UTCTime.UTCTime
instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PersistField (GHC.Maybe.Maybe a)
instance Database.Groundhog.Core.PersistField a => Database.Groundhog.Core.PersistField [a]
instance Database.Groundhog.Core.PersistField ()
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PersistField b) => Database.Groundhog.Core.PersistField (a, b)
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PersistField b, Database.Groundhog.Core.PersistField c) => Database.Groundhog.Core.PersistField (a, b, c)
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PersistField b, Database.Groundhog.Core.PersistField c, Database.Groundhog.Core.PersistField d) => Database.Groundhog.Core.PersistField (a, b, c, d)
instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.PersistField b, Database.Groundhog.Core.PersistField c, Database.Groundhog.Core.PersistField d, Database.Groundhog.Core.PersistField e) => Database.Groundhog.Core.PersistField (a, b, c, d, e)
instance (Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.PersistField v) => Database.Groundhog.Core.PersistField (Database.Groundhog.Core.KeyForBackend db v)
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.Field v c a) a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.SubField db v c a) a
instance Database.Groundhog.Core.PersistField a => Database.Groundhog.Core.Projection (Database.Groundhog.Core.Expr db r a) a
instance (a Data.Type.Equality.~ GHC.Types.Bool) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.Cond db r) a
instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.AutoKeyField v c) a
instance Database.Groundhog.Core.EntityConstr v c => Database.Groundhog.Core.Projection (c (Database.Groundhog.Core.ConstructorMarker v)) v
instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Projection (u (Database.Groundhog.Core.UniqueMarker v)) k
instance (Database.Groundhog.Core.Projection a1 a1', Database.Groundhog.Core.Projection a2 a2') => Database.Groundhog.Core.Projection (a1, a2) (a1', a2')
instance (Database.Groundhog.Core.Projection a1 a1', Database.Groundhog.Core.Projection a2 a2', Database.Groundhog.Core.Projection a3 a3') => Database.Groundhog.Core.Projection (a1, a2, a3) (a1', a2', a3')
instance (Database.Groundhog.Core.Projection a1 a1', Database.Groundhog.Core.Projection a2 a2', Database.Groundhog.Core.Projection a3 a3', Database.Groundhog.Core.Projection a4 a4') => Database.Groundhog.Core.Projection (a1, a2, a3, a4) (a1', a2', a3', a4')
instance (Database.Groundhog.Core.Projection a1 a1', Database.Groundhog.Core.Projection a2 a2', Database.Groundhog.Core.Projection a3 a3', Database.Groundhog.Core.Projection a4 a4', Database.Groundhog.Core.Projection a5 a5') => Database.Groundhog.Core.Projection (a1, a2, a3, a4, a5) (a1', a2', a3', a4', a5')
instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Assignable (Database.Groundhog.Core.AutoKeyField v c) a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.Assignable (Database.Groundhog.Core.SubField db v c a) a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.Assignable (Database.Groundhog.Core.Field v c a) a
instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Assignable (u (Database.Groundhog.Core.UniqueMarker v)) k
instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.FieldLike (Database.Groundhog.Core.AutoKeyField v c) a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.FieldLike (Database.Groundhog.Core.SubField db v c a) a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.PersistField a) => Database.Groundhog.Core.FieldLike (Database.Groundhog.Core.Field v c a) a
instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.FieldLike (u (Database.Groundhog.Core.UniqueMarker v)) k
instance Data.Aeson.Types.FromJSON.FromJSON Database.Groundhog.Core.PersistValue
instance Data.Aeson.Types.ToJSON.ToJSON Database.Groundhog.Core.PersistValue
instance GHC.Read.Read (Database.Groundhog.Core.Key v u) => Data.Aeson.Types.FromJSON.FromJSON (Database.Groundhog.Core.Key v u)
instance GHC.Show.Show (Database.Groundhog.Core.Key v u) => Data.Aeson.Types.ToJSON.ToJSON (Database.Groundhog.Core.Key v u)


-- | This module provides mechanism for flexible and typesafe usage of
--   plain data values and fields. The expressions can used in conditions
--   and right part of Update statement. Example:
--   
--   <pre>
--   StringField ==. "abc" &amp;&amp;. NumberField &gt;. (0 :: Int) ||. MaybeField ==. (Nothing :: Maybe String) ||. MaybeField ==. Just "def"
--   </pre>
--   
--   Note that polymorphic values like numbers or Nothing must have a type
--   annotation. Comparison operators specific for SQL such as IN and LIKE
--   are defined in <a>Database.Groundhog.Generic.Sql.Functions</a>.
module Database.Groundhog.Expression

-- | Instances of this type can be converted to <a>UntypedExpr</a>. It is
--   useful for uniform manipulation over fields, constant values, etc.
class Expression db r a
toExpr :: Expression db r a => a -> UntypedExpr db r
class Unifiable a b

-- | This helper class can make type signatures more concise
class (Expression db r a, PersistField a') => ExpressionOf db r a a' | a -> a'

-- | Update field
(=.) :: (Assignable f a', ProjectionDb f db, ProjectionRestriction f r, Expression db r b, Unifiable f b) => f -> b -> Update db r
infixr 3 =.

-- | Boolean "and" operator.
(&&.) :: Cond db r -> Cond db r -> Cond db r
infixr 3 &&.

-- | Boolean "or" operator.
(||.) :: Cond db r -> Cond db r -> Cond db r
infixr 2 ||.
(==.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 ==.
(/=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 /=.
(<.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 <.
(<=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 <=.
(>.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 >.
(>=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 >=.

-- | This function more limited than (==.), but has better type inference.
--   If you want to compare your value to Nothing with <tt>(==.)</tt>
--   operator, you have to write the types explicitly <tt>myExpr ==.
--   (Nothing :: Maybe Int)</tt>. TODO: restrict db r
isFieldNothing :: (Expression db r f, Projection f (Maybe a), PrimitivePersistField (Maybe a), Unifiable f (Maybe a)) => f -> Cond db r

-- | Converts value to <a>Expr</a>. It can help to pass values of different
--   types into functions which expect arguments of the same type, like
--   (+).
liftExpr :: ExpressionOf db r a a' => a -> Expr db r a'

-- | It is kept for compatibility with older Groundhog versions and can be
--   replaced with "liftExpr".

-- | <i>Deprecated: Please use liftExpr instead</i>
toArith :: ExpressionOf db r a a' => a -> Expr db r a'
instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r Data.Type.Equality.~ (Database.Groundhog.Expression.Not isDef, GHC.Maybe.Maybe k)) => Database.Groundhog.Expression.NormalizeValue (GHC.Maybe.Maybe (Database.Groundhog.Core.Key v u)) r
instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r Data.Type.Equality.~ (Database.Groundhog.Expression.Not isDef, k)) => Database.Groundhog.Expression.NormalizeValue (Database.Groundhog.Core.Key v u) r
instance (k Data.Type.Equality.~ v) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HTrue v u k
instance (k Data.Type.Equality.~ Database.Groundhog.Core.Key v u) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HFalse v u k
instance (b Data.Type.Equality.~ Database.Groundhog.Core.HFalse) => Database.Groundhog.Expression.TypeEq x y b
instance Database.Groundhog.Expression.TypeEq x x Database.Groundhog.Core.HTrue
instance Database.Groundhog.Expression.NormalizeValue a (isPlain, r) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.Field v c a) (Database.Groundhog.Core.HFalse, r)
instance Database.Groundhog.Expression.NormalizeValue a (isPlain, r) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.SubField db v c a) (Database.Groundhog.Core.HFalse, r)
instance Database.Groundhog.Expression.NormalizeValue a (isPlain, r) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.Expr db r' a) (Database.Groundhog.Core.HFalse, r)
instance Database.Groundhog.Expression.NormalizeValue (Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) (isPlain, r) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (u (Database.Groundhog.Core.UniqueMarker v)) (Database.Groundhog.Core.HFalse, r)
instance Database.Groundhog.Expression.NormalizeValue (Database.Groundhog.Core.Key v Database.Groundhog.Core.BackendSpecific) (isPlain, r) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.AutoKeyField v c) (Database.Groundhog.Core.HFalse, r)
instance Database.Groundhog.Expression.NormalizeValue t r => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse t r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, a)) => Database.Groundhog.Expression.NormalizeValue a r
instance (Database.Groundhog.Expression.Normalize bk a (ak, r), Database.Groundhog.Expression.Normalize ak b (bk, r)) => Database.Groundhog.Expression.Unifiable a b
instance (Database.Groundhog.Expression.Expression db r a, Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue a (flag, a'), Database.Groundhog.Core.PersistField a') => Database.Groundhog.Expression.ExpressionOf db r a a'
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Field v c a) r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.SubField db v c a) r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Expr db r' a) r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u))) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (u (Database.Groundhog.Core.UniqueMarker v)) r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v Database.Groundhog.Core.BackendSpecific)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.AutoKeyField v c) r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.Cond db r') r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Cond db r') r
instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, t)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue t r
instance Database.Groundhog.Expression.Unifiable a a
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.Field v c a)
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, db' Data.Type.Equality.~ db, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.SubField db v c a)
instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.AutoKeyField v c)
instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u), Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (u (Database.Groundhog.Core.UniqueMarker v))
instance (db' Data.Type.Equality.~ db, r' Data.Type.Equality.~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Cond db r)
instance Database.Groundhog.Core.PurePersistField a => Database.Groundhog.Expression.Expression db r a
instance (Database.Groundhog.Core.PersistField a, db' Data.Type.Equality.~ db, r' Data.Type.Equality.~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Expr db r a)


-- | This module defines the functions which are used only for backends
--   creation.
module Database.Groundhog.Generic.Sql

-- | Renders conditions for SQL backend. Returns Nothing if the fields
--   don't have any columns.
renderCond :: SqlDb db => RenderConfig -> Cond db r -> Maybe (RenderS db r)
defaultShowPrim :: PersistValue -> String
renderOrders :: SqlDb db => RenderConfig -> [Order db r] -> RenderS db r
renderUpdates :: SqlDb db => RenderConfig -> [Update db r] -> Maybe (RenderS db r)
renderFields :: StringLike s => (s -> s) -> [(String, DbType)] -> s
renderChain :: RenderConfig -> FieldChain -> [Utf8] -> [Utf8]
renderExpr :: SqlDb db => RenderConfig -> UntypedExpr db r -> RenderS db r
renderExprPriority :: SqlDb db => RenderConfig -> Int -> UntypedExpr db r -> RenderS db r
renderExprExtended :: SqlDb db => RenderConfig -> Int -> UntypedExpr db r -> [RenderS db r]
renderPersistValue :: PersistValue -> RenderS db r

-- | Helps creating an expression which depends on render configuration. It
--   can be used in pair with <a>prerenderExpr</a>. <tt> myExpr x =
--   mkExprWithConf $ conf _ -&gt; let x' = prerenderExpr conf x in x' + x'
--   * x'</tt> @
mkExprWithConf :: (SqlDb db, PersistField a) => (RenderConfig -> Int -> Expr db r a) -> Expr db r a

-- | If we reuse complex expression several times, prerendering it saves
--   time. <a>RenderConfig</a> can be obtained with <a>mkExprWithConf</a>
prerenderExpr :: forall db r a. (SqlDb db, PersistField a) => RenderConfig -> Expr db r a -> Expr db r a
intercalateS :: StringLike s => s -> [s] -> s
commasJoin :: StringLike s => [s] -> s
flatten :: StringLike s => (s -> s) -> (String, DbType) -> [s] -> [s]
data RenderS db r
RenderS :: Utf8 -> ([PersistValue] -> [PersistValue]) -> RenderS db r
[getQuery] :: RenderS db r -> Utf8
[getValues] :: RenderS db r -> [PersistValue] -> [PersistValue]

-- | Datatype for incremental building SQL queries
newtype Utf8
Utf8 :: Builder -> Utf8
newtype RenderConfig
RenderConfig :: (Utf8 -> Utf8) -> RenderConfig
[esc] :: RenderConfig -> Utf8 -> Utf8
fromUtf8 :: Utf8 -> ByteString
class (Semigroup a, Monoid a, IsString a) => StringLike a
fromChar :: StringLike a => Char -> a
fromString :: IsString a => String -> a

-- | An associative operation.
(<>) :: Semigroup a => a -> a -> a
infixr 6 <>
function :: SqlDb db => String -> [UntypedExpr db r] -> Snippet db r
operator :: (SqlDb db, Expression db r a, Expression db r b) => Int -> String -> a -> b -> Snippet db r
parens :: Int -> Int -> RenderS db r -> RenderS db r
mkExpr :: forall db r a. (SqlDb db, PersistField a) => Snippet db r -> Expr db r a

-- | Escape function, priority of the outer operator. The result is a list
--   for the embedded data which may expand to several RenderS.
newtype Snippet db r
Snippet :: (RenderConfig -> Int -> [RenderS db r]) -> Snippet db r

-- | This class distinguishes databases which support SQL-specific
--   expressions. It contains ad hoc members for features whose syntax
--   differs across the databases.
class (DbDescriptor db, QueryRaw db ~ Snippet db) => SqlDb db
append :: (SqlDb db, ExpressionOf db r a String, ExpressionOf db r b String) => a -> b -> Expr db r String
signum' :: (SqlDb db, ExpressionOf db r x a, Num a) => x -> Expr db r a
quotRem' :: (SqlDb db, ExpressionOf db r x a, ExpressionOf db r y a, Integral a) => x -> y -> (Expr db r a, Expr db r a)
equalsOperator :: SqlDb db => RenderS db r -> RenderS db r -> RenderS db r
notEqualsOperator :: SqlDb db => RenderS db r -> RenderS db r -> RenderS db r

-- | This class distinguishes databases which support trigonometry and
--   other math functions. For example, PostgreSQL has them but Sqlite does
--   not. It contains ad hoc members for features whose syntax differs
--   across the databases.
class SqlDb db => FloatingSqlDb db

-- | Natural logarithm
log' :: (FloatingSqlDb db, ExpressionOf db r x a, Floating a) => x -> Expr db r a
logBase' :: (FloatingSqlDb db, ExpressionOf db r b a, ExpressionOf db r x a, Floating a) => b -> x -> Expr db r a

-- | Returns escaped table name optionally qualified with schema
tableName :: StringLike s => (s -> s) -> EntityDef -> ConstructorDef -> s

-- | Returns escaped main table name optionally qualified with schema
mainTableName :: StringLike s => (s -> s) -> EntityDef -> s
instance GHC.Base.Semigroup (Database.Groundhog.Generic.Sql.RenderS db r)
instance GHC.Base.Monoid (Database.Groundhog.Generic.Sql.RenderS db r)
instance Data.String.IsString (Database.Groundhog.Generic.Sql.RenderS db r)
instance Database.Groundhog.Generic.Sql.StringLike (Database.Groundhog.Generic.Sql.RenderS db r)
instance Database.Groundhog.Generic.Sql.StringLike Database.Groundhog.Core.Utf8
instance Database.Groundhog.Generic.Sql.StringLike GHC.Base.String
instance GHC.Base.Semigroup Database.Groundhog.Core.Utf8
instance GHC.Base.Monoid Database.Groundhog.Core.Utf8
instance Data.String.IsString Database.Groundhog.Core.Utf8


-- | This module has common SQL functions and operators which are supported
--   in the most SQL databases
module Database.Groundhog.Generic.Sql.Functions
like :: (SqlDb db, ExpressionOf db r a a', IsString a') => a -> String -> Cond db r
notLike :: (SqlDb db, ExpressionOf db r a a', IsString a') => a -> String -> Cond db r
in_ :: (SqlDb db, Expression db r a, Expression db r b, PrimitivePersistField b, Unifiable a b) => a -> [b] -> Cond db r
notIn_ :: (SqlDb db, Expression db r a, Expression db r b, PrimitivePersistField b, Unifiable a b) => a -> [b] -> Cond db r
lower :: (SqlDb db, ExpressionOf db r a a', IsString a') => a -> Expr db r a'
upper :: (SqlDb db, ExpressionOf db r a a', IsString a') => a -> Expr db r a'
case_ :: (SqlDb db, ExpressionOf db r a a', ExpressionOf db r b a') => [(Cond db r, a)] -> b -> Expr db r a'

-- | This class distinguishes databases which support SQL-specific
--   expressions. It contains ad hoc members for features whose syntax
--   differs across the databases.
class (DbDescriptor db, QueryRaw db ~ Snippet db) => SqlDb db
append :: (SqlDb db, ExpressionOf db r a String, ExpressionOf db r b String) => a -> b -> Expr db r String
signum' :: (SqlDb db, ExpressionOf db r x a, Num a) => x -> Expr db r a
quotRem' :: (SqlDb db, ExpressionOf db r x a, ExpressionOf db r y a, Integral a) => x -> y -> (Expr db r a, Expr db r a)
equalsOperator :: SqlDb db => RenderS db r -> RenderS db r -> RenderS db r
notEqualsOperator :: SqlDb db => RenderS db r -> RenderS db r -> RenderS db r
cot :: (FloatingSqlDb db, ExpressionOf db r a a', Floating a') => a -> Expr db r a'

-- | a version of arctangent taking two real floating-point arguments. For
--   real floating <tt>x</tt> and <tt>y</tt>, <tt><a>atan2</a> y x</tt>
--   computes the angle (from the positive x-axis) of the vector from the
--   origin to the point <tt>(x,y)</tt>. <tt><a>atan2</a> y x</tt> returns
--   a value in the range [<tt>-pi</tt>, <tt>pi</tt>]. It follows the
--   Common Lisp semantics for the origin when signed zeroes are supported.
--   <tt><a>atan2</a> y 1</tt>, with <tt>y</tt> in a type that is
--   <a>RealFloat</a>, should return the same value as <tt><a>atan</a>
--   y</tt>. A default definition of <a>atan2</a> is provided, but
--   implementors can provide a more accurate implementation.
atan2 :: RealFloat a => a -> a -> a
radians :: (FloatingSqlDb db, ExpressionOf db r a a', Floating a') => a -> Expr db r a'
degrees :: (FloatingSqlDb db, ExpressionOf db r a a', Floating a') => a -> Expr db r a'
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PersistField a, GHC.Num.Num a) => GHC.Num.Num (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PersistField a, GHC.Real.Fractional a) => GHC.Real.Fractional (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.FloatingSqlDb db, Database.Groundhog.Core.PersistField a, GHC.Float.Floating a) => GHC.Float.Floating (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PersistField a, GHC.Classes.Ord a) => GHC.Classes.Ord (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PersistField a, GHC.Real.Real a) => GHC.Real.Real (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PersistField a, GHC.Enum.Enum a) => GHC.Enum.Enum (Database.Groundhog.Core.Expr db r a)
instance (Database.Groundhog.Generic.Sql.SqlDb db, Database.Groundhog.Core.PurePersistField a, GHC.Real.Integral a) => GHC.Real.Integral (Database.Groundhog.Core.Expr db r a)


-- | This helper module contains generic versions of PersistBackend
--   functions
module Database.Groundhog.Generic.PersistBackendHelpers
get :: forall conn v. (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Key v BackendSpecific -> Action conn (Maybe v)
select :: forall conn r v c opts. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c, HasSelectOptions opts conn r) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> (opts -> RenderS conn r) -> Utf8 -> opts -> Action conn [v]
selectAll :: forall conn v. (PersistBackendConn conn, PersistEntity v) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Action conn [(AutoKey v, v)]
selectStream :: forall conn r v c opts. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c, HasSelectOptions opts conn r) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> (opts -> RenderS conn r) -> Utf8 -> opts -> Action conn (RowStream v)

-- | It may call the passed function multiple times
selectAllStream :: forall conn v. (PersistBackendConn conn, PersistEntity v) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Action conn (RowStream (AutoKey v, v))
getBy :: forall conn v u. (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u))) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Key v (Unique u) -> Action conn (Maybe v)
project :: forall conn r v c p opts a'. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c, Projection p a', ProjectionDb p conn, ProjectionRestriction p r, HasSelectOptions opts conn r) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> (opts -> RenderS conn r) -> Utf8 -> p -> opts -> Action conn [a']
projectStream :: forall conn r v c p opts a'. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c, Projection p a', ProjectionDb p conn, ProjectionRestriction p r, HasSelectOptions opts conn r) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> (opts -> RenderS conn r) -> Utf8 -> p -> opts -> Action conn (RowStream a')
count :: forall conn r v c. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Cond conn r -> Action conn Int
replace :: forall conn r v. (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> (Utf8 -> [PersistValue] -> Action conn ()) -> (Bool -> Utf8 -> ConstructorDef -> [PersistValue] -> RenderS conn r) -> Key v BackendSpecific -> v -> Action conn ()
replaceBy :: forall conn v u. (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u))) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn ()) -> u (UniqueMarker v) -> v -> Action conn ()
update :: forall conn r v c. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn ()) -> [Update conn r] -> Cond conn r -> Action conn ()
delete :: forall conn r v c. (SqlDb conn, r ~ RestrictionHolder v c, PersistBackendConn conn, PersistEntity v, EntityConstr v c) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn ()) -> Cond conn r -> Action conn ()
deleteBy :: forall conn v. (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn ()) -> Key v BackendSpecific -> Action conn ()
deleteAll :: forall conn v. (PersistBackendConn conn, PersistEntity v) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn ()) -> v -> Action conn ()
insertByAll :: forall conn v. (PersistBackendConn conn, PersistEntity v) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Bool -> v -> Action conn (Either (AutoKey v) (AutoKey v))
countAll :: forall conn v. (PersistBackendConn conn, PersistEntity v) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> v -> Action conn Int
insertBy :: forall conn v u. (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u))) => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Bool -> u (UniqueMarker v) -> v -> Action conn (Either (AutoKey v) (AutoKey v))


-- | This helper module is intended for use by the backend creators
module Database.Groundhog.Generic.Migration
data Column
Column :: String -> Bool -> DbTypePrimitive -> Maybe String -> Column
[colName] :: Column -> String
[colNull] :: Column -> Bool
[colType] :: Column -> DbTypePrimitive
[colDefault] :: Column -> Maybe String
data Reference
Reference :: QualifiedName -> [(String, String)] -> Maybe ReferenceActionType -> Maybe ReferenceActionType -> Reference
[referencedTableName] :: Reference -> QualifiedName

-- | child column, parent column
[referencedColumns] :: Reference -> [(String, String)]
[referenceOnDelete] :: Reference -> Maybe ReferenceActionType
[referenceOnUpdate] :: Reference -> Maybe ReferenceActionType

-- | Schema-qualified name of a table of another database object
type QualifiedName = (Maybe String, String)
data TableInfo
TableInfo :: [Column] -> [UniqueDefInfo] -> [(Maybe String, Reference)] -> TableInfo
[tableColumns] :: TableInfo -> [Column]
[tableUniques] :: TableInfo -> [UniqueDefInfo]

-- | constraint name and reference
[tableReferences] :: TableInfo -> [(Maybe String, Reference)]

-- | Either column name or expression
type UniqueDefInfo = UniqueDef' String (Either String String)
data AlterColumn
Type :: DbTypePrimitive -> AlterColumn
IsNull :: AlterColumn
NotNull :: AlterColumn
Default :: String -> AlterColumn
NoDefault :: AlterColumn
UpdateValue :: String -> AlterColumn
data AlterTable
AddUnique :: UniqueDefInfo -> AlterTable
DropConstraint :: String -> AlterTable
DropIndex :: String -> AlterTable
AddReference :: Reference -> AlterTable
DropReference :: String -> AlterTable
DropColumn :: String -> AlterTable
AddColumn :: Column -> AlterTable
AlterColumn :: Column -> [AlterColumn] -> AlterTable
data AlterDB
AddTable :: String -> AlterDB

-- | Qualified table name, create statement, structure of table from DB,
--   structure of table from datatype, alters
AlterTable :: QualifiedName -> String -> TableInfo -> TableInfo -> [AlterTable] -> AlterDB

-- | Qualified trigger name, qualified table name
DropTrigger :: QualifiedName -> QualifiedName -> AlterDB

-- | Qualified trigger name, qualified table name, body
AddTriggerOnDelete :: QualifiedName -> QualifiedName -> String -> AlterDB

-- | Qualified trigger name, qualified table name, field name, body
AddTriggerOnUpdate :: QualifiedName -> QualifiedName -> Maybe String -> String -> AlterDB

-- | Statement which creates the function
CreateOrReplaceFunction :: String -> AlterDB

-- | Qualified function name
DropFunction :: QualifiedName -> AlterDB

-- | Schema name, if not exists
CreateSchema :: String -> Bool -> AlterDB
data MigrationPack conn
MigrationPack :: (DbTypePrimitive -> DbTypePrimitive -> Bool) -> ((Maybe String, Reference) -> (Maybe String, Reference) -> Bool) -> (UniqueDefInfo -> UniqueDefInfo -> Bool) -> (String -> String -> Bool) -> (QualifiedName -> [(String, String)] -> Action conn (Bool, [AlterDB])) -> (QualifiedName -> [(String, String)] -> Action conn [(Bool, [AlterDB])]) -> (EntityDef -> ConstructorDef -> Action conn (Bool, SingleMigration)) -> (String -> String) -> String -> String -> Int -> ([UniqueDefInfo] -> [Reference] -> ([String], [AlterTable])) -> (DbTypePrimitive -> String) -> (Column -> String) -> (AlterDB -> SingleMigration) -> ReferenceActionType -> ReferenceActionType -> MigrationPack conn
[compareTypes] :: MigrationPack conn -> DbTypePrimitive -> DbTypePrimitive -> Bool
[compareRefs] :: MigrationPack conn -> (Maybe String, Reference) -> (Maybe String, Reference) -> Bool
[compareUniqs] :: MigrationPack conn -> UniqueDefInfo -> UniqueDefInfo -> Bool
[compareDefaults] :: MigrationPack conn -> String -> String -> Bool
[migTriggerOnDelete] :: MigrationPack conn -> QualifiedName -> [(String, String)] -> Action conn (Bool, [AlterDB])
[migTriggerOnUpdate] :: MigrationPack conn -> QualifiedName -> [(String, String)] -> Action conn [(Bool, [AlterDB])]
[migConstr] :: MigrationPack conn -> EntityDef -> ConstructorDef -> Action conn (Bool, SingleMigration)
[escape] :: MigrationPack conn -> String -> String
[autoincrementedKeyTypeName] :: MigrationPack conn -> String
[mainTableId] :: MigrationPack conn -> String
[defaultPriority] :: MigrationPack conn -> Int

-- | Sql pieces for the create table statement that add constraints and
--   alterations for running after the table is created
[addUniquesReferences] :: MigrationPack conn -> [UniqueDefInfo] -> [Reference] -> ([String], [AlterTable])
[showSqlType] :: MigrationPack conn -> DbTypePrimitive -> String
[showColumn] :: MigrationPack conn -> Column -> String
[showAlterDb] :: MigrationPack conn -> AlterDB -> SingleMigration
[defaultReferenceOnDelete] :: MigrationPack conn -> ReferenceActionType
[defaultReferenceOnUpdate] :: MigrationPack conn -> ReferenceActionType
class PersistBackendConn conn => SchemaAnalyzer conn
schemaExists :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => String -> m Bool
getCurrentSchema :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => m (Maybe String)
listTables :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => Maybe String -> m [String]
listTableTriggers :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => QualifiedName -> m [String]
analyzeTable :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => QualifiedName -> m (Maybe TableInfo)
analyzeTrigger :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => QualifiedName -> m (Maybe String)
analyzeFunction :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => QualifiedName -> m (Maybe (Maybe [DbTypePrimitive], Maybe DbTypePrimitive, String))
getMigrationPack :: (SchemaAnalyzer conn, PersistBackend m, Conn m ~ conn) => m (MigrationPack conn)

-- | Create migration for a given entity and all entities it depends on.
--   The stateful Map is used to avoid duplicate migrations when an entity
--   type occurs several times in a datatype
migrateRecursively :: (PersistBackend m, PersistEntity v) => (String -> m SingleMigration) -> (EntityDef -> m SingleMigration) -> (DbType -> m SingleMigration) -> v -> Migration m
migrateSchema :: SchemaAnalyzer conn => MigrationPack conn -> String -> Action conn SingleMigration
migrateEntity :: (SchemaAnalyzer conn, PersistBackendConn conn) => MigrationPack conn -> EntityDef -> Action conn SingleMigration
migrateList :: (SchemaAnalyzer conn, PersistBackendConn conn) => MigrationPack conn -> DbType -> Action conn SingleMigration
getAlters :: MigrationPack m -> TableInfo -> TableInfo -> [AlterTable]
defaultMigConstr :: (SchemaAnalyzer conn, PersistBackendConn conn) => MigrationPack conn -> EntityDef -> ConstructorDef -> Action conn (Bool, SingleMigration)
showReferenceAction :: ReferenceActionType -> String
readReferenceAction :: String -> Maybe ReferenceActionType
instance GHC.Show.Show Database.Groundhog.Generic.Migration.AlterDB
instance GHC.Show.Show Database.Groundhog.Generic.Migration.AlterTable
instance GHC.Show.Show Database.Groundhog.Generic.Migration.AlterColumn
instance GHC.Show.Show Database.Groundhog.Generic.Migration.TableInfo
instance GHC.Show.Show Database.Groundhog.Generic.Migration.Reference
instance GHC.Show.Show Database.Groundhog.Generic.Migration.Column
instance GHC.Classes.Eq Database.Groundhog.Generic.Migration.Column


-- | This module exports the most commonly used functions and datatypes.
--   
--   See <a>http://github.com/lykahb/groundhog/blob/master/examples/</a>.
module Database.Groundhog

-- | This class helps to shorten the type signatures of user monadic code.
--   If your monad has several connections, e.g., for main and audit
--   databases, create run*Db function runAuditDb :: Action conn a -&gt; m
--   a
class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {
    type family Conn m;
}
getConnection :: PersistBackend m => m (Conn m)
class (DbDescriptor conn, ConnectionManager conn) => PersistBackendConn conn

-- | Insert a new record to a database and return its autogenerated key or
--   ()
insert :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (AutoKey v)

-- | Insert a new record to a database. For some backends it may be faster
--   than <a>insert</a>.
insert_ :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()

-- | Try to insert a record and return Right newkey. If there is a
--   constraint violation for the given constraint, Left oldkey is returned
--   , where oldkey is an identifier of the record with the matching
--   values.
insertBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m (Either (AutoKey v) (AutoKey v))

-- | Try to insert a record and return Right newkey. If there is a
--   constraint violation for any constraint, Left oldkey is returned ,
--   where oldkey is an identifier of the record with the matching values.
--   Note that if several constraints are violated, a key of an arbitrary
--   matching record is returned.
insertByAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (Either (AutoKey v) (AutoKey v))

-- | Replace a record with the given autogenerated key. Result is undefined
--   if the record does not exist.
replace :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> v -> m ()

-- | Replace a record. The unique key marker defines what unique key of the
--   entity is used.
replaceBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m ()

-- | Return a list of the records satisfying the condition. Example:
--   <tt>select $ (FirstField ==. "abc" &amp;&amp;. SecondField &gt;.
--   "def") `orderBy` [Asc ThirdField] `limitTo` 100</tt>
select :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => opts -> m [v]

-- | Return a list of all records. Order is undefined. It can be useful for
--   datatypes with multiple constructors.
selectAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => m [(AutoKey v, v)]

-- | Fetch an entity from a database
get :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m (Maybe v)

-- | Fetch an entity from a database by its unique key
getBy :: (PersistBackendConn conn, PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => Key v (Unique u) -> m (Maybe v)

-- | Update the records satisfying the condition. Example: <tt>update
--   [FirstField =. "abc"] $ FirstField ==. "def"</tt>
update :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => [Update conn (RestrictionHolder v c)] -> Cond conn (RestrictionHolder v c) -> m ()

-- | Remove the records satisfying the condition
delete :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m ()

-- | Remove the record with given key. No-op if the record does not exist
deleteBy :: (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m ()

-- | Remove all records. The entity parameter is used only for type
--   inference.
deleteAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()

-- | Count total number of records satisfying the condition
count :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m Int

-- | Count total number of records with all constructors. The entity
--   parameter is used only for type inference
countAll :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m Int

-- | Fetch projection of some fields. Example: <tt>project (SecondField,
--   ThirdField) $ (FirstField ==. "abc" &amp;&amp;. SecondField &gt;.
--   "def") `orderBy` [Asc ThirdField] `offsetBy` 100</tt>
project :: (PersistBackendConn conn, PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => p -> opts -> m [a]

-- | Check database schema and create migrations for the entity and the
--   entities it contains
migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m

-- | Execute raw query
executeRaw :: (PersistBackendConn conn, PersistBackend m, Conn m ~ conn) => Bool -> String -> [PersistValue] -> m ()

-- | Execute raw query with results
queryRaw :: (PersistBackendConn conn, PersistBackend m, Conn m ~ conn) => Bool -> String -> [PersistValue] -> m (RowStream [PersistValue])
insertList :: (PersistBackendConn conn, PersistField a, PersistBackend m, Conn m ~ conn) => [a] -> m Int64
getList :: (PersistBackendConn conn, PersistField a, PersistBackend m, Conn m ~ conn) => Int64 -> m [a]

-- | A unique identifier of a value stored in a database. This may be a
--   primary key, a constraint or unique indices. The second parameter is
--   the key description.
data family Key v :: * -> *

-- | This type is the default key for the entity.
type family DefaultKey v

-- | This type is the default autoincremented key for the entity. If entity
--   does not have such key, AutoKey v = ().
type family AutoKey v

-- | A holder for Unique constraints
data Unique (u :: (* -> *) -> *)

-- | A phantom datatype to make instance head different <tt>u (UniqueMarker
--   v)</tt>
data UniqueMarker v a

-- | Key marked with this type can have value for any backend
data BackendSpecific

-- | Creates value of unique key using the data extracted from the passed
--   value
extractUnique :: (IsUniqueKey uKey, uKey ~ Key v u) => v -> uKey

-- | Represents condition for a query.
data Cond db r
And :: Cond db r -> Cond db r -> Cond db r
Or :: Cond db r -> Cond db r -> Cond db r
Not :: Cond db r -> Cond db r
Compare :: ExprRelation -> UntypedExpr db r -> UntypedExpr db r -> Cond db r
CondRaw :: QueryRaw db r -> Cond db r
CondEmpty :: Cond db r

-- | Defines sort order of a result-set
data Order db r
Asc :: f -> Order db r
Desc :: f -> Order db r
data family Selector v :: * -> *

-- | It can be used in expressions like a regular field. For example,
--   <tt>delete (AutoKeyField ==. k)</tt> or <tt>delete (AutoKeyField ==. k
--   ||. SomeField ==. "DUPLICATE")</tt>
data AutoKeyField v (c :: (* -> *) -> *)
[AutoKeyField] :: AutoKeyField v c

-- | Accesses fields of the embedded datatypes. For example, <tt>SomeField
--   ==. ("abc", "def") ||. SomeField ~&gt; Tuple2_0Selector ==. "def"</tt>
(~>) :: (EntityConstr v c, FieldLike f a, DbDescriptor db, Projection' f db (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField db v c a'
infixl 5 ~>
limitTo :: (HasSelectOptions a db r, HasLimit a ~ HFalse) => a -> Int -> SelectOptions db r HTrue (HasOffset a) (HasOrder a) (HasDistinct a)
offsetBy :: (HasSelectOptions a db r, HasOffset a ~ HFalse) => a -> Int -> SelectOptions db r (HasLimit a) HTrue (HasOrder a) (HasDistinct a)
orderBy :: (HasSelectOptions a db r, HasOrder a ~ HFalse) => a -> [Order db r] -> SelectOptions db r (HasLimit a) (HasOffset a) HTrue (HasDistinct a)

-- | <i>Deprecated: Use deleteBy instead</i>
deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()

-- | Update field
(=.) :: (Assignable f a', ProjectionDb f db, ProjectionRestriction f r, Expression db r b, Unifiable f b) => f -> b -> Update db r
infixr 3 =.

-- | Boolean "and" operator.
(&&.) :: Cond db r -> Cond db r -> Cond db r
infixr 3 &&.

-- | Boolean "or" operator.
(||.) :: Cond db r -> Cond db r -> Cond db r
infixr 2 ||.
(==.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 ==.
(/=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 /=.
(<.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 <.
(<=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 <=.
(>.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 >.
(>=.) :: (Expression db r a, Expression db r b, Unifiable a b) => a -> b -> Cond db r
infix 4 >=.

-- | This function more limited than (==.), but has better type inference.
--   If you want to compare your value to Nothing with <tt>(==.)</tt>
--   operator, you have to write the types explicitly <tt>myExpr ==.
--   (Nothing :: Maybe Int)</tt>. TODO: restrict db r
isFieldNothing :: (Expression db r f, Projection f (Maybe a), PrimitivePersistField (Maybe a), Unifiable f (Maybe a)) => f -> Cond db r

-- | Converts value to <a>Expr</a>. It can help to pass values of different
--   types into functions which expect arguments of the same type, like
--   (+).
liftExpr :: ExpressionOf db r a a' => a -> Expr db r a'

-- | It is kept for compatibility with older Groundhog versions and can be
--   replaced with "liftExpr".

-- | <i>Deprecated: Please use liftExpr instead</i>
toArith :: ExpressionOf db r a a' => a -> Expr db r a'

-- | Produce the migrations but not execute them. Fails when an unsafe
--   migration occurs.
createMigration :: Monad m => Migration m -> m NamedMigrations

-- | Execute the migrations with printing to stderr. Fails when an unsafe
--   migration occurs.
executeMigration :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()

-- | Execute migrations. Executes the unsafe migrations without warnings
--   and prints them to stderr
executeMigrationUnsafe :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()

-- | Creates migrations and executes them with printing to stderr. Fails
--   when an unsafe migration occurs. &gt; runMigration m = createMigration
--   m &gt;&gt;= executeMigration
runMigration :: (PersistBackend m, MonadIO m) => Migration m -> m ()

-- | Creates migrations and executes them with printing to stderr. Executes
--   the unsafe migrations without warnings &gt; runMigrationUnsafe m =
--   createMigration m &gt;&gt;= executeMigrationUnsafe
runMigrationUnsafe :: (PersistBackend m, MonadIO m) => Migration m -> m ()

-- | Pretty print the migrations
printMigration :: MonadIO m => NamedMigrations -> m ()
