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

-- | Bare bones, type-safe EDSL for SQL queries on persistent backends.
--   
--   persistent is a library for type-safe data serialization. It
--   has many kinds of backends, such as SQL backends
--   (persistent-mysql, persistent-postgresql,
--   persistent-sqlite) and NoSQL backends
--   (persistent-mongoDB).
--   
--   While persistent is a nice library for storing and retrieving
--   records, currently it has a poor interface for SQL backends compared
--   to SQL itself. For example, it's extremely hard to do a type-safe
--   JOIN on a many-to-one relation, and simply impossible to do
--   any other kinds of JOINs (including for the very common
--   many-to-many relations). Users have the option of writing raw SQL, but
--   that's error prone and not type-checked.
--   
--   esqueleto is a bare bones, type-safe EDSL for SQL queries
--   that works with unmodified persistent SQL backends. Its
--   language closely resembles SQL, so (a) you don't have to learn new
--   concepts, just new syntax, and (b) it's fairly easy to predict the
--   generated SQL and optimize it for your backend. Most kinds of errors
--   committed when writing SQL are caught as compile-time
--   errors---although it is possible to write type-checked
--   esqueleto queries that fail at runtime.
--   
--   Currently, SELECTs, UPDATEs, INSERTs and
--   DELETEs are supported. Not all SQL features are available,
--   but most of them can be easily added (especially functions), so please
--   open an issue or send a pull request if you need anything that is not
--   covered by esqueleto on
--   https://github.com/meteficha/esqueleto/.
--   
--   The name of this library means "skeleton" in Portuguese and contains
--   all three SQL letters in the correct order =). It was inspired by
--   Scala's Squeryl but created from scratch.
@package esqueleto
@version 1.3.4.2

-- | This is an internal module, anything exported by this module may
--   change without a major version bump. Please use only
--   Database.Esqueleto if possible.
module Database.Esqueleto.Internal.Language

