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


-- | Bare bones, type-safe EDSL for SQL queries on persistent backends.
--   
--   <tt>persistent</tt> is a library for type-safe data serialization. It
--   has many kinds of backends, such as SQL backends
--   (<tt>persistent-mysql</tt>, <tt>persistent-postgresql</tt>,
--   <tt>persistent-sqlite</tt>) and NoSQL backends
--   (<tt>persistent-mongoDB</tt>).
--   
--   While <tt>persistent</tt> is a nice library for storing and retrieving
--   records, currently it has a poor interface for SQL backends compared
--   to SQL itself. For example, it's extremely hard to do a type-safe
--   <tt>JOIN</tt> on a many-to-one relation, and simply impossible to do
--   any other kinds of <tt>JOIN</tt>s (including for the very common
--   many-to-many relations). Users have the option of writing raw SQL, but
--   that's error prone and not type-checked.
--   
--   <tt>esqueleto</tt> is a bare bones, type-safe EDSL for SQL queries
--   that works with unmodified <tt>persistent</tt> SQL backends. Its
--   language closely resembles SQL, so (a) you don't have to learn new
--   concepts, just new syntax, and (b) it's fairly easy to predict the
--   generated SQL and optimize it for your backend. Most kinds of errors
--   committed when writing SQL are caught as compile-time
--   errors---although it is possible to write type-checked
--   <tt>esqueleto</tt> queries that fail at runtime.
--   
--   Currently, <tt>SELECT</tt>s, <tt>UPDATE</tt>s, <tt>INSERT</tt>s and
--   <tt>DELETE</tt>s 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 <tt>esqueleto</tt> on
--   <a>https://github.com/meteficha/esqueleto/</a>.
--   
--   The name of this library means "skeleton" in Portuguese and contains
--   all three SQL letters in the correct order =). It was inspired by
--   Scala's Squeryl but created from scratch.
@package esqueleto
@version 1.3.4.2


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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Phantom type used by <a>orderBy</a>, <a>asc</a> and <a>desc</a>.
data OrderBy

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

-- | Phantom type used by <tt>insertSelect</tt>.
data Insertion a

-- | (Internal) A kind of <tt>JOIN</tt>.
data JoinKind

-- | <pre>
--   INNER JOIN
--   </pre>
InnerJoinKind :: JoinKind

-- | <pre>
--   CROSS JOIN
--   </pre>
CrossJoinKind :: JoinKind

-- | <pre>
--   LEFT OUTER JOIN
--   </pre>
LeftOuterJoinKind :: JoinKind

-- | <pre>
--   RIGHT OUTER JOIN
--   </pre>
RightOuterJoinKind :: JoinKind

-- | <pre>
--   FULL OUTER JOIN
--   </pre>
FullOuterJoinKind :: JoinKind

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

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

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

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


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

-- | SQL backend for <tt>esqueleto</tt> using <a>SqlPersistT</a>.
data SqlQuery a

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

-- | Phantom type used by <a>orderBy</a>, <a>asc</a> and <a>desc</a>.
data OrderBy

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

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

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

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

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

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

-- | SQL backend for <tt>esqueleto</tt> using <a>SqlPersistT</a>.
data SqlQuery a

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

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

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

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

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

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

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

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

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

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

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

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

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

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