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

-- | Type-safe EDSL for SQL queries on persistent backends.
--   
--   esqueleto is a bare bones, type-safe EDSL for SQL queries
--   that works with unmodified persistent SQL backends. Its
--   language closely resembles SQL, so you don't have to learn new
--   concepts, just new syntax, and 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.
--   
--   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, including with filters, it
--   does not try to support some of the features that are specific to SQL
--   backends. In particular, esqueleto is the recommended library
--   for type-safe JOINs on persistent SQL backends. (The
--   alternative is using raw SQL, but that's error prone and does not
--   offer any composability.)
--   
--   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/bitemyapp/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 2.5.3

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

-- | (Internal) Start a from query with an entity. from does
--   two kinds of magic using fromStart, fromJoin and
--   fromFinish:
--   
--   
--   
- The simple but tedious magic of allowing tuples to be used.
--   
- The more advanced magic of creating JOINs. The
--   JOIN is processed from right to left. The rightmost entity of
--   the JOIN is created with fromStart. Each JOIN
--   step is then translated into a call to fromJoin. In the end,
--   fromFinish is called to materialize the JOIN.
--   
fromStart :: (Esqueleto query expr backend, PersistEntity a, PersistEntityBackend a ~ backend) => query (expr (PreprocessedFrom (expr (Entity a))))

-- | (Internal) Same as fromStart, but entity may be missing.
fromStartMaybe :: (Esqueleto query expr backend, PersistEntity a, PersistEntityBackend a ~ backend) => query (expr (PreprocessedFrom (expr (Maybe (Entity a)))))

-- | (Internal) Do a JOIN.
fromJoin :: (Esqueleto query expr backend, IsJoinKind join) => expr (PreprocessedFrom a) -> expr (PreprocessedFrom b) -> query (expr (PreprocessedFrom (join a b)))

-- | (Internal) Finish a JOIN.
fromFinish :: Esqueleto query expr backend => expr (PreprocessedFrom a) -> query a

-- | WHERE clause: restrict the query's result.
where_ :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | ON clause: restrict the a JOIN's result. The
--   ON clause will be applied to the last JOIN
--   that does not have an ON clause yet. If there are no
--   JOINs without ON clauses (either because you didn't
--   do any JOIN, or because all JOINs already have their
--   own ON clauses), a runtime exception
--   OnClauseWithoutMatchingJoinException is thrown. ON
--   clauses are optional when doing JOINs.
--   
--   On the simple case of doing just one JOIN, for example
--   
--   
--   select $
--   from $ \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooId ==. bar ^. BarFooId)
--     ...
--   
--   
--   there's no ambiguity and the rules above just mean that you're allowed
--   to call on only once (as in SQL). If you have many joins, then
--   the ons are applied on the reverse order that the
--   JOINs appear. For example:
--   
--   
--   select $
--   from $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -> do
--     on (baz ^. BazId ==. bar ^. BarBazId)
--     on (foo ^. FooId ==. bar ^. BarFooId)
--     ...
--   
--   
--   The order is reversed in order to improve composability. For
--   example, consider query1 and query2 below:
--   
--   
--   let query1 =
--         from $ \(foo `<a>InnerJoin</a>` bar) -> do
--           on (foo ^. FooId ==. bar ^. BarFooId)
--       query2 =
--         from $ \(mbaz `<a>LeftOuterJoin</a>` quux) -> do
--           return (mbaz ?. BazName, quux)
--       test1 =      (,) <$> query1 <*> query2
--       test2 = flip (,) <$> query2 <*> query1
--   
--   
--   If the order was not reversed, then test2 would be
--   broken: query1's on would refer to query2's
--   LeftOuterJoin.
on :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | GROUP BY clause. You can enclose multiple columns in a tuple.
--   
--   
--   select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy (bar ^. BarId, bar ^. BarName)
--     return (bar ^. BarId, bar ^. BarName, countRows)
--   
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   let to restrict the more general countRows to
--   SqlExpr (Value Int) to avoid ambiguity---the second use of
--   countRows has its type restricted by the :: Int
--   below):
--   
--   
--   r <- select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy $ bar ^. BarName
--     let countRows' = countRows
--     orderBy [asc countRows']
--     return (bar ^. BarName, countRows')
--   forM_ r $ \(Value name, Value count) -> do
--     print name
--     print (count :: Int)
--   
groupBy :: (Esqueleto query expr backend, ToSomeValues expr a) => a -> query ()

-- | ORDER BY clause. See also asc and desc.
--   
--   Multiple calls to orderBy get concatenated on the final query,
--   including distinctOnOrderBy.
orderBy :: Esqueleto query expr backend => [expr OrderBy] -> query ()

-- | Ascending order of this field or expression.
asc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy

-- | Descending order of this field or expression.
desc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy

-- | LIMIT. Limit the number of returned rows.
limit :: Esqueleto query expr backend => Int64 -> query ()

-- | OFFSET. Usually used with limit.
offset :: Esqueleto query expr backend => Int64 -> query ()

-- | DISTINCT. Change the current SELECT into SELECT
--   DISTINCT. For example:
--   
--   
--   select $ distinct $
--     from \foo -> do
--     ...
--   
--   
--   Note that this also has the same effect:
--   
--   
--   select $
--     from \foo -> do
--     distinct (return ())
--     ...
--   
--   
--   Since: 2.2.4
distinct :: Esqueleto query expr backend => query a -> query a

-- | DISTINCT ON. Change the current SELECT into
--   SELECT DISTINCT ON (expressions). For example:
--   
--   
--   select $
--     from \foo ->
--     distinctOn [don (foo ^. FooName), don (foo ^. FooState)] $ do
--     ...
--   
--   
--   You can also chain different calls to distinctOn. The above is
--   equivalent to:
--   
--   
--   select $
--     from \foo ->
--     distinctOn [don (foo ^. FooName)] $
--     distinctOn [don (foo ^. FooState)] $ do
--     ...
--   
--   
--   Each call to distinctOn adds more expressions. Calls to
--   distinctOn override any calls to distinct.
--   
--   Note that PostgreSQL requires the expressions on DISTINCT ON
--   to be the first ones to appear on a ORDER BY. This is not
--   managed automatically by esqueleto, keeping its spirit of trying to be
--   close to raw SQL.
--   
--   Supported by PostgreSQL only.
--   
--   Since: 2.2.4
distinctOn :: Esqueleto query expr backend => [expr DistinctOn] -> query a -> query a

-- | Erase an expression's type so that it's suitable to be used by
--   distinctOn.
--   
--   Since: 2.2.4
don :: Esqueleto query expr backend => expr (Value a) -> expr DistinctOn

-- | A convenience function that calls both distinctOn and
--   orderBy. In other words,
--   
--   
--   distinctOnOrderBy [asc foo, desc bar, desc quux] $ do
--     ...
--   
--   
--   is the same as:
--   
--   
--   distinctOn [don foo, don  bar, don  quux] $ do
--     orderBy  [asc foo, desc bar, desc quux]
--     ...
--   
--   
--   Since: 2.2.4
distinctOnOrderBy :: Esqueleto query expr backend => [expr OrderBy] -> query a -> query a

-- | ORDER BY random() clause.
--   
--   Since: 1.3.10
rand :: Esqueleto query expr backend => expr OrderBy

-- | HAVING.
--   
--   Since: 1.2.2
having :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | Add a locking clause to the query. Please read LockingKind
--   documentation and your RDBMS manual.
--   
--   If multiple calls to locking are made on the same query, the
--   last one is used.
--   
--   Since: 2.2.7
locking :: Esqueleto query expr backend => LockingKind -> query ()

-- | Execute a subquery SELECT in an expression. Returns a simple
--   value so should be used only when the SELECT query is
--   guaranteed to return just one row.
sub_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)

-- | Same as sub_select but using SELECT DISTINCT.

-- | Deprecated: Since 2.2.4: use sub_select and
--   distinct.
sub_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)