-- | Finally tagless representation of esqueleto's EDSL.
class (Functor query, Applicative query, Monad query) => Esqueleto query expr backend | query -> expr backend, expr -> query backend
fromStart :: (Esqueleto query expr backend, PersistEntity a, PersistEntityBackend a ~ backend) => query (expr (PreprocessedFrom (expr (Entity a))))
fromStartMaybe :: (Esqueleto query expr backend, PersistEntity a, PersistEntityBackend a ~ backend) => query (expr (PreprocessedFrom (expr (Maybe (Entity a)))))
fromJoin :: (Esqueleto query expr backend, IsJoinKind join) => expr (PreprocessedFrom a) -> expr (PreprocessedFrom b) -> query (expr (PreprocessedFrom (join a b)))
fromFinish :: Esqueleto query expr backend => expr (PreprocessedFrom a) -> query a
where_ :: Esqueleto query expr backend => expr (Value Bool) -> query ()
on :: Esqueleto query expr backend => expr (Value Bool) -> query ()
groupBy :: (Esqueleto query expr backend, ToSomeValues expr a) => a -> query ()
orderBy :: Esqueleto query expr backend => [expr OrderBy] -> query ()
asc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy
desc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy
limit :: Esqueleto query expr backend => Int64 -> query ()
offset :: Esqueleto query expr backend => Int64 -> query ()
having :: Esqueleto query expr backend => expr (Value Bool) -> query ()
sub_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)
sub_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)
(^.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Entity val) -> EntityField val typ -> expr (Value typ)
(?.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Maybe (Entity val)) -> EntityField val typ -> expr (Value (Maybe typ))
val :: (Esqueleto query expr backend, PersistField typ) => typ -> expr (Value typ)
isNothing :: (Esqueleto query expr backend, PersistField typ) => expr (Value (Maybe typ)) -> expr (Value Bool)
just :: Esqueleto query expr backend => expr (Value typ) -> expr (Value (Maybe typ))
nothing :: Esqueleto query expr backend => expr (Value (Maybe typ))
joinV :: Esqueleto query expr backend => expr (Value (Maybe (Maybe typ))) -> expr (Value (Maybe typ))
countRows :: (Esqueleto query expr backend, Num a) => expr (Value a)
count :: (Esqueleto query expr backend, Num a) => expr (Value typ) -> expr (Value a)
not_ :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool)
(==.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(>=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(>.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(<=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(<.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(!=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(&&.) :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool) -> expr (Value Bool)
(||.) :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool) -> expr (Value Bool)
(+.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(-.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(/.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(*.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
random_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a)
round_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
ceiling_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
floor_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
sum_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
min_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
max_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
avg_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b))
like :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)
(%) :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s)
concat_ :: (Esqueleto query expr backend, PersistField s, IsString s) => [expr (Value s)] -> expr (Value s)
(++.) :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value s)
subList_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)
subList_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)
valList :: (Esqueleto query expr backend, PersistField typ) => [typ] -> expr (ValueList typ)
in_ :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)
notIn :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)
exists :: Esqueleto query expr backend => query () -> expr (Value Bool)
notExists :: Esqueleto query expr backend => query () -> expr (Value Bool)
set :: (Esqueleto query expr backend, PersistEntity val) => expr (Entity val) -> [expr (Update val)] -> query ()
(=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => EntityField val typ -> expr (Value typ) -> expr (Update val)
(+=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(-=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(*=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(/=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(<#) :: Esqueleto query expr backend => (a -> b) -> expr (Value a) -> expr (Insertion b)
(<&>) :: Esqueleto query expr backend => expr (Insertion (a -> b)) -> expr (Value a) -> expr (Insertion b)

-- | FROM clause: bring entities into scope.
--   
--   This function internally uses two type classes in order to provide
--   some flexibility of how you may call it. Internally we refer to these
--   type classes as the two different magics.
--   
--   The innermost magic allows you to use from with the following
--   types:
--   
--   
--   
- expr (Entity val), which brings a single entity into
--   scope.
--   
- expr (Maybe (Entity val)), which brings a single entity
--   that may be NULL into scope. Used for OUTER
--   JOINs.
--   
- A JOIN of any other two types allowed by the innermost
--   magic, where a JOIN may be an InnerJoin, a
--   CrossJoin, a LeftOuterJoin, a RightOuterJoin, or
--   a FullOuterJoin. The JOINs have right fixity, the same
--   as in SQL.
--   
--   
--   The outermost magic allows you to use from on any tuples of
--   types supported by innermost magic (and also tuples of tuples, and so
--   on), up to 8-tuples.
--   
--   Note that using from for the same entity twice does work and
--   corresponds to a self-join. You don't even need to use two different
--   calls to from, you may use a JOIN or a tuple.
--   
--   The following are valid examples of uses of from (the types
--   of the arguments of the lambda are inside square brackets):
--   
--   
--   from $ \person -> ...
--   from $ \(person, blogPost) -> ...
--   from $ \(p `<a>LeftOuterJoin</a>` mb) -> ...
--   from $ \(p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2) -> ...
--   from $ \((p1 `<a>InnerJoin</a>` f) `<a>InnerJoin</a>` p2) -> ...
--   
--   
--   The types of the arguments to the lambdas above are, respectively:
--   
--   
--   person
--     :: ( Esqueleto query expr backend
--        , PersistEntity Person
--        , PersistEntityBackend Person ~ backend
--        ) => expr (Entity Person)
--   (person, blogPost)
--     :: (...) => (expr (Entity Person), expr (Entity BlogPost))
--   (p `<a>LeftOuterJoin</a>` mb)
--     :: (...) => InnerJoin (expr (Entity Person)) (expr (Maybe (Entity BlogPost)))
--   (p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2)
--     :: (...) => InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   ((p1 `<a>InnerJoin</a>` f) `<a>InnerJoin</a>` p2) ::
--     :: (...) => InnerJoin
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   
--   
--   Note that some backends may not support all kinds of JOINs.
--   For example, when using the SQL backend with SQLite, it will not
--   accept the last example above (which is associated to the left,
--   instead of being to the right) and will not accept
--   RightOuterJoins or FullOuterJoins.
from :: From query expr backend a => (a -> query b) -> query b

-- | A single value (as opposed to a whole entity). You may use
--   (^.) or (?.) to get a Value
--   from an Entity.
data Value a
Value :: a -> Value a

-- | A list of single values. There's a limited set of funcitons able to
--   work with this data type (such as subList_select,
--   valList, in_ and exists).
data ValueList a
ValueList :: a -> ValueList a

-- | A wrapper type for for any expr (Value a) for all a.
data SomeValue expr
SomeValue :: expr (Value a) -> SomeValue expr

-- | A class of things that can be converted into a list of SomeValue. It
--   has instances for tuples and is the reason why groupBy can take
--   tuples, like groupBy (foo ^. FooId, foo ^. FooName, foo ^.
--   FooType).
class ToSomeValues expr a
toSomeValues :: ToSomeValues expr a => a -> [SomeValue expr]

-- | Data type that represents an INNER JOIN (see
--   LeftOuterJoin for an example).
data InnerJoin a b
InnerJoin :: a -> b -> InnerJoin a b

-- | Data type that represents a CROSS JOIN (see
--   LeftOuterJoin for an example).
data CrossJoin a b
CrossJoin :: a -> b -> CrossJoin a b

-- | Data type that represents a LEFT OUTER JOIN. For example,
--   
--   
--   select $
--   from $ \(person `<a>LeftOuterJoin</a>` pet) ->
--     ...
--   
--   
--   is translated into
--   
--   
--   SELECT ...
--   FROM Person LEFT OUTER JOIN Pet
--   ...
--   
--   
--   See also: from.
data LeftOuterJoin a b
LeftOuterJoin :: a -> b -> LeftOuterJoin a b

-- | Data type that represents a RIGHT OUTER JOIN (see
--   LeftOuterJoin for an example).
data RightOuterJoin a b
RightOuterJoin :: a -> b -> RightOuterJoin a b

-- | Data type that represents a FULL OUTER JOIN (see
--   LeftOuterJoin for an example).
data FullOuterJoin a b
FullOuterJoin :: a -> b -> FullOuterJoin a b

-- | Exception thrown whenever on is used to create an ON
--   clause but no matching JOIN is found.
data OnClauseWithoutMatchingJoinException
OnClauseWithoutMatchingJoinException :: String -> OnClauseWithoutMatchingJoinException

-- | Phantom type used by orderBy, asc and desc.
data OrderBy

-- | Phantom type for a SET operation on an entity of the given
--   type (see set and '(=.)').
data Update typ

-- | Phantom type used by insertSelect.
data Insertion a

-- | (Internal) A kind of JOIN.
data JoinKind

-- | 
--   INNER JOIN
--   
InnerJoinKind :: JoinKind

-- | 
--   CROSS JOIN
--   
CrossJoinKind :: JoinKind

-- | 
--   LEFT OUTER JOIN
--   
LeftOuterJoinKind :: JoinKind

-- | 
--   RIGHT OUTER JOIN
--   
RightOuterJoinKind :: JoinKind

-- | 
--   FULL OUTER JOIN
--   
FullOuterJoinKind :: JoinKind

-- | (Internal) Functions that operate on types (that should be) of kind
--   JoinKind.
class IsJoinKind join
smartJoin :: IsJoinKind join => a -> b -> join a b
reifyJoinKind :: IsJoinKind join => join a b -> JoinKind

-- | (Internal) Phantom type used to process from (see
--   fromStart).
data PreprocessedFrom a

-- | (Internal) Class that implements the tuple from magic (see
--   fromStart).
class Esqueleto query expr backend => From query expr backend a

-- | (Internal) Class that implements the JOIN from magic
--   (see fromStart).
class Esqueleto query expr backend => FromPreprocess query expr backend a
instance Typeable1 Value
instance Typeable1 ValueList
instance Typeable OnClauseWithoutMatchingJoinException
instance Eq a => Eq (Value a)
instance Ord a => Ord (Value a)
instance Show a => Show (Value a)
instance Eq a => Eq (ValueList a)
instance Ord a => Ord (ValueList a)
instance Show a => Show (ValueList a)
instance Eq OnClauseWithoutMatchingJoinException
instance Ord OnClauseWithoutMatchingJoinException
instance Show OnClauseWithoutMatchingJoinException
instance (Esqueleto query expr backend, FromPreprocess query expr backend a, FromPreprocess query expr backend b, IsJoinKind join) => FromPreprocess query expr backend (join a b)
instance (Esqueleto query expr backend, PersistEntity val, PersistEntityBackend val ~ backend) => FromPreprocess query expr backend (expr (Maybe (Entity val)))
instance (Esqueleto query expr backend, PersistEntity val, PersistEntityBackend val ~ backend) => FromPreprocess query expr backend (expr (Entity val))
instance (From query expr backend a, From query expr backend b, From query expr backend c, From query expr backend d, From query expr backend e, From query expr backend f, From query expr backend g, From query expr backend h) => From query expr backend (a, b, c, d, e, f, g, h)
instance (From query expr backend a, From query expr backend b, From query expr backend c, From query expr backend d, From query expr backend e, From query expr backend f, From query expr backend g) => From query expr backend (a, b, c, d, e, f, g)
instance (From query expr backend a, From query expr backend b, From query expr backend c, From query expr backend d, From query expr backend e, From query expr backend f) => From query expr backend (a, b, c, d, e, f)
instance (From query expr backend a, From query expr backend b, From query expr backend c, From query expr backend d, From query expr backend e) => From query expr backend (a, b, c, d, e)
instance (From query expr backend a, From query expr backend b, From query expr backend c, From query expr backend d) => From query expr backend (a, b, c, d)
instance (From query expr backend a, From query expr backend b, From query expr backend c) => From query expr backend (a, b, c)
instance (From query expr backend a, From query expr backend b) => From query expr backend (a, b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (FullOuterJoin a b)) => From query expr backend (FullOuterJoin a b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (RightOuterJoin a b)) => From query expr backend (RightOuterJoin a b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (LeftOuterJoin a b)) => From query expr backend (LeftOuterJoin a b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (CrossJoin a b)) => From query expr backend (CrossJoin a b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (InnerJoin a b)) => From query expr backend (InnerJoin a b)
instance (Esqueleto query expr backend, FromPreprocess query expr backend (expr (Maybe (Entity val)))) => From query expr backend (expr (Maybe (Entity val)))
instance (Esqueleto query expr backend, FromPreprocess query expr backend (expr (Entity val))) => From query expr backend (expr (Entity val))
instance Exception OnClauseWithoutMatchingJoinException
instance IsJoinKind FullOuterJoin
instance IsJoinKind RightOuterJoin
instance IsJoinKind LeftOuterJoin
instance IsJoinKind CrossJoin
instance IsJoinKind InnerJoin
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c, ToSomeValues expr d, ToSomeValues expr e, ToSomeValues expr f, ToSomeValues expr g, ToSomeValues expr h) => ToSomeValues expr (a, b, c, d, e, f, g, h)
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c, ToSomeValues expr d, ToSomeValues expr e, ToSomeValues expr f, ToSomeValues expr g) => ToSomeValues expr (a, b, c, d, e, f, g)
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c, ToSomeValues expr d, ToSomeValues expr e, ToSomeValues expr f) => ToSomeValues expr (a, b, c, d, e, f)
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c, ToSomeValues expr d, ToSomeValues expr e) => ToSomeValues expr (a, b, c, d, e)
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c, ToSomeValues expr d) => ToSomeValues expr (a, b, c, d)
instance (ToSomeValues expr a, ToSomeValues expr b, ToSomeValues expr c) => ToSomeValues expr (a, b, c)
instance (ToSomeValues expr a, ToSomeValues expr b) => ToSomeValues expr (a, b)

-- | This is an internal module, anything exported by this module may
--   change without a major version bump. Please use only
--   Database.Esqueleto if possible.
module Database.Esqueleto.Internal.Sql

-- | SQL backend for esqueleto using SqlPersistT.
data SqlQuery a

-- | An expression on the SQL backend.
data SqlExpr a

-- | Constraint synonym for persistent entities whose backend is
--   SqlPersistT.
type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.
--   
--   We've seen that from has some magic about which kinds of things
--   you may bring into scope. This select function also has some
--   magic for which kinds of things you may bring back to Haskell-land by
--   using SqlQuery's return:
--   
--   
--   
- You may return a SqlExpr (Entity v) for an entity
--   v (i.e., like the * in SQL), which is then returned
--   to Haskell-land as just Entity v.
--   
- You may return a SqlExpr (Maybe (Entity v)) for an entity
--   v that may be NULL, which is then returned to
--   Haskell-land as Maybe (Entity v). Used for OUTER
--   JOINs.
--   
- You may return a SqlExpr (Value t) for a value
--   t (i.e., a single column), where t is any instance
--   of PersistField, which is then returned to Haskell-land as
--   Value t. You may use Value to return projections of
--   an Entity (see (^.) and (?.))
--   or to return any other value calculated on the query (e.g.,
--   countRows or sub_select).
--   
--   
--   The SqlSelect a r class has functional dependencies that
--   allow type information to flow both from a to r and
--   vice-versa. This means that you'll almost never have to give any type
--   signatures for esqueleto queries. For example, the query
--   select $ from $ \p -> return p alone is ambiguous, but in
--   the context of
--   
--   
--   do ps <- select $
--            from $ \p ->
--            return p
--      liftIO $ mapM_ (putStrLn . personName . entityVal) ps
--   
--   
--   we are able to infer from that single personName . entityVal
--   function composition that the p inside the query is of type
--   SqlExpr (Entity Person).
select :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m [r]

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectSource :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m (Source (ResourceT (SqlPersistT m)) r)

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.
selectDistinct :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m [r]

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectDistinctSource :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m (Source (ResourceT (SqlPersistT m)) r)

-- | Execute an esqueleto DELETE query inside
--   persistent's SqlPersistT monad. Note that currently
--   there are no type checks for statements that should not appear on a
--   DELETE query.
--   
--   Example of usage:
--   
--   
--   delete $
--   from $ \appointment ->
--   where_ (appointment ^. AppointmentDate <. val now)
--   
--   
--   Unlike select, there is a useful way of using delete
--   that will lead to type ambiguities. If you want to delete all rows
--   (i.e., no where_ clause), you'll have to use a type signature:
--   
--   
--   delete $
--   from $ \(appointment :: SqlExpr (Entity Appointment)) ->
--   return ()
--   
delete :: (MonadLogger m, MonadResourceBase m) => SqlQuery () -> SqlPersistT m ()

-- | Same as delete, but returns the number of rows affected.
deleteCount :: (MonadLogger m, MonadResourceBase m) => SqlQuery () -> SqlPersistT m Int64

-- | Execute an esqueleto UPDATE query inside
--   persistent's SqlPersistT monad. Note that currently
--   there are no type checks for statements that should not appear on a
--   UPDATE query.
--   
--   Example of usage:
--   
--   
--   update $ p -> do
--   set p [ PersonAge =. just (val thisYear) -. p ^. PersonBorn ]
--   where_ $ isNull (p ^. PersonAge)
--   
update :: (MonadLogger m, MonadResourceBase m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlPersistT m ()

-- | Same as update, but returns the number of rows affected.
updateCount :: (MonadLogger m, MonadResourceBase m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlPersistT m Int64

-- | Insert a PersistField for every unique selected value.
insertSelectDistinct :: (MonadLogger m, MonadResourceBase m, SqlSelect (SqlExpr (Insertion a)) r, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m ()

-- | Insert a PersistField for every selected value.
insertSelect :: (MonadLogger m, MonadResourceBase m, SqlSelect (SqlExpr (Insertion a)) r, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m ()

-- | (Internal) Create a custom binary operator. You should
--   not use this function directly since its type is very general,
--   you should always use it with an explicit type signature. For example:
--   
--   
--   (==.) :: SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value Bool)
--   (==.) = unsafeSqlBinOp  = 
--   
--   
--   In the example above, we constraint the arguments to be of the same
--   type and constraint the result to be a boolean value.
unsafeSqlBinOp :: Builder -> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)

-- | (Internal) A raw SQL value. The same warning from
--   unsafeSqlBinOp applies to this function as well.
unsafeSqlValue :: Builder -> SqlExpr (Value a)

-- | (Internal) A raw SQL function. Once again, the same warning from
--   unsafeSqlBinOp applies to this function as well.
unsafeSqlFunction :: UnsafeSqlFunctionArgument a => Builder -> a -> SqlExpr (Value b)
class UnsafeSqlFunctionArgument a

-- | (Internal) Execute an esqueleto SELECT
--   SqlQuery inside persistent's SqlPersistT monad.
rawSelectSource :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => Mode -> SqlQuery a -> SqlPersistT m (Source (ResourceT (SqlPersistT m)) r)

-- | (Internal) Run a Source of rows.
runSource :: MonadResourceBase m => Source (ResourceT (SqlPersistT m)) r -> SqlPersistT m [r]

-- | (Internal) Execute an esqueleto statement inside
--   persistent's SqlPersistT monad.
rawEsqueleto :: (MonadLogger m, MonadResourceBase m) => Mode -> SqlQuery () -> SqlPersistT m Int64

-- | (Internal) Pretty prints a SqlQuery into a SQL query.
--   
--   Note: if you're curious about the SQL query being generated by
--   esqueleto, instead of manually using this function (which is
--   possible but tedious), you may just turn on query logging of
--   persistent.
toRawSql :: SqlSelect a r => Mode -> QueryType a -> IdentInfo -> SqlQuery a -> (Builder, [PersistValue])

-- | (Internal) Mode of query being converted by toRawSql.
data Mode
SELECT :: Mode
SELECT_DISTINCT :: Mode
DELETE :: Mode
UPDATE :: Mode

-- | List of identifiers already in use and supply of temporary
--   identifiers.
data IdentState
initialIdentState :: IdentState

-- | Information needed to escape and use identifiers.
type IdentInfo = (Connection, IdentState)

-- | (Internal) Class for mapping results coming from SqlQuery into
--   actual results.
--   
--   This looks very similar to RawSql, and it is! However, there
--   are some crucial differences and ultimately they're different classes.
class SqlSelect a r | a -> r, r -> a

-- | (Internal) Coerce a value's type from 'SqlExpr (Value a)' to 'SqlExpr
--   (Value b)'. You should not use this function unless you know
--   what you're doing!
veryUnsafeCoerceSqlExprValue :: SqlExpr (Value a) -> SqlExpr (Value b)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk, SqlSelect l rl, SqlSelect m rm, SqlSelect n rn, SqlSelect o ro, SqlSelect p rp) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk, SqlSelect l rl, SqlSelect m rm, SqlSelect n rn, SqlSelect o ro) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk, SqlSelect l rl, SqlSelect m rm, SqlSelect n rn) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk, SqlSelect l rl, SqlSelect m rm) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk, SqlSelect l rl) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj, SqlSelect k rk) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri, SqlSelect j rj) => SqlSelect (a, b, c, d, e, f, g, h, i, j) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh, SqlSelect i ri) => SqlSelect (a, b, c, d, e, f, g, h, i) (ra, rb, rc, rd, re, rf, rg, rh, ri)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg, SqlSelect h rh) => SqlSelect (a, b, c, d, e, f, g, h) (ra, rb, rc, rd, re, rf, rg, rh)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf, SqlSelect g rg) => SqlSelect (a, b, c, d, e, f, g) (ra, rb, rc, rd, re, rf, rg)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re, SqlSelect f rf) => SqlSelect (a, b, c, d, e, f) (ra, rb, rc, rd, re, rf)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd, SqlSelect e re) => SqlSelect (a, b, c, d, e) (ra, rb, rc, rd, re)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc, SqlSelect d rd) => SqlSelect (a, b, c, d) (ra, rb, rc, rd)
instance (SqlSelect a ra, SqlSelect b rb, SqlSelect c rc) => SqlSelect (a, b, c) (ra, rb, rc)
instance (SqlSelect a ra, SqlSelect b rb) => SqlSelect (a, b) (ra, rb)
instance PersistField a => SqlSelect (SqlExpr (Value a)) (Value a)
instance PersistEntity a => SqlSelect (SqlExpr (Maybe (Entity a))) (Maybe (Entity a))
instance PersistEntity a => SqlSelect (SqlExpr (Entity a)) (Entity a)
instance SqlSelect () ()
instance PersistEntity a => SqlSelect (SqlExpr (Insertion a)) (Insertion a)
instance (UnsafeSqlFunctionArgument a, UnsafeSqlFunctionArgument b, UnsafeSqlFunctionArgument c, UnsafeSqlFunctionArgument d) => UnsafeSqlFunctionArgument (a, b, c, d)
instance (UnsafeSqlFunctionArgument a, UnsafeSqlFunctionArgument b, UnsafeSqlFunctionArgument c) => UnsafeSqlFunctionArgument (a, b, c)
instance (UnsafeSqlFunctionArgument a, UnsafeSqlFunctionArgument b) => UnsafeSqlFunctionArgument (a, b)
instance UnsafeSqlFunctionArgument a => UnsafeSqlFunctionArgument [a]
instance a ~ Value b => UnsafeSqlFunctionArgument (SqlExpr a)
instance ToSomeValues SqlExpr (SqlExpr (Value a))
instance Esqueleto SqlQuery SqlExpr SqlBackend
instance Monoid LimitClause
instance Monoid GroupByClause
instance Monoid WhereClause
instance Monoid SideData
instance Applicative SqlQuery
instance Monad SqlQuery
instance Functor SqlQuery