-- | Project a field of an entity.
(^.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Entity val) -> EntityField val typ -> expr (Value typ)

-- | Project a field of an entity that may be null.
(?.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Maybe (Entity val)) -> EntityField val typ -> expr (Value (Maybe typ))

-- | Lift a constant value from Haskell-land to the query.
val :: (Esqueleto query expr backend, PersistField typ) => typ -> expr (Value typ)

-- | IS NULL comparison.
isNothing :: (Esqueleto query expr backend, PersistField typ) => expr (Value (Maybe typ)) -> expr (Value Bool)

-- | Analogous to Just, promotes a value of type typ into
--   one of type Maybe typ. It should hold that val .
--   Just === just . val.
just :: Esqueleto query expr backend => expr (Value typ) -> expr (Value (Maybe typ))

-- | NULL value.
nothing :: Esqueleto query expr backend => expr (Value (Maybe typ))

-- | Join nested Maybes in a Value into one. This is useful
--   when calling aggregate functions on nullable fields.
joinV :: Esqueleto query expr backend => expr (Value (Maybe (Maybe typ))) -> expr (Value (Maybe typ))

-- | COUNT(*) value.
countRows :: (Esqueleto query expr backend, Num a) => expr (Value a)

-- | COUNT.
count :: (Esqueleto query expr backend, Num a) => expr (Value typ) -> expr (Value a)

-- | COUNT(DISTINCT x).
--   
--   Since: 2.4.1
countDistinct :: (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, Num a) => expr (Value a)
round_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
ceiling_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
floor_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
sum_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b))
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))

-- | Allow a number of one type to be used as one of another type via an
--   implicit cast. An explicit cast is not made, this function changes
--   only the types on the Haskell side.
--   
--   Caveat: Trying to use castNum from Double to
--   Int will not result in an integer, the original fractional
--   number will still be used! Use round_, ceiling_ or
--   floor_ instead.
--   
--   Safety: This operation is mostly safe due to the Num
--   constraint between the types and the fact that RDBMSs usually allow
--   numbers of different types to be used interchangeably. However, there
--   may still be issues with the query not being accepted by the RDBMS or
--   persistent not being able to parse it.
--   
--   Since: 2.2.9
castNum :: (Esqueleto query expr backend, Num a, Num b) => expr (Value a) -> expr (Value b)

-- | Same as castNum, but for nullable values.
--   
--   Since: 2.2.9
castNumM :: (Esqueleto query expr backend, Num a, Num b) => expr (Value (Maybe a)) -> expr (Value (Maybe b))

-- | COALESCE function. Evaluates the arguments in order and
--   returns the value of the first non-NULL expression, or NULL (Nothing)
--   otherwise. Some RDBMSs (such as SQLite) require at least two
--   arguments; please refer to the appropriate documentation.
--   
--   Since: 1.4.3
coalesce :: (Esqueleto query expr backend, PersistField a) => [expr (Value (Maybe a))] -> expr (Value (Maybe a))

-- | Like coalesce, but takes a non-nullable expression placed at
--   the end of the expression list, which guarantees a non-NULL result.
--   
--   Since: 1.4.3
coalesceDefault :: (Esqueleto query expr backend, PersistField a) => [expr (Value (Maybe a))] -> expr (Value a) -> expr (Value a)

-- | LOWER function.
lower_ :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s)

-- | LIKE operator.
like :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)

-- | ILIKE operator (case-insensitive LIKE).
--   
--   Supported by PostgreSQL only.
--   
--   Since: 2.2.3
ilike :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)

-- | The string %. May be useful while using like
--   and concatenation (concat_ or ++., depending on your
--   database). Note that you always have to type the parenthesis, for
--   example:
--   
--   
--   name `<a>like</a>` (%) ++. val "John" ++. (%)
--   
(%) :: (Esqueleto query expr backend, SqlString s) => expr (Value s)

-- | The CONCAT function with a variable number of parameters.
--   Supported by MySQL and PostgreSQL.
concat_ :: (Esqueleto query expr backend, SqlString s) => [expr (Value s)] -> expr (Value s)

-- | The || string concatenation operator (named after Haskell's
--   ++ in order to avoid naming clash with ||.). Supported
--   by SQLite and PostgreSQL.
(++.) :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value s)

-- | Cast a string type into Text. This function is very useful if
--   you want to use newtypes, or if you want to apply functions
--   such as like to strings of different types.
--   
--   Safety: This is a slightly unsafe function, especially if you
--   have defined your own instances of SqlString. Also, since
--   Maybe is an instance of SqlString, it's possible to turn
--   a nullable value into a non-nullable one. Avoid using this function if
--   possible.
castString :: (Esqueleto query expr backend, SqlString s, SqlString r) => expr (Value s) -> expr (Value r)

-- | Execute a subquery SELECT in an expression. Returns a list of
--   values.
subList_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)

-- | Same as sublist_select but using SELECT DISTINCT.

-- | Deprecated: Since 2.2.4: use subList_select and
--   distinct.
subList_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)

-- | Lift a list of constant value from Haskell-land to the query.
valList :: (Esqueleto query expr backend, PersistField typ) => [typ] -> expr (ValueList typ)

-- | Same as just but for ValueList. Most of the time you
--   won't need it, though, because you can use just from inside
--   subList_select or Just from inside valList.
--   
--   Since: 2.2.12
justList :: Esqueleto query expr backend => expr (ValueList typ) -> expr (ValueList (Maybe typ))

-- | IN operator. For example if you want to select all
--   Persons by a list of IDs:
--   
--   
--   SELECT *
--   FROM Person
--   WHERE Person.id IN (?)
--   
--   
--   In esqueleto, we may write the same query above as:
--   
--   
--   select $
--   from $ \person -> do
--   where_ $ person ^. PersonId `<a>in_</a>` valList personIds
--   return person
--   
--   
--   Where personIds is of type [Key Person].
in_ :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)

-- | NOT IN operator.
notIn :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)

-- | EXISTS operator. For example:
--   
--   
--   select $
--   from $ \person -> do
--   where_ $ exists $
--            from $ \post -> do
--            where_ (post ^. BlogPostAuthorId ==. person ^. PersonId)
--   return person
--   
exists :: Esqueleto query expr backend => query () -> expr (Value Bool)

-- | NOT EXISTS operator.
notExists :: Esqueleto query expr backend => query () -> expr (Value Bool)

-- | SET clause used on UPDATEs. Note that while it's not
--   a type error to use this function on a SELECT, it will most
--   certainly result in a runtime error.
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)

-- | Apply a PersistField constructor to expr Value
--   arguments.
(<#) :: Esqueleto query expr backend => (a -> b) -> expr (Value a) -> expr (Insertion b)

-- | Apply extra expr Value arguments to a PersistField
--   constructor
(<&>) :: Esqueleto query expr backend => expr (Insertion (a -> b)) -> expr (Value a) -> expr (Insertion b)

-- | CASE statement. For example:
--   
--   
--   select $
--   return $
--   case_
--      [ when_
--          (exists $
--          from $ \p -> do
--          where_ (p ^. PersonName ==. val "Mike"))
--        then_
--          (sub_select $
--          from $ \v -> do
--          let sub =
--                  from $ \c -> do
--                  where_ (c ^. PersonName ==. val "Mike")
--                  return (c ^. PersonFavNum)
--          where_ (v ^. PersonFavNum >. sub_select sub)
--          return $ count (v ^. PersonName) +. val (1 :: Int)) ]
--      (else_ $ val (-1))
--   
--   
--   This query is a bit complicated, but basically it checks if a person
--   named "Mike" exists, and if that person does, run the
--   subquery to find out how many people have a ranking (by Fav Num)
--   higher than "Mike".
--   
--   NOTE: There are a few things to be aware about this statement.
--   
--   
--   
- This only implements the full CASE statement, it does not
--   implement the "simple" CASE statement.
--   
- At least one when_ and then_ is mandatory otherwise
--   it will emit an error.
--   
- The else_ is also mandatory, unlike the SQL statement in
--   which if the ELSE is omitted it will return a NULL.
--   You can reproduce this via nothing.
--   
--   
--   Since: 2.1.2
case_ :: (Esqueleto query expr backend, PersistField a) => [(expr (Value Bool), expr (Value a))] -> expr (Value a) -> expr (Value a)

-- | Convert an entity's key into another entity's.
--   
--   This function is to be used when you change an entity's Id to
--   be that of another entity. For example:
--   
--   
--   Bar
--     barNum Int
--   Foo
--     Id BarId
--     fooNum Int
--   
--   
--   For this example, declare:
--   
--   
--   instance ToBaseId Foo where
--     type BaseEnt Foo = Bar
--     toBaseIdWitness = FooKey
--   
--   
--   Now you're able to write queries such as:
--   
--   
--   select $
--   from $ (bar `<a>InnerJoin</a>` foo) -> do
--   on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
--   return (bar, foo)
--   
--   
--   Note: this function may be unsafe to use in conditions not like the
--   one of the example above.
--   
--   Since: 2.4.3
toBaseId :: (Esqueleto query expr backend, ToBaseId ent) => expr (Value (Key ent)) -> expr (Value (Key (BaseEnt ent)))

-- | 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 left fixity.
--   
--   
--   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
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   (p1 `<a>InnerJoin</a>` (f `<a>InnerJoin</a>` p2)) ::
--     :: (...) => InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   
--   
--   Note that some backends may not support all kinds of JOINs.
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

-- | Unwrap a Value.
--   
--   Since: 1.4.1
unValue :: Value a -> a

-- | A list of single values. There's a limited set of functions 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] :: Esqueleto query expr backend => 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 used by distinctOn and don.
data DistinctOn

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

-- | Different kinds of locking clauses supported by locking.
--   
--   Note that each RDBMS has different locking support. The constructors
--   of this datatype specify only the syntax of the locking
--   mechanism, not its semantics. For example, even though both
--   MySQL and PostgreSQL support ForUpdate, there are no guarantees
--   that they will behave the same.
--   
--   Since: 2.2.7
data LockingKind

-- | FOR UPDATE syntax. Supported by MySQL, Oracle and PostgreSQL.
--   
--   Since: 2.2.7
ForUpdate :: LockingKind

-- | FOR SHARE syntax. Supported by PostgreSQL.
--   
--   Since: 2.2.7
ForShare :: LockingKind

-- | LOCK IN SHARE MODE syntax. Supported by MySQL.
--   
--   Since: 2.2.7
LockInShareMode :: LockingKind

-- | Phantom class of data types that are treated as strings by the RDBMS.
--   It has no methods because it's only used to avoid type errors such as
--   trying to concatenate integers.
--   
--   If you have a custom data type or newtype, feel free to make
--   it an instance of this class.
--   
--   Since: 2.4.0
class PersistField a => SqlString a

-- | Class that enables one to use toBaseId to convert an entity's
--   key on a query into another (cf. toBaseId).
class ToBaseId ent where type BaseEnt ent :: * where {
    type family BaseEnt ent :: *;
}
toBaseIdWitness :: ToBaseId ent => Key (BaseEnt ent) -> Key ent

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

-- | (Internal) smartJoin a b is a JOIN of the correct
--   kind.
smartJoin :: IsJoinKind join => a -> b -> join a b

-- | (Internal) Reify a JoinKind from a JOIN. This
--   function is non-strict.
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

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
then_ :: ()

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
else_ :: expr a -> expr a
instance GHC.Show.Show Database.Esqueleto.Internal.Language.OnClauseWithoutMatchingJoinException
instance GHC.Classes.Ord Database.Esqueleto.Internal.Language.OnClauseWithoutMatchingJoinException
instance GHC.Classes.Eq Database.Esqueleto.Internal.Language.OnClauseWithoutMatchingJoinException
instance GHC.Classes.Eq Database.Esqueleto.Internal.Language.JoinKind
instance GHC.Show.Show a => GHC.Show.Show (Database.Esqueleto.Internal.Language.ValueList a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.Esqueleto.Internal.Language.ValueList a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.Esqueleto.Internal.Language.ValueList a)
instance GHC.Show.Show a => GHC.Show.Show (Database.Esqueleto.Internal.Language.Value a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.Esqueleto.Internal.Language.Value a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.Esqueleto.Internal.Language.Value a)
instance GHC.Base.Functor Database.Esqueleto.Internal.Language.Value
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c, Database.Esqueleto.Internal.Language.ToSomeValues expr d) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c, d)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c, Database.Esqueleto.Internal.Language.ToSomeValues expr d, Database.Esqueleto.Internal.Language.ToSomeValues expr e) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c, d, e)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c, Database.Esqueleto.Internal.Language.ToSomeValues expr d, Database.Esqueleto.Internal.Language.ToSomeValues expr e, Database.Esqueleto.Internal.Language.ToSomeValues expr f) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c, d, e, f)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c, Database.Esqueleto.Internal.Language.ToSomeValues expr d, Database.Esqueleto.Internal.Language.ToSomeValues expr e, Database.Esqueleto.Internal.Language.ToSomeValues expr f, Database.Esqueleto.Internal.Language.ToSomeValues expr g) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Internal.Language.ToSomeValues expr a, Database.Esqueleto.Internal.Language.ToSomeValues expr b, Database.Esqueleto.Internal.Language.ToSomeValues expr c, Database.Esqueleto.Internal.Language.ToSomeValues expr d, Database.Esqueleto.Internal.Language.ToSomeValues expr e, Database.Esqueleto.Internal.Language.ToSomeValues expr f, Database.Esqueleto.Internal.Language.ToSomeValues expr g, Database.Esqueleto.Internal.Language.ToSomeValues expr h) => Database.Esqueleto.Internal.Language.ToSomeValues expr (a, b, c, d, e, f, g, h)
instance Database.Esqueleto.Internal.Language.IsJoinKind Database.Esqueleto.Internal.Language.InnerJoin
instance Database.Esqueleto.Internal.Language.IsJoinKind Database.Esqueleto.Internal.Language.CrossJoin
instance Database.Esqueleto.Internal.Language.IsJoinKind Database.Esqueleto.Internal.Language.LeftOuterJoin
instance Database.Esqueleto.Internal.Language.IsJoinKind Database.Esqueleto.Internal.Language.RightOuterJoin
instance Database.Esqueleto.Internal.Language.IsJoinKind Database.Esqueleto.Internal.Language.FullOuterJoin
instance GHC.Exception.Exception Database.Esqueleto.Internal.Language.OnClauseWithoutMatchingJoinException
instance a ~ GHC.Types.Char => Database.Esqueleto.Internal.Language.SqlString [a]
instance Database.Esqueleto.Internal.Language.SqlString Data.Text.Internal.Text
instance Database.Esqueleto.Internal.Language.SqlString Data.Text.Internal.Lazy.Text
instance Database.Esqueleto.Internal.Language.SqlString Data.ByteString.Internal.ByteString
instance Database.Esqueleto.Internal.Language.SqlString Text.Blaze.Html.Html
instance Database.Esqueleto.Internal.Language.SqlString a => Database.Esqueleto.Internal.Language.SqlString (GHC.Base.Maybe a)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (expr (Database.Persist.Class.PersistEntity.Entity val))) => Database.Esqueleto.Internal.Language.From query expr backend (expr (Database.Persist.Class.PersistEntity.Entity val))
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (expr (GHC.Base.Maybe (Database.Persist.Class.PersistEntity.Entity val)))) => Database.Esqueleto.Internal.Language.From query expr backend (expr (GHC.Base.Maybe (Database.Persist.Class.PersistEntity.Entity val)))
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (Database.Esqueleto.Internal.Language.InnerJoin a b)) => Database.Esqueleto.Internal.Language.From query expr backend (Database.Esqueleto.Internal.Language.InnerJoin a b)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (Database.Esqueleto.Internal.Language.CrossJoin a b)) => Database.Esqueleto.Internal.Language.From query expr backend (Database.Esqueleto.Internal.Language.CrossJoin a b)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (Database.Esqueleto.Internal.Language.LeftOuterJoin a b)) => Database.Esqueleto.Internal.Language.From query expr backend (Database.Esqueleto.Internal.Language.LeftOuterJoin a b)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (Database.Esqueleto.Internal.Language.RightOuterJoin a b)) => Database.Esqueleto.Internal.Language.From query expr backend (Database.Esqueleto.Internal.Language.RightOuterJoin a b)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (Database.Esqueleto.Internal.Language.FullOuterJoin a b)) => Database.Esqueleto.Internal.Language.From query expr backend (Database.Esqueleto.Internal.Language.FullOuterJoin a b)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b) => Database.Esqueleto.Internal.Language.From query expr backend (a, b)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c, Database.Esqueleto.Internal.Language.From query expr backend d) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c, d)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c, Database.Esqueleto.Internal.Language.From query expr backend d, Database.Esqueleto.Internal.Language.From query expr backend e) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c, d, e)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c, Database.Esqueleto.Internal.Language.From query expr backend d, Database.Esqueleto.Internal.Language.From query expr backend e, Database.Esqueleto.Internal.Language.From query expr backend f) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c, d, e, f)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c, Database.Esqueleto.Internal.Language.From query expr backend d, Database.Esqueleto.Internal.Language.From query expr backend e, Database.Esqueleto.Internal.Language.From query expr backend f, Database.Esqueleto.Internal.Language.From query expr backend g) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Internal.Language.From query expr backend a, Database.Esqueleto.Internal.Language.From query expr backend b, Database.Esqueleto.Internal.Language.From query expr backend c, Database.Esqueleto.Internal.Language.From query expr backend d, Database.Esqueleto.Internal.Language.From query expr backend e, Database.Esqueleto.Internal.Language.From query expr backend f, Database.Esqueleto.Internal.Language.From query expr backend g, Database.Esqueleto.Internal.Language.From query expr backend h) => Database.Esqueleto.Internal.Language.From query expr backend (a, b, c, d, e, f, g, h)
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Persist.Class.PersistEntity.PersistEntity val, Database.Persist.Class.PersistEntity.PersistEntityBackend val ~ backend) => Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (expr (Database.Persist.Class.PersistEntity.Entity val))
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Persist.Class.PersistEntity.PersistEntity val, Database.Persist.Class.PersistEntity.PersistEntityBackend val ~ backend) => Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (expr (GHC.Base.Maybe (Database.Persist.Class.PersistEntity.Entity val)))
instance (Database.Esqueleto.Internal.Language.Esqueleto query expr backend, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend a, Database.Esqueleto.Internal.Language.FromPreprocess query expr backend b, Database.Esqueleto.Internal.Language.IsJoinKind join) => Database.Esqueleto.Internal.Language.FromPreprocess query expr backend (join 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.
--   
--   There are many comments describing the constructors of this data type.
--   However, Haddock doesn't like GADTs, so you'll have to read them by
--   hitting "Source".
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, MonadIO m) => SqlQuery a -> SqlReadT m [r]

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

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.