-- | The esqueleto EDSL (embedded domain specific language). This
--   module replaces Database.Persist, so instead of importing
--   that module you should just import this one:
--   
--   
--   -- For a module using just esqueleto.
--   import Database.Esqueleto
--   
--   
--   If you need to use persistent's default support for queries
--   as well, either import it qualified:
--   
--   
--   -- For a module that mostly uses esqueleto.
--   import Database.Esqueleto
--   import qualified Database.Persistent as P
--   
--   
--   or import esqueleto itself qualified:
--   
--   
--   -- For a module uses esqueleto just on some queries.
--   import Database.Persistent
--   import qualified Database.Esqueleto as E
--   
--   
--   Other than identifier name clashes, esqueleto does not
--   conflict with persistent in any way.
module Database.Esqueleto

-- | Finally tagless representation of esqueleto's EDSL.
class (Functor query, Applicative query, Monad query) => Esqueleto query expr backend | query -> expr backend, expr -> query backend
where_ :: Esqueleto query expr backend => expr (Value Bool) -> query ()
on :: Esqueleto query expr backend => expr (Value Bool) -> query ()
groupBy :: (Esqueleto query expr backend, ToSomeValues expr a) => a -> query ()
orderBy :: Esqueleto query expr backend => [expr OrderBy] -> query ()
asc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy
desc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy
limit :: Esqueleto query expr backend => Int64 -> query ()
offset :: Esqueleto query expr backend => Int64 -> query ()
having :: Esqueleto query expr backend => expr (Value Bool) -> query ()
sub_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)
sub_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)
(^.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Entity val) -> EntityField val typ -> expr (Value typ)
(?.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Maybe (Entity val)) -> EntityField val typ -> expr (Value (Maybe typ))
val :: (Esqueleto query expr backend, PersistField typ) => typ -> expr (Value typ)
isNothing :: (Esqueleto query expr backend, PersistField typ) => expr (Value (Maybe typ)) -> expr (Value Bool)
just :: Esqueleto query expr backend => expr (Value typ) -> expr (Value (Maybe typ))
nothing :: Esqueleto query expr backend => expr (Value (Maybe typ))
joinV :: Esqueleto query expr backend => expr (Value (Maybe (Maybe typ))) -> expr (Value (Maybe typ))
countRows :: (Esqueleto query expr backend, Num a) => expr (Value a)
count :: (Esqueleto query expr backend, Num a) => expr (Value typ) -> expr (Value a)
not_ :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool)
(==.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(>=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(>.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(<=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(<.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(!=.) :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (Value typ) -> expr (Value Bool)
(&&.) :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool) -> expr (Value Bool)
(||.) :: Esqueleto query expr backend => expr (Value Bool) -> expr (Value Bool) -> expr (Value Bool)
(+.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(-.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(/.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
(*.) :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value a) -> expr (Value a)
random_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a)
round_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
ceiling_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
floor_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value b)
sum_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
min_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
max_ :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr (Value (Maybe a))
avg_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b))
like :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)
(%) :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s)
concat_ :: (Esqueleto query expr backend, PersistField s, IsString s) => [expr (Value s)] -> expr (Value s)
(++.) :: (Esqueleto query expr backend, PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value s)
subList_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)
subList_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)
valList :: (Esqueleto query expr backend, PersistField typ) => [typ] -> expr (ValueList typ)
in_ :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)
notIn :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)
exists :: Esqueleto query expr backend => query () -> expr (Value Bool)
notExists :: Esqueleto query expr backend => query () -> expr (Value Bool)
set :: (Esqueleto query expr backend, PersistEntity val) => expr (Entity val) -> [expr (Update val)] -> query ()
(=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => EntityField val typ -> expr (Value typ) -> expr (Update val)
(+=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(-=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(*=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(/=.) :: (Esqueleto query expr backend, PersistEntity val, PersistField a) => EntityField val a -> expr (Value a) -> expr (Update val)
(<#) :: Esqueleto query expr backend => (a -> b) -> expr (Value a) -> expr (Insertion b)
(<&>) :: Esqueleto query expr backend => expr (Insertion (a -> b)) -> expr (Value a) -> expr (Insertion b)

-- | FROM clause: bring entities into scope.
--   
--   This function internally uses two type classes in order to provide
--   some flexibility of how you may call it. Internally we refer to these
--   type classes as the two different magics.
--   
--   The innermost magic allows you to use from with the following
--   types:
--   
--   
--   
- expr (Entity val), which brings a single entity into
--   scope.
--   
- expr (Maybe (Entity val)), which brings a single entity
--   that may be NULL into scope. Used for OUTER
--   JOINs.
--   
- A JOIN of any other two types allowed by the innermost
--   magic, where a JOIN may be an InnerJoin, a
--   CrossJoin, a LeftOuterJoin, a RightOuterJoin, or
--   a FullOuterJoin. The JOINs have right fixity, the same
--   as in SQL.
--   
--   
--   The outermost magic allows you to use from on any tuples of
--   types supported by innermost magic (and also tuples of tuples, and so
--   on), up to 8-tuples.
--   
--   Note that using from for the same entity twice does work and
--   corresponds to a self-join. You don't even need to use two different
--   calls to from, you may use a JOIN or a tuple.
--   
--   The following are valid examples of uses of from (the types
--   of the arguments of the lambda are inside square brackets):
--   
--   
--   from $ \person -> ...
--   from $ \(person, blogPost) -> ...
--   from $ \(p `<a>LeftOuterJoin</a>` mb) -> ...
--   from $ \(p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2) -> ...
--   from $ \((p1 `<a>InnerJoin</a>` f) `<a>InnerJoin</a>` p2) -> ...
--   
--   
--   The types of the arguments to the lambdas above are, respectively:
--   
--   
--   person
--     :: ( Esqueleto query expr backend
--        , PersistEntity Person
--        , PersistEntityBackend Person ~ backend
--        ) => expr (Entity Person)
--   (person, blogPost)
--     :: (...) => (expr (Entity Person), expr (Entity BlogPost))
--   (p `<a>LeftOuterJoin</a>` mb)
--     :: (...) => InnerJoin (expr (Entity Person)) (expr (Maybe (Entity BlogPost)))
--   (p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2)
--     :: (...) => InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   ((p1 `<a>InnerJoin</a>` f) `<a>InnerJoin</a>` p2) ::
--     :: (...) => InnerJoin
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   
--   
--   Note that some backends may not support all kinds of JOINs.
--   For example, when using the SQL backend with SQLite, it will not
--   accept the last example above (which is associated to the left,
--   instead of being to the right) and will not accept
--   RightOuterJoins or FullOuterJoins.
from :: From query expr backend a => (a -> query b) -> query b

-- | A single value (as opposed to a whole entity). You may use
--   (^.) or (?.) to get a Value
--   from an Entity.
data Value a
Value :: a -> Value a

-- | A list of single values. There's a limited set of funcitons able to
--   work with this data type (such as subList_select,
--   valList, in_ and exists).
data ValueList a
ValueList :: a -> ValueList a

-- | Phantom type used by orderBy, asc and desc.
data OrderBy

-- | Data type that represents an INNER JOIN (see
--   LeftOuterJoin for an example).
data InnerJoin a b
InnerJoin :: a -> b -> InnerJoin a b

-- | Data type that represents a CROSS JOIN (see
--   LeftOuterJoin for an example).
data CrossJoin a b
CrossJoin :: a -> b -> CrossJoin a b

-- | Data type that represents a LEFT OUTER JOIN. For example,
--   
--   
--   select $
--   from $ \(person `<a>LeftOuterJoin</a>` pet) ->
--     ...
--   
--   
--   is translated into
--   
--   
--   SELECT ...
--   FROM Person LEFT OUTER JOIN Pet
--   ...
--   
--   
--   See also: from.
data LeftOuterJoin a b
LeftOuterJoin :: a -> b -> LeftOuterJoin a b

-- | Data type that represents a RIGHT OUTER JOIN (see
--   LeftOuterJoin for an example).
data RightOuterJoin a b
RightOuterJoin :: a -> b -> RightOuterJoin a b

-- | Data type that represents a FULL OUTER JOIN (see
--   LeftOuterJoin for an example).
data FullOuterJoin a b
FullOuterJoin :: a -> b -> FullOuterJoin a b

-- | Exception thrown whenever on is used to create an ON
--   clause but no matching JOIN is found.
data OnClauseWithoutMatchingJoinException
OnClauseWithoutMatchingJoinException :: String -> OnClauseWithoutMatchingJoinException

-- | SQL backend for esqueleto using SqlPersistT.
data SqlQuery a

-- | An expression on the SQL backend.
data SqlExpr a

-- | Constraint synonym for persistent entities whose backend is
--   SqlPersistT.
type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.
--   
--   We've seen that from has some magic about which kinds of things
--   you may bring into scope. This select function also has some
--   magic for which kinds of things you may bring back to Haskell-land by
--   using SqlQuery's return:
--   
--   
--   
- You may return a SqlExpr (Entity v) for an entity
--   v (i.e., like the * in SQL), which is then returned
--   to Haskell-land as just Entity v.
--   
- You may return a SqlExpr (Maybe (Entity v)) for an entity
--   v that may be NULL, which is then returned to
--   Haskell-land as Maybe (Entity v). Used for OUTER
--   JOINs.
--   
- You may return a SqlExpr (Value t) for a value
--   t (i.e., a single column), where t is any instance
--   of PersistField, which is then returned to Haskell-land as
--   Value t. You may use Value to return projections of
--   an Entity (see (^.) and (?.))
--   or to return any other value calculated on the query (e.g.,
--   countRows or sub_select).
--   
--   
--   The SqlSelect a r class has functional dependencies that
--   allow type information to flow both from a to r and
--   vice-versa. This means that you'll almost never have to give any type
--   signatures for esqueleto queries. For example, the query
--   select $ from $ \p -> return p alone is ambiguous, but in
--   the context of
--   
--   
--   do ps <- select $
--            from $ \p ->
--            return p
--      liftIO $ mapM_ (putStrLn . personName . entityVal) ps
--   
--   
--   we are able to infer from that single personName . entityVal
--   function composition that the p inside the query is of type
--   SqlExpr (Entity Person).
select :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m [r]

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.
selectDistinct :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m [r]

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectSource :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m (Source (ResourceT (SqlPersistT m)) r)

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectDistinctSource :: (SqlSelect a r, MonadLogger m, MonadResourceBase m) => SqlQuery a -> SqlPersistT m (Source (ResourceT (SqlPersistT m)) r)

-- | Execute an esqueleto DELETE query inside
--   persistent's SqlPersistT monad. Note that currently
--   there are no type checks for statements that should not appear on a
--   DELETE query.
--   
--   Example of usage:
--   
--   
--   delete $
--   from $ \appointment ->
--   where_ (appointment ^. AppointmentDate <. val now)
--   
--   
--   Unlike select, there is a useful way of using delete
--   that will lead to type ambiguities. If you want to delete all rows
--   (i.e., no where_ clause), you'll have to use a type signature:
--   
--   
--   delete $
--   from $ \(appointment :: SqlExpr (Entity Appointment)) ->
--   return ()
--   
delete :: (MonadLogger m, MonadResourceBase m) => SqlQuery () -> SqlPersistT m ()

-- | Same as delete, but returns the number of rows affected.
deleteCount :: (MonadLogger m, MonadResourceBase m) => SqlQuery () -> SqlPersistT m Int64

-- | Execute an esqueleto UPDATE query inside
--   persistent's SqlPersistT monad. Note that currently
--   there are no type checks for statements that should not appear on a
--   UPDATE query.
--   
--   Example of usage:
--   
--   
--   update $ p -> do
--   set p [ PersonAge =. just (val thisYear) -. p ^. PersonBorn ]
--   where_ $ isNull (p ^. PersonAge)
--   
update :: (MonadLogger m, MonadResourceBase m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlPersistT m ()

-- | Same as update, but returns the number of rows affected.
updateCount :: (MonadLogger m, MonadResourceBase m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlPersistT m Int64

-- | Insert a PersistField for every selected value.
insertSelect :: (MonadLogger m, MonadResourceBase m, SqlSelect (SqlExpr (Insertion a)) r, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m ()

-- | Insert a PersistField for every unique selected value.
insertSelectDistinct :: (MonadLogger m, MonadResourceBase m, SqlSelect (SqlExpr (Insertion a)) r, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlPersistT m ()

-- | valkey i = val (Key (PersistInt64 i))
--   (https://github.com/meteficha/esqueleto/issues/9).
valkey :: Esqueleto query expr backend => Int64 -> expr (Value (Key entity))

-- | Synonym for delete that does not clash with
--   esqueleto's delete.
deleteKey :: (PersistStore m, PersistMonadBackend m ~ PersistEntityBackend val, PersistEntity val) => Key val -> m ()