-- | Deprecated: Since 2.2.4: use select and distinct.
selectDistinct :: (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlPersistT m [r]

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.

-- | Deprecated: Since 2.2.4: use selectSource and
--   distinct.
selectDistinctSource :: (SqlSelect a r, MonadResource m) => SqlQuery a -> Source (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 :: (MonadIO m) => SqlQuery () -> SqlWriteT m ()

-- | Same as delete, but returns the number of rows affected.
deleteCount :: (MonadIO m) => SqlQuery () -> SqlWriteT 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_ $ isNothing (p ^. PersonAge)
--   
update :: (MonadIO m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()

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

-- | Insert a PersistField for every unique selected value.

-- | Deprecated: Since 2.2.4: use insertSelect and
--   distinct.
insertSelectDistinct :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

-- | Insert a PersistField for every selected value.
--   
--   Since: 2.4.2
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

-- | Insert a PersistField for every selected value, return the
--   count afterward
insertSelectCount :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m Int64

-- | (Internal) Create a case statement.
--   
--   Since: 2.1.1
unsafeSqlCase :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a)

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

-- | Similar to unsafeSqlBinOp, but may also be applied to composite
--   keys. Uses the operator given as the second argument whenever applied
--   to composite keys.
--   
--   Usage example:
--   
--   
--   (==.) :: SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value Bool)
--   (==.) = unsafeSqlBinOpComposite " = " " AND "
--   
--   
--   Persistent has a hack for implementing composite keys (see
--   ECompositeKey doc for more details), so we're forced to use a
--   hack here as well. We deconstruct ERaw values based on two
--   rules:
--   
--   
--   
- If it is a single placeholder, then it's assumed to be coming from
--   a PersistList and thus its components are separated so that
--   they may be applied to a composite key.
--   
- If it is not a single placeholder, then it's assumed to be a
--   foreign (composite or not) key, so we enforce that it has no
--   placeholders and split it on the commas.
--   
unsafeSqlBinOpComposite :: Builder -> 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)

-- | (Internal) An unsafe SQL function to extract a subfield from a
--   compound field, e.g. datetime. See unsafeSqlBinOp for warnings.
--   
--   Since: 1.3.6.
unsafeSqlExtractSubField :: 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, MonadIO m1, MonadIO m2) => Mode -> SqlQuery a -> SqlReadT m1 (Acquire (Source m2 r))

-- | (Internal) Run a Source of rows.
runSource :: Monad m => Source (ReaderT backend m) r -> ReaderT backend m [r]

-- | (Internal) Execute an esqueleto statement inside
--   persistent's SqlPersistT monad.
rawEsqueleto :: (MonadIO m, SqlSelect a r, IsSqlBackend backend) => Mode -> SqlQuery a -> ReaderT backend 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 :: (IsSqlBackend backend, SqlSelect a r) => Mode -> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])

-- | (Internal) Mode of query being converted by toRawSql.
data Mode
SELECT :: Mode
DELETE :: Mode
UPDATE :: Mode
INSERT_INTO :: 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 = (SqlBackend, 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 where sqlInsertInto = error "Type does not support sqlInsertInto."

-- | Creates the variable part of the SELECT query and returns the
--   list of PersistValues that will be given to rawQuery.
sqlSelectCols :: SqlSelect a r => IdentInfo -> a -> (Builder, [PersistValue])

-- | Number of columns that will be consumed.
sqlSelectColCount :: SqlSelect a r => Proxy a -> Int

-- | Transform a row of the result into the data type.
sqlSelectProcessRow :: SqlSelect a r => [PersistValue] -> Either Text r

-- | Create INSERT INTO clause instead.
sqlInsertInto :: SqlSelect a r => IdentInfo -> a -> (Builder, [PersistValue])

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

-- | (Internal) Coerce a value's type from 'SqlExpr (ValueList a)' to
--   'SqlExpr (Value a)'. Does not work with empty lists.
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)
instance GHC.Base.Functor Database.Esqueleto.Internal.Sql.SqlQuery
instance GHC.Base.Monad Database.Esqueleto.Internal.Sql.SqlQuery
instance GHC.Base.Applicative Database.Esqueleto.Internal.Sql.SqlQuery
instance GHC.Base.Monoid Database.Esqueleto.Internal.Sql.SideData
instance GHC.Base.Monoid Database.Esqueleto.Internal.Sql.DistinctClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Sql.WhereClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Sql.GroupByClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Sql.LimitClause
instance Database.Esqueleto.Internal.Language.Esqueleto Database.Esqueleto.Internal.Sql.SqlQuery Database.Esqueleto.Internal.Sql.SqlExpr Database.Persist.Sql.Types.Internal.SqlBackend
instance Database.Esqueleto.Internal.Language.ToSomeValues Database.Esqueleto.Internal.Sql.SqlExpr (Database.Esqueleto.Internal.Sql.SqlExpr (Database.Esqueleto.Internal.Language.Value a))
instance a ~ Database.Esqueleto.Internal.Language.Value b => Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument (Database.Esqueleto.Internal.Sql.SqlExpr a)
instance Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument a => Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument [a]
instance (Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument b) => Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument (a, b)
instance (Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument c) => Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument (a, b, c)
instance (Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument d) => Database.Esqueleto.Internal.Sql.UnsafeSqlFunctionArgument (a, b, c, d)
instance Database.Esqueleto.Internal.Sql.SqlSelect (Database.Esqueleto.Internal.Sql.SqlExpr Database.Esqueleto.Internal.Sql.InsertFinal) Database.Esqueleto.Internal.Sql.InsertFinal
instance Database.Esqueleto.Internal.Sql.SqlSelect () ()
instance Database.Persist.Class.PersistEntity.PersistEntity a => Database.Esqueleto.Internal.Sql.SqlSelect (Database.Esqueleto.Internal.Sql.SqlExpr (Database.Persist.Class.PersistEntity.Entity a)) (Database.Persist.Class.PersistEntity.Entity a)
instance Database.Persist.Class.PersistEntity.PersistEntity a => Database.Esqueleto.Internal.Sql.SqlSelect (Database.Esqueleto.Internal.Sql.SqlExpr (GHC.Base.Maybe (Database.Persist.Class.PersistEntity.Entity a))) (GHC.Base.Maybe (Database.Persist.Class.PersistEntity.Entity a))
instance Database.Persist.Class.PersistField.PersistField a => Database.Esqueleto.Internal.Sql.SqlSelect (Database.Esqueleto.Internal.Sql.SqlExpr (Database.Esqueleto.Internal.Language.Value a)) (Database.Esqueleto.Internal.Language.Value a)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b) (ra, rb)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c) (ra, rb, rc)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d) (ra, rb, rc, rd)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e) (ra, rb, rc, rd, re)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f) (ra, rb, rc, rd, re, rf)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f, g) (ra, rb, rc, rd, re, rf, rg)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f, g, h) (ra, rb, rc, rd, re, rf, rg, rh)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f, g, h, i) (ra, rb, rc, rd, re, rf, rg, rh, ri)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f, g, h, i, j) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk) => Database.Esqueleto.Internal.Sql.SqlSelect (a, b, c, d, e, f, g, h, i, j, k) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
instance (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk, Database.Esqueleto.Internal.Sql.SqlSelect l rl) => Database.Esqueleto.Internal.Sql.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 (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk, Database.Esqueleto.Internal.Sql.SqlSelect l rl, Database.Esqueleto.Internal.Sql.SqlSelect m rm) => Database.Esqueleto.Internal.Sql.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 (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk, Database.Esqueleto.Internal.Sql.SqlSelect l rl, Database.Esqueleto.Internal.Sql.SqlSelect m rm, Database.Esqueleto.Internal.Sql.SqlSelect n rn) => Database.Esqueleto.Internal.Sql.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 (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk, Database.Esqueleto.Internal.Sql.SqlSelect l rl, Database.Esqueleto.Internal.Sql.SqlSelect m rm, Database.Esqueleto.Internal.Sql.SqlSelect n rn, Database.Esqueleto.Internal.Sql.SqlSelect o ro) => Database.Esqueleto.Internal.Sql.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 (Database.Esqueleto.Internal.Sql.SqlSelect a ra, Database.Esqueleto.Internal.Sql.SqlSelect b rb, Database.Esqueleto.Internal.Sql.SqlSelect c rc, Database.Esqueleto.Internal.Sql.SqlSelect d rd, Database.Esqueleto.Internal.Sql.SqlSelect e re, Database.Esqueleto.Internal.Sql.SqlSelect f rf, Database.Esqueleto.Internal.Sql.SqlSelect g rg, Database.Esqueleto.Internal.Sql.SqlSelect h rh, Database.Esqueleto.Internal.Sql.SqlSelect i ri, Database.Esqueleto.Internal.Sql.SqlSelect j rj, Database.Esqueleto.Internal.Sql.SqlSelect k rk, Database.Esqueleto.Internal.Sql.SqlSelect l rl, Database.Esqueleto.Internal.Sql.SqlSelect m rm, Database.Esqueleto.Internal.Sql.SqlSelect n rn, Database.Esqueleto.Internal.Sql.SqlSelect o ro, Database.Esqueleto.Internal.Sql.SqlSelect p rp) => Database.Esqueleto.Internal.Sql.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)

-- | This module contain PostgreSQL-specific functions.
--   
--   Since: 2.2.8
module Database.Esqueleto.PostgreSQL

-- | (array_agg) Concatenate input values, including
--   NULLs, into an array.
--   
--   Since: 2.2.8
arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a])

-- | (string_agg) Concatenate input values separated by a
--   delimiter.
--   
--   Since: 2.2.8
stringAgg :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)

-- | (chr) Translate the given integer to a character. (Note the
--   result will depend on the character set of your database.)
--   
--   Since: 2.2.11
chr :: SqlString s => SqlExpr (Value Int) -> SqlExpr (Value s)

-- | 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.Persist as P
--   
--   
--   or import esqueleto itself qualified:
--   
--   
--   -- For a module that uses esqueleto just on some queries.
--   import Database.Persist
--   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 clause: restrict the query's result.
where_ :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | ON clause: restrict the a JOIN's result. The
--   ON clause will be applied to the last JOIN
--   that does not have an ON clause yet. If there are no
--   JOINs without ON clauses (either because you didn't
--   do any JOIN, or because all JOINs already have their
--   own ON clauses), a runtime exception
--   OnClauseWithoutMatchingJoinException is thrown. ON
--   clauses are optional when doing JOINs.
--   
--   On the simple case of doing just one JOIN, for example
--   
--   
--   select $
--   from $ \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooId ==. bar ^. BarFooId)
--     ...
--   
--   
--   there's no ambiguity and the rules above just mean that you're allowed
--   to call on only once (as in SQL). If you have many joins, then
--   the ons are applied on the reverse order that the
--   JOINs appear. For example:
--   
--   
--   select $
--   from $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -> do
--     on (baz ^. BazId ==. bar ^. BarBazId)
--     on (foo ^. FooId ==. bar ^. BarFooId)
--     ...
--   
--   
--   The order is reversed in order to improve composability. For
--   example, consider query1 and query2 below:
--   
--   
--   let query1 =
--         from $ \(foo `<a>InnerJoin</a>` bar) -> do
--           on (foo ^. FooId ==. bar ^. BarFooId)
--       query2 =
--         from $ \(mbaz `<a>LeftOuterJoin</a>` quux) -> do
--           return (mbaz ?. BazName, quux)
--       test1 =      (,) <$> query1 <*> query2
--       test2 = flip (,) <$> query2 <*> query1
--   
--   
--   If the order was not reversed, then test2 would be
--   broken: query1's on would refer to query2's
--   LeftOuterJoin.
on :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | GROUP BY clause. You can enclose multiple columns in a tuple.
--   
--   
--   select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy (bar ^. BarId, bar ^. BarName)
--     return (bar ^. BarId, bar ^. BarName, countRows)
--   
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   let to restrict the more general countRows to
--   SqlExpr (Value Int) to avoid ambiguity---the second use of
--   countRows has its type restricted by the :: Int
--   below):
--   
--   
--   r <- select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy $ bar ^. BarName
--     let countRows' = countRows
--     orderBy [asc countRows']
--     return (bar ^. BarName, countRows')
--   forM_ r $ \(Value name, Value count) -> do
--     print name
--     print (count :: Int)
--   
groupBy :: (Esqueleto query expr backend, ToSomeValues expr a) => a -> query ()

-- | ORDER BY clause. See also asc and desc.
--   
--   Multiple calls to orderBy get concatenated on the final query,
--   including distinctOnOrderBy.
orderBy :: Esqueleto query expr backend => [expr OrderBy] -> query ()

-- | Ascending order of this field or expression.
asc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy

-- | Descending order of this field or expression.
desc :: (Esqueleto query expr backend, PersistField a) => expr (Value a) -> expr OrderBy

-- | LIMIT. Limit the number of returned rows.
limit :: Esqueleto query expr backend => Int64 -> query ()

-- | OFFSET. Usually used with limit.
offset :: Esqueleto query expr backend => Int64 -> query ()

-- | DISTINCT. Change the current SELECT into SELECT
--   DISTINCT. For example:
--   
--   
--   select $ distinct $
--     from \foo -> do
--     ...
--   
--   
--   Note that this also has the same effect:
--   
--   
--   select $
--     from \foo -> do
--     distinct (return ())
--     ...
--   
--   
--   Since: 2.2.4
distinct :: Esqueleto query expr backend => query a -> query a

-- | DISTINCT ON. Change the current SELECT into
--   SELECT DISTINCT ON (expressions). For example:
--   
--   
--   select $
--     from \foo ->
--     distinctOn [don (foo ^. FooName), don (foo ^. FooState)] $ do
--     ...
--   
--   
--   You can also chain different calls to distinctOn. The above is
--   equivalent to:
--   
--   
--   select $
--     from \foo ->
--     distinctOn [don (foo ^. FooName)] $
--     distinctOn [don (foo ^. FooState)] $ do
--     ...
--   
--   
--   Each call to distinctOn adds more expressions. Calls to
--   distinctOn override any calls to distinct.
--   
--   Note that PostgreSQL requires the expressions on DISTINCT ON
--   to be the first ones to appear on a ORDER BY. This is not
--   managed automatically by esqueleto, keeping its spirit of trying to be
--   close to raw SQL.
--   
--   Supported by PostgreSQL only.
--   
--   Since: 2.2.4
distinctOn :: Esqueleto query expr backend => [expr DistinctOn] -> query a -> query a

-- | Erase an expression's type so that it's suitable to be used by
--   distinctOn.
--   
--   Since: 2.2.4
don :: Esqueleto query expr backend => expr (Value a) -> expr DistinctOn

-- | A convenience function that calls both distinctOn and
--   orderBy. In other words,
--   
--   
--   distinctOnOrderBy [asc foo, desc bar, desc quux] $ do
--     ...
--   
--   
--   is the same as:
--   
--   
--   distinctOn [don foo, don  bar, don  quux] $ do
--     orderBy  [asc foo, desc bar, desc quux]
--     ...
--   
--   
--   Since: 2.2.4
distinctOnOrderBy :: Esqueleto query expr backend => [expr OrderBy] -> query a -> query a

-- | ORDER BY random() clause.
--   
--   Since: 1.3.10
rand :: Esqueleto query expr backend => expr OrderBy

-- | HAVING.
--   
--   Since: 1.2.2
having :: Esqueleto query expr backend => expr (Value Bool) -> query ()

-- | Add a locking clause to the query. Please read LockingKind
--   documentation and your RDBMS manual.
--   
--   If multiple calls to locking are made on the same query, the
--   last one is used.
--   
--   Since: 2.2.7
locking :: Esqueleto query expr backend => LockingKind -> query ()

-- | Execute a subquery SELECT in an expression. Returns a simple
--   value so should be used only when the SELECT query is
--   guaranteed to return just one row.
sub_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)

-- | Same as sub_select but using SELECT DISTINCT.

-- | Deprecated: Since 2.2.4: use sub_select and
--   distinct.
sub_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (Value a)

-- | Project a field of an entity.
(^.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Entity val) -> EntityField val typ -> expr (Value typ)

-- | Project a field of an entity that may be null.
(?.) :: (Esqueleto query expr backend, PersistEntity val, PersistField typ) => expr (Maybe (Entity val)) -> EntityField val typ -> expr (Value (Maybe typ))

-- | Lift a constant value from Haskell-land to the query.
val :: (Esqueleto query expr backend, PersistField typ) => typ -> expr (Value typ)

-- | IS NULL comparison.
isNothing :: (Esqueleto query expr backend, PersistField typ) => expr (Value (Maybe typ)) -> expr (Value Bool)

-- | Analogous to Just, promotes a value of type typ into
--   one of type Maybe typ. It should hold that val .
--   Just === just . val.
just :: Esqueleto query expr backend => expr (Value typ) -> expr (Value (Maybe typ))

-- | NULL value.
nothing :: Esqueleto query expr backend => expr (Value (Maybe typ))

-- | Join nested Maybes in a Value into one. This is useful
--   when calling aggregate functions on nullable fields.
joinV :: Esqueleto query expr backend => expr (Value (Maybe (Maybe typ))) -> expr (Value (Maybe typ))

-- | COUNT(*) value.
countRows :: (Esqueleto query expr backend, Num a) => expr (Value a)

-- | COUNT.
count :: (Esqueleto query expr backend, Num a) => expr (Value typ) -> expr (Value a)

-- | COUNT(DISTINCT x).
--   
--   Since: 2.4.1
countDistinct :: (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, Num a) => expr (Value a)
round_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
ceiling_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
floor_ :: (Esqueleto query expr backend, PersistField a, Num a, PersistField b, Num b) => expr (Value a) -> expr (Value b)
sum_ :: (Esqueleto query expr backend, PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b))
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))

-- | Allow a number of one type to be used as one of another type via an
--   implicit cast. An explicit cast is not made, this function changes
--   only the types on the Haskell side.
--   
--   Caveat: Trying to use castNum from Double to
--   Int will not result in an integer, the original fractional
--   number will still be used! Use round_, ceiling_ or
--   floor_ instead.
--   
--   Safety: This operation is mostly safe due to the Num
--   constraint between the types and the fact that RDBMSs usually allow
--   numbers of different types to be used interchangeably. However, there
--   may still be issues with the query not being accepted by the RDBMS or
--   persistent not being able to parse it.
--   
--   Since: 2.2.9
castNum :: (Esqueleto query expr backend, Num a, Num b) => expr (Value a) -> expr (Value b)

-- | Same as castNum, but for nullable values.
--   
--   Since: 2.2.9
castNumM :: (Esqueleto query expr backend, Num a, Num b) => expr (Value (Maybe a)) -> expr (Value (Maybe b))

-- | COALESCE function. Evaluates the arguments in order and
--   returns the value of the first non-NULL expression, or NULL (Nothing)
--   otherwise. Some RDBMSs (such as SQLite) require at least two
--   arguments; please refer to the appropriate documentation.
--   
--   Since: 1.4.3
coalesce :: (Esqueleto query expr backend, PersistField a) => [expr (Value (Maybe a))] -> expr (Value (Maybe a))

-- | Like coalesce, but takes a non-nullable expression placed at
--   the end of the expression list, which guarantees a non-NULL result.
--   
--   Since: 1.4.3
coalesceDefault :: (Esqueleto query expr backend, PersistField a) => [expr (Value (Maybe a))] -> expr (Value a) -> expr (Value a)

-- | LOWER function.
lower_ :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s)

-- | LIKE operator.
like :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)

-- | ILIKE operator (case-insensitive LIKE).
--   
--   Supported by PostgreSQL only.
--   
--   Since: 2.2.3
ilike :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)

-- | The string %. May be useful while using like
--   and concatenation (concat_ or ++., depending on your
--   database). Note that you always have to type the parenthesis, for
--   example:
--   
--   
--   name `<a>like</a>` (%) ++. val "John" ++. (%)
--   
(%) :: (Esqueleto query expr backend, SqlString s) => expr (Value s)

-- | The CONCAT function with a variable number of parameters.
--   Supported by MySQL and PostgreSQL.
concat_ :: (Esqueleto query expr backend, SqlString s) => [expr (Value s)] -> expr (Value s)

-- | The || string concatenation operator (named after Haskell's
--   ++ in order to avoid naming clash with ||.). Supported
--   by SQLite and PostgreSQL.
(++.) :: (Esqueleto query expr backend, SqlString s) => expr (Value s) -> expr (Value s) -> expr (Value s)

-- | Cast a string type into Text. This function is very useful if
--   you want to use newtypes, or if you want to apply functions
--   such as like to strings of different types.
--   
--   Safety: This is a slightly unsafe function, especially if you
--   have defined your own instances of SqlString. Also, since
--   Maybe is an instance of SqlString, it's possible to turn
--   a nullable value into a non-nullable one. Avoid using this function if
--   possible.
castString :: (Esqueleto query expr backend, SqlString s, SqlString r) => expr (Value s) -> expr (Value r)

-- | Execute a subquery SELECT in an expression. Returns a list of
--   values.
subList_select :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)

-- | Same as sublist_select but using SELECT DISTINCT.

-- | Deprecated: Since 2.2.4: use subList_select and
--   distinct.
subList_selectDistinct :: (Esqueleto query expr backend, PersistField a) => query (expr (Value a)) -> expr (ValueList a)

-- | Lift a list of constant value from Haskell-land to the query.
valList :: (Esqueleto query expr backend, PersistField typ) => [typ] -> expr (ValueList typ)

-- | Same as just but for ValueList. Most of the time you
--   won't need it, though, because you can use just from inside
--   subList_select or Just from inside valList.
--   
--   Since: 2.2.12
justList :: Esqueleto query expr backend => expr (ValueList typ) -> expr (ValueList (Maybe typ))

-- | IN operator. For example if you want to select all
--   Persons by a list of IDs:
--   
--   
--   SELECT *
--   FROM Person
--   WHERE Person.id IN (?)
--   
--   
--   In esqueleto, we may write the same query above as:
--   
--   
--   select $
--   from $ \person -> do
--   where_ $ person ^. PersonId `<a>in_</a>` valList personIds
--   return person
--   
--   
--   Where personIds is of type [Key Person].
in_ :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)

-- | NOT IN operator.
notIn :: (Esqueleto query expr backend, PersistField typ) => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)

-- | EXISTS operator. For example:
--   
--   
--   select $
--   from $ \person -> do
--   where_ $ exists $
--            from $ \post -> do
--            where_ (post ^. BlogPostAuthorId ==. person ^. PersonId)
--   return person
--   
exists :: Esqueleto query expr backend => query () -> expr (Value Bool)

-- | NOT EXISTS operator.
notExists :: Esqueleto query expr backend => query () -> expr (Value Bool)

-- | SET clause used on UPDATEs. Note that while it's not
--   a type error to use this function on a SELECT, it will most
--   certainly result in a runtime error.
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)

-- | Apply a PersistField constructor to expr Value
--   arguments.
(<#) :: Esqueleto query expr backend => (a -> b) -> expr (Value a) -> expr (Insertion b)

-- | Apply extra expr Value arguments to a PersistField
--   constructor
(<&>) :: Esqueleto query expr backend => expr (Insertion (a -> b)) -> expr (Value a) -> expr (Insertion b)

-- | CASE statement. For example:
--   
--   
--   select $
--   return $
--   case_
--      [ when_
--          (exists $
--          from $ \p -> do
--          where_ (p ^. PersonName ==. val "Mike"))
--        then_
--          (sub_select $
--          from $ \v -> do
--          let sub =
--                  from $ \c -> do
--                  where_ (c ^. PersonName ==. val "Mike")
--                  return (c ^. PersonFavNum)
--          where_ (v ^. PersonFavNum >. sub_select sub)
--          return $ count (v ^. PersonName) +. val (1 :: Int)) ]
--      (else_ $ val (-1))
--   
--   
--   This query is a bit complicated, but basically it checks if a person
--   named "Mike" exists, and if that person does, run the
--   subquery to find out how many people have a ranking (by Fav Num)
--   higher than "Mike".
--   
--   NOTE: There are a few things to be aware about this statement.
--   
--   
--   
- This only implements the full CASE statement, it does not
--   implement the "simple" CASE statement.
--   
- At least one when_ and then_ is mandatory otherwise
--   it will emit an error.
--   
- The else_ is also mandatory, unlike the SQL statement in
--   which if the ELSE is omitted it will return a NULL.
--   You can reproduce this via nothing.
--   
--   
--   Since: 2.1.2
case_ :: (Esqueleto query expr backend, PersistField a) => [(expr (Value Bool), expr (Value a))] -> expr (Value a) -> expr (Value a)

-- | Convert an entity's key into another entity's.
--   
--   This function is to be used when you change an entity's Id to
--   be that of another entity. For example:
--   
--   
--   Bar
--     barNum Int
--   Foo
--     Id BarId
--     fooNum Int
--   
--   
--   For this example, declare:
--   
--   
--   instance ToBaseId Foo where
--     type BaseEnt Foo = Bar
--     toBaseIdWitness = FooKey
--   
--   
--   Now you're able to write queries such as:
--   
--   
--   select $
--   from $ (bar `<a>InnerJoin</a>` foo) -> do
--   on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
--   return (bar, foo)
--   
--   
--   Note: this function may be unsafe to use in conditions not like the
--   one of the example above.
--   
--   Since: 2.4.3
toBaseId :: (Esqueleto query expr backend, ToBaseId ent) => expr (Value (Key ent)) -> expr (Value (Key (BaseEnt ent)))

-- | Class that enables one to use toBaseId to convert an entity's
--   key on a query into another (cf. toBaseId).
class ToBaseId ent where type BaseEnt ent :: * where {
    type family BaseEnt ent :: *;
}
toBaseIdWitness :: ToBaseId ent => Key (BaseEnt ent) -> Key ent

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
then_ :: ()

-- | Syntax sugar for case_.
--   
--   Since: 2.1.2
else_ :: expr a -> expr a

-- | 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 left fixity.
--   
--   
--   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
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   (p1 `<a>InnerJoin</a>` (f `<a>InnerJoin</a>` p2)) ::
--     :: (...) => InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   
--   
--   Note that some backends may not support all kinds of JOINs.
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

-- | Unwrap a Value.
--   
--   Since: 1.4.1
unValue :: Value a -> a

-- | A list of single values. There's a limited set of functions 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

-- | Phantom type used by distinctOn and don.
data DistinctOn

-- | Different kinds of locking clauses supported by locking.
--   
--   Note that each RDBMS has different locking support. The constructors
--   of this datatype specify only the syntax of the locking
--   mechanism, not its semantics. For example, even though both
--   MySQL and PostgreSQL support ForUpdate, there are no guarantees
--   that they will behave the same.
--   
--   Since: 2.2.7
data LockingKind

-- | FOR UPDATE syntax. Supported by MySQL, Oracle and PostgreSQL.
--   
--   Since: 2.2.7
ForUpdate :: LockingKind

-- | FOR SHARE syntax. Supported by PostgreSQL.
--   
--   Since: 2.2.7
ForShare :: LockingKind

-- | LOCK IN SHARE MODE syntax. Supported by MySQL.
--   
--   Since: 2.2.7
LockInShareMode :: LockingKind

-- | Phantom class of data types that are treated as strings by the RDBMS.
--   It has no methods because it's only used to avoid type errors such as
--   trying to concatenate integers.
--   
--   If you have a custom data type or newtype, feel free to make
--   it an instance of this class.
--   
--   Since: 2.4.0
class PersistField a => SqlString a

-- | 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.
--   
--   There are many comments describing the constructors of this data type.
--   However, Haddock doesn't like GADTs, so you'll have to read them by
--   hitting "Source".
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, MonadIO m) => SqlQuery a -> SqlReadT m [r]

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a list of
--   rows.

-- | Deprecated: Since 2.2.4: use select and distinct.
selectDistinct :: (SqlSelect a r, MonadIO 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, MonadResource m) => SqlQuery a -> Source (SqlPersistT m) r

-- | Execute an esqueleto SELECT DISTINCT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.

-- | Deprecated: Since 2.2.4: use selectSource and
--   distinct.
selectDistinctSource :: (SqlSelect a r, MonadResource m) => SqlQuery a -> Source (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 :: (MonadIO m) => SqlQuery () -> SqlWriteT m ()

-- | Same as delete, but returns the number of rows affected.
deleteCount :: (MonadIO m) => SqlQuery () -> SqlWriteT 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_ $ isNothing (p ^. PersonAge)
--   
update :: (MonadIO m, SqlEntity val) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()

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

-- | Insert a PersistField for every selected value.
--   
--   Since: 2.4.2
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

-- | Insert a PersistField for every selected value, return the
--   count afterward
insertSelectCount :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m Int64

-- | Insert a PersistField for every unique selected value.

-- | Deprecated: Since 2.2.4: use insertSelect and
--   distinct.
insertSelectDistinct :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

-- | Apply a PersistField constructor to expr Value
--   arguments.
(<#) :: Esqueleto query expr backend => (a -> b) -> expr (Value a) -> expr (Insertion b)

-- | Apply extra expr Value arguments to a PersistField
--   constructor
(<&>) :: Esqueleto query expr backend => expr (Insertion (a -> b)) -> expr (Value a) -> expr (Insertion b)

-- | valkey i = val . toSqlKey
--   (https://github.com/prowdsponsor/esqueleto/issues/9).
valkey :: (Esqueleto query expr backend, ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> expr (Value (Key entity))

-- | valJ is like val but for something that is already a
--   Value. The use case it was written for was, given a
--   Value lift the Key for that Value into the
--   query expression in a type safe way. However, the implementation is
--   more generic than that so we call it valJ.
--   
--   Its important to note that the input entity and the output entity are
--   constrained to be the same by the type signature on the function
--   (https://github.com/prowdsponsor/esqueleto/pull/69).
--   
--   Since: 1.4.2
valJ :: (Esqueleto query expr backend, PersistField (Key entity)) => Value (Key entity) -> expr (Value (Key entity))

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