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


-- | Type-safe EDSL for SQL queries on persistent backends.
--   
--   <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 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
--   <tt>esqueleto</tt> queries that fail at runtime.
--   
--   <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, including with filters, it
--   does not try to support some of the features that are specific to SQL
--   backends. In particular, <tt>esqueleto</tt> is the recommended library
--   for type-safe <tt>JOIN</tt>s on <tt>persistent</tt> SQL backends. (The
--   alternative is using raw SQL, but that's error prone and does not
--   offer any composability.)
--   
--   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/bitemyapp/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 3.3.3.2


-- | This is an internal module. This module may have breaking changes
--   without a corresponding major version bump. If you use this module,
--   please open an issue with your use-case so we can safely support it.
module Database.Esqueleto.Internal.ExprParser

-- | A type representing the access of a table value. In Esqueleto, we get
--   a guarantee that the access will look something like:
--   
--   <pre>
--   escape-char [character] escape-char . escape-char [character] escape-char
--               ^^^^^^^^^^^                           ^^^^^^^^^^^
--               table name                            column name
--   </pre>
data TableAccess
TableAccess :: Text -> Text -> TableAccess
[tableAccessTable] :: TableAccess -> Text
[tableAccessColumn] :: TableAccess -> Text

-- | Parse a <tt>SqlExpr (Value Bool)</tt>'s textual representation into a
--   list of <a>TableAccess</a>
parseOnExpr :: SqlBackend -> Text -> Either String (Set TableAccess)

-- | This function uses the <a>connEscapeName</a> function in the
--   <a>SqlBackend</a> with an empty identifier to pull out an escape
--   character. This implementation works with postgresql, mysql, and
--   sqlite backends.
mkEscapeChar :: SqlBackend -> Either String Char
type ExprParser a = Char -> Parser a
onExpr :: ExprParser (Set TableAccess)
skipToEscape :: ExprParser ()
parseEscapedIdentifier :: ExprParser [Char]
parseTableAccess :: ExprParser TableAccess
parseEscapedChars :: ExprParser [Char]
instance GHC.Show.Show Database.Esqueleto.Internal.ExprParser.TableAccess
instance GHC.Classes.Ord Database.Esqueleto.Internal.ExprParser.TableAccess
instance GHC.Classes.Eq Database.Esqueleto.Internal.ExprParser.TableAccess


-- | 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.
--   
--   If you use this module, please report what your use case is on the
--   issue tracker so we can safely support it.
module Database.Esqueleto.Internal.Internal

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

-- | (Internal) Same as <a>fromStart</a>, but entity may be missing.
fromStartMaybe :: (PersistEntity a, BackendCompatible SqlBackend (PersistEntityBackend a)) => SqlQuery (SqlExpr (PreprocessedFrom (SqlExpr (Maybe (Entity a)))))

-- | (Internal) Do a <tt>JOIN</tt>.
fromJoin :: IsJoinKind join => SqlExpr (PreprocessedFrom a) -> SqlExpr (PreprocessedFrom b) -> SqlQuery (SqlExpr (PreprocessedFrom (join a b)))

-- | (Internal) Finish a <tt>JOIN</tt>.
fromFinish :: SqlExpr (PreprocessedFrom a) -> SqlQuery a

-- | <tt>WHERE</tt> clause: restrict the query's result.
where_ :: SqlExpr (Value Bool) -> SqlQuery ()

-- | An <tt>ON</tt> clause, useful to describe how two tables are related.
--   Cross joins and tuple-joins do not need an <a>on</a> clause, but
--   <a>InnerJoin</a> and the various outer joins do.
--   
--   If you don't include an <a>on</a> clause (or include too many!) then a
--   runtime exception will be thrown.
--   
--   As an example, consider this simple join:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   We need to specify the clause for joining the two columns together. If
--   we had this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>CrossJoin</a>` bar) -&gt; do
--     ...
--   </pre>
--   
--   Then we can safely omit the <a>on</a> clause, because the cross join
--   will make pairs of all records possible.
--   
--   You can do multiple <a>on</a> clauses in a query. This query joins
--   three tables, and has two <a>on</a> clauses:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   Old versions of esqueleto required that you provide the <a>on</a>
--   clauses in reverse order. This restriction has been lifted - you can
--   now provide <a>on</a> clauses in any order, and the SQL should work
--   itself out. The above query is now totally equivalent to this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     ...
--   </pre>
on :: SqlExpr (Value Bool) -> SqlQuery ()

-- | <tt>GROUP BY</tt> clause. You can enclose multiple columns in a tuple.
--   
--   <pre>
--   select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> (bar <a>^.</a> BarId, bar <a>^.</a> BarName)
--     return (bar <a>^.</a> BarId, bar <a>^.</a> BarName, countRows)
--   </pre>
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   <tt>let</tt> to restrict the more general <a>countRows</a> to
--   <tt>SqlSqlExpr (Value Int)</tt> to avoid ambiguity---the second use of
--   <a>countRows</a> has its type restricted by the <tt>:: Int</tt>
--   below):
--   
--   <pre>
--   r &lt;- select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> $ bar <a>^.</a> BarName
--     let countRows' = <a>countRows</a>
--     <a>orderBy</a> [<a>asc</a> countRows']
--     return (bar <a>^.</a> BarName, countRows')
--   forM_ r $ \(<a>Value</a> name, <a>Value</a> count) -&gt; do
--     print name
--     print (count :: Int)
--   </pre>
--   
--   <h3>Need more columns?</h3>
--   
--   The <a>ToSomeValues</a> class is defined for <a>SqlExpr</a> and tuples
--   of <a>SqlExpr</a>s. We only have definitions for up to 8 elements in a
--   tuple right now, so it's possible that you may need to have more than
--   8 elements.
--   
--   For example, consider a query with a <a>groupBy</a> call like this:
--   
--   <pre>
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   </pre>
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   <pre>
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   </pre>
groupBy :: ToSomeValues a => a -> SqlQuery ()

-- | <tt>ORDER BY</tt> clause. See also <a>asc</a> and <a>desc</a>.
--   
--   Multiple calls to <a>orderBy</a> get concatenated on the final query,
--   including <a>distinctOnOrderBy</a>.
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()

-- | Ascending order of this field or SqlExpression.
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | Descending order of this field or SqlExpression.
desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | <tt>LIMIT</tt>. Limit the number of returned rows.
limit :: Int64 -> SqlQuery ()

-- | <tt>OFFSET</tt>. Usually used with <a>limit</a>.
offset :: Int64 -> SqlQuery ()

-- | <tt>DISTINCT</tt>. Change the current <tt>SELECT</tt> into <tt>SELECT
--   DISTINCT</tt>. For example:
--   
--   <pre>
--   select $ distinct $
--     <a>from</a> \foo -&gt; do
--     ...
--   </pre>
--   
--   Note that this also has the same effect:
--   
--   <pre>
--   select $
--     <a>from</a> \foo -&gt; do
--     distinct (return ())
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinct :: SqlQuery a -> SqlQuery a

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

-- | Erase an SqlExpression's type so that it's suitable to be used by
--   <a>distinctOn</a>.
--   
--   <i>Since: 2.2.4</i>
don :: SqlExpr (Value a) -> SqlExpr DistinctOn

-- | A convenience function that calls both <a>distinctOn</a> and
--   <a>orderBy</a>. In other words,
--   
--   <pre>
--   <a>distinctOnOrderBy</a> [asc foo, desc bar, desc quux] $ do
--     ...
--   </pre>
--   
--   is the same as:
--   
--   <pre>
--   <a>distinctOn</a> [don foo, don  bar, don  quux] $ do
--     <a>orderBy</a>  [asc foo, desc bar, desc quux]
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a

-- | <tt>ORDER BY random()</tt> clause.
--   
--   <i>Since: 1.3.10</i>

-- | <i>Deprecated: Since 2.6.0: <a>rand</a> ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.</i>
rand :: SqlExpr OrderBy

-- | <tt>HAVING</tt>.
--   
--   <i>Since: 1.2.2</i>
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a
--   simple value so should be used only when the <tt>SELECT</tt> query is
--   guaranteed to return just one row.
--   
--   Deprecated in 3.2.0.

-- | <i>Deprecated: sub_select sub_select is an unsafe function to use. If
--   used with a SqlQuery that returns 0 results, then it may return NULL
--   despite not mentioning Maybe in the return type. If it returns more
--   than 1 result, then it will throw a SQL error. Instead, consider using
--   one of the following alternatives: - subSelect: attaches a LIMIT 1 and
--   the Maybe return type, totally safe. - subSelectMaybe: Attaches a
--   LIMIT 1, useful for a query that already has a Maybe in the return
--   type. - subSelectCount: Performs a count of the query - this is always
--   safe. - subSelectUnsafe: Performs no checks or guarantees. Safe to use
--   with countRows and friends.</i>
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. The query
--   passed to this function will only return a single result - it has a
--   <tt>LIMIT 1</tt> passed in to the query to make it safe, and the
--   return type is <a>Maybe</a> to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing <tt><a>joinV</a> . <a>subSelect</a></tt>,
--   then consider using <a>subSelectMaybe</a>.
--   
--   If you're performing a <a>countRows</a>, then you can use
--   <a>subSelectCount</a> which is safe.
--   
--   If you know that the subquery will always return exactly one row (eg a
--   foreign key constraint guarantees that you'll get exactly one row),
--   then consider <a>subSelectUnsafe</a>, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is a shorthand for the common <tt><a>joinV</a> . <a>subSelect</a></tt>
--   idiom, where you are calling <a>subSelect</a> on an expression that
--   would be <a>Maybe</a> already.
--   
--   As an example, you would use this function when calling <a>sum_</a> or
--   <a>max_</a>, which have <a>Maybe</a> in the result type (for a 0 row
--   query).
subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))

-- | Performs a <tt>COUNT</tt> of the given query in a <tt>subSelect</tt>
--   manner. This is always guaranteed to return a result value, and is
--   completely safe.
subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a> that returns a
--   list. This is an alias for <a>subList_select</a> and is provided for
--   symmetry with the other safe subselect functions.
subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

-- | Performs a sub-select using the given foreign key on the entity. This
--   is useful to extract values that are known to be present by the
--   database schema.
--   
--   As an example, consider the following persistent definition:
--   
--   <pre>
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   </pre>
--   
--   The following query will return the name of the user.
--   
--   <pre>
--   getUserWithName =
--       <a>select</a> $
--       <a>from</a> $ user -&gt;
--       <a>pure</a> (user, <a>subSelectForeign</a> user UserProfile (^. ProfileName)
--   </pre>
subSelectForeign :: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) => SqlExpr (Entity val2) -> EntityField val2 (Key val1) -> (SqlExpr (Entity val1) -> SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is unsafe, because it can throw runtime exceptions in two cases:
--   
--   <ol>
--   <li>If the query passed has 0 result rows, then it will return a
--   <tt>NULL</tt> value. The <tt>persistent</tt> parsing operations will
--   fail on an unexpected <tt>NULL</tt>.</li>
--   <li>If the query passed returns more than one row, then the SQL engine
--   will fail with an error like "More than one row returned by a subquery
--   used as an expression".</li>
--   </ol>
--   
--   This function is safe if you guarantee that exactly one row will be
--   returned, or if the result already has a <a>Maybe</a> type for some
--   reason.
--   
--   For variants with the safety encoded already, see <a>subSelect</a> and
--   <a>subSelectMaybe</a>. For the most common safe use of this, see
--   <a>subSelectCount</a>.
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Project a field of an entity.
(^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
infixl 9 ^.

-- | Project an SqlExpression that may be null, guarding against null
--   cases.
withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a

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

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

-- | <tt>IS NULL</tt> comparison.
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)

-- | Analogous to <a>Just</a>, promotes a value of type <tt>typ</tt> into
--   one of type <tt>Maybe typ</tt>. It should hold that <tt><a>val</a> .
--   Just === just . <a>val</a></tt>.
just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))

-- | <tt>NULL</tt> value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested <a>Maybe</a>s in a <a>Value</a> into one. This is useful
--   when calling aggregate functions on nullable fields.
joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
countHelper :: Num a => Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)

-- | <tt>COUNT(*)</tt> value.
countRows :: Num a => SqlExpr (Value a)

-- | <tt>COUNT</tt>.
count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)

-- | <tt>COUNT(DISTINCT x)</tt>.
--   
--   <i>Since: 2.4.1</i>
countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 ==.
(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >=.
(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >.
(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <=.
(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <.
(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 !=.
(&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 3 &&.
(||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 2 ||.
(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 +.
(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 -.
(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 /.
(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 *.

-- | <tt>BETWEEN</tt>.
--   
--   @since: 3.1.0
between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)

-- | <i>Deprecated: Since 2.6.0: <a>random_</a> is not uniform across all
--   databases! Please use a specific one such as <a>random_</a>,
--   <a>random_</a>, or <a>random_</a></i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (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.
--   
--   <i>Caveat</i>: Trying to use <tt>castNum</tt> from <tt>Double</tt> to
--   <tt>Int</tt> will not result in an integer, the original fractional
--   number will still be used! Use <a>round_</a>, <a>ceiling_</a> or
--   <a>floor_</a> instead.
--   
--   <i>Safety</i>: This operation is mostly safe due to the <a>Num</a>
--   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
--   <tt>persistent</tt> not being able to parse it.
--   
--   <i>Since: 2.2.9</i>
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

-- | Same as <a>castNum</a>, but for nullable values.
--   
--   <i>Since: 2.2.9</i>
castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))

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

-- | Like <tt>coalesce</tt>, but takes a non-nullable SqlExpression placed
--   at the end of the SqlExpression list, which guarantees a non-NULL
--   result.
--   
--   <i>Since: 1.4.3</i>
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)

-- | <tt>LOWER</tt> function.
lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>UPPER</tt> function. <i>Since: 3.3.0</i>
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>TRIM</tt> function. <i>Since: 3.3.0</i>
trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>RTRIM</tt> function. <i>Since: 3.3.0</i>
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LTRIM</tt> function. <i>Since: 3.3.0</i>
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LENGTH</tt> function. <i>Since: 3.3.0</i>
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)

-- | <tt>LEFT</tt> function. <i>Since: 3.3.0</i>
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>RIGHT</tt> function. <i>Since: 3.3.0</i>
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>LIKE</tt> operator.
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `like`

-- | <tt>ILIKE</tt> operator (case-insensitive <tt>LIKE</tt>).
--   
--   Supported by PostgreSQL only.
--   
--   <i>Since: 2.2.3</i>
ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `ilike`

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

-- | The <tt>CONCAT</tt> function with a variable number of parameters.
--   Supported by MySQL and PostgreSQL.
concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)

-- | The <tt>||</tt> string concatenation operator (named after Haskell's
--   <a>++</a> in order to avoid naming clash with <a>||.</a>). Supported
--   by SQLite and PostgreSQL.
(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
infixr 5 ++.

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a list
--   of values.
subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

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

-- | Same as <a>just</a> but for <a>ValueList</a>. Most of the time you
--   won't need it, though, because you can use <a>just</a> from inside
--   <a>subList_select</a> or <a>Just</a> from inside <a>valList</a>.
--   
--   <i>Since: 2.2.12</i>
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

-- | <tt>NOT IN</tt> operator.
notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)

-- | <tt>EXISTS</tt> operator. For example:
--   
--   <pre>
--   select $
--   <a>from</a> $ \person -&gt; do
--   <a>where_</a> $ <a>exists</a> $
--            <a>from</a> $ \post -&gt; do
--            <a>where_</a> (post <a>^.</a> BlogPostAuthorId <a>==.</a> person <a>^.</a> PersonId)
--   return person
--   </pre>
exists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>NOT EXISTS</tt> operator.
notExists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>SET</tt> clause used on <tt>UPDATE</tt>s. Note that while it's not
--   a type error to use this function on a <tt>SELECT</tt>, it will most
--   certainly result in a runtime error.
set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Update val)] -> SqlQuery ()
(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Update val)
infixr 3 =.
(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 +=.
(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 -=.
(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 *=.
(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 /=.

-- | Apply a <a>PersistField</a> constructor to <tt>SqlExpr Value</tt>
--   arguments.
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

-- | Apply extra <tt>SqlExpr Value</tt> arguments to a <a>PersistField</a>
--   constructor
(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

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

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

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

-- | Syntax sugar for <a>case_</a>.
--   
--   <i>Since: 2.1.2</i>
then_ :: ()

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

-- | 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>.
newtype Value a
Value :: a -> Value a
[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 <a>subList_select</a>,
--   <a>valList</a>, <a>in_</a> and <a>exists</a>).
newtype ValueList a
ValueList :: a -> ValueList a

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

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

-- | A class for constructors or function which result type is known.
class FinalResult a
finalR :: FinalResult a => a -> KnowResult a

-- | Convert a constructor for a <a>Unique</a> key on a record to the
--   <a>UniqueDef</a> that defines it. You can supply just the constructor
--   itself, or a value of the type - the library is capable of figuring it
--   out from there.
toUniqueDef :: forall a val. (KnowResult a ~ Unique val, PersistEntity val, FinalResult a) => a -> UniqueDef

-- | Render updates to be use in a SET clause for a given sql backend.
renderUpdates :: BackendCompatible SqlBackend backend => backend -> [SqlExpr (Update val)] -> (Builder, [PersistValue])

-- | 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
infixl 2 `InnerJoin`
infixl 2 `InnerJoin`

-- | 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
infixl 2 `CrossJoin`
infixl 2 `CrossJoin`

-- | Data type that represents a <tt>LEFT OUTER JOIN</tt>. For example,
--   
--   <pre>
--   select $
--   <a>from</a> $ \(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
infixl 2 `LeftOuterJoin`
infixl 2 `LeftOuterJoin`

-- | 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
infixl 2 `RightOuterJoin`
infixl 2 `RightOuterJoin`

-- | 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
infixl 2 `FullOuterJoin`
infixl 2 `FullOuterJoin`

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

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

-- | (Internal) Reify a <tt>JoinKind</tt> from a <tt>JOIN</tt>. This
--   function is non-strict.
reifyJoinKind :: IsJoinKind join => join a b -> JoinKind

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

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

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

-- | Phantom type used by <a>distinctOn</a> and <a>don</a>.
data DistinctOn

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

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

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

-- | <tt>FOR UPDATE</tt> syntax. Supported by MySQL, Oracle and PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdate :: LockingKind

-- | <tt>FOR UPDATE SKIP LOCKED</tt> syntax. Supported by MySQL, Oracle and
--   PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdateSkipLocked :: LockingKind

-- | <tt>FOR SHARE</tt> syntax. Supported by PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForShare :: LockingKind

-- | <tt>LOCK IN SHARE MODE</tt> syntax. Supported by MySQL.
--   
--   <i>Since: 2.2.7</i>
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 <tt>newtype</tt>, feel free to make
--   it an instance of this class.
--   
--   <i>Since: 2.4.0</i>
class PersistField a => SqlString a

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

-- | Convert from the key of the BaseEnt(ity) to the key of the child
--   entity. This function is not actually called, but that it typechecks
--   proves this operation is safe.
toBaseIdWitness :: ToBaseId ent => Key (BaseEnt ent) -> Key ent

-- | <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 left fixity.</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>
--   <a>from</a> $ \person -&gt; ...
--   <a>from</a> $ \(person, blogPost) -&gt; ...
--   <a>from</a> $ \(p `<a>LeftOuterJoin</a>` mb) -&gt; ...
--   <a>from</a> $ \(p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2) -&gt; ...
--   <a>from</a> $ \((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
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   (p1 `<a>InnerJoin</a>` (f `<a>InnerJoin</a>` p2)) ::
--     :: (...) =&gt; InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   </pre>
--   
--   Note that some backends may not support all kinds of <tt>JOIN</tt>s.
from :: From a => (a -> SqlQuery b) -> SqlQuery b

-- | (Internal) Class that implements the tuple <a>from</a> magic (see
--   <a>fromStart</a>).
class From a
from_ :: From a => SqlQuery a

-- | (Internal) Class that implements the <tt>JOIN</tt> <a>from</a> magic
--   (see <a>fromStart</a>).
class FromPreprocess a
fromPreprocess :: FromPreprocess a => SqlQuery (SqlExpr (PreprocessedFrom a))

-- | Exception data type for <tt>esqueleto</tt> internal errors
data EsqueletoError
CompositeKeyErr :: CompositeKeyError -> EsqueletoError
AliasedValueErr :: UnexpectedValueError -> EsqueletoError
UnexpectedCaseErr :: UnexpectedCaseError -> EsqueletoError
SqlBinOpCompositeErr :: SqlBinOpCompositeError -> EsqueletoError
data UnexpectedValueError
NotError :: UnexpectedValueError
ToInsertionError :: UnexpectedValueError
CombineInsertionError :: UnexpectedValueError
FoldHelpError :: UnexpectedValueError
SqlCaseError :: UnexpectedValueError
SqlCastAsError :: UnexpectedValueError
SqlFunctionError :: UnexpectedValueError
MakeOnClauseError :: UnexpectedValueError
MakeExcError :: UnexpectedValueError
MakeSetError :: UnexpectedValueError
MakeWhereError :: UnexpectedValueError
MakeHavingError :: UnexpectedValueError
type CompositeKeyError = UnexpectedValueError
data UnexpectedCaseError
EmptySqlExprValueList :: UnexpectedCaseError
MakeFromError :: UnexpectedCaseError
UnsupportedSqlInsertIntoType :: UnexpectedCaseError
InsertionFinalError :: UnexpectedCaseError
NewIdentForError :: UnexpectedCaseError
UnsafeSqlCaseError :: UnexpectedCaseError
OperationNotSupported :: UnexpectedCaseError
NotImplemented :: UnexpectedCaseError
data SqlBinOpCompositeError
MismatchingLengthsError :: SqlBinOpCompositeError
NullPlaceholdersError :: SqlBinOpCompositeError
DeconstructionError :: SqlBinOpCompositeError

-- | SQL backend for <tt>esqueleto</tt> using <a>SqlPersistT</a>.
newtype SqlQuery a
Q :: WriterT SideData (State IdentState) a -> SqlQuery a
[unQ] :: SqlQuery a -> WriterT SideData (State IdentState) a

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

-- | Side data written by <a>SqlQuery</a>.
data SideData
SideData :: !DistinctClause -> ![FromClause] -> ![SetClause] -> !WhereClause -> !GroupByClause -> !HavingClause -> ![OrderByClause] -> !LimitClause -> !LockingClause -> SideData
[sdDistinctClause] :: SideData -> !DistinctClause
[sdFromClause] :: SideData -> ![FromClause]
[sdSetClause] :: SideData -> ![SetClause]
[sdWhereClause] :: SideData -> !WhereClause
[sdGroupByClause] :: SideData -> !GroupByClause
[sdHavingClause] :: SideData -> !HavingClause
[sdOrderByClause] :: SideData -> ![OrderByClause]
[sdLimitClause] :: SideData -> !LimitClause
[sdLockingClause] :: SideData -> !LockingClause

-- | The <tt>DISTINCT</tt> "clause".
data DistinctClause

-- | The default, everything.
DistinctAll :: DistinctClause

-- | Only <tt>DISTINCT</tt>, SQL standard.
DistinctStandard :: DistinctClause

-- | <tt>DISTINCT ON</tt>, PostgreSQL extension.
DistinctOn :: [SqlExpr DistinctOn] -> DistinctClause

-- | A part of a <tt>FROM</tt> clause.
data FromClause
FromStart :: Ident -> EntityDef -> FromClause
FromJoin :: FromClause -> JoinKind -> FromClause -> Maybe (SqlExpr (Value Bool)) -> FromClause
OnClause :: SqlExpr (Value Bool) -> FromClause
FromQuery :: Ident -> (IdentInfo -> (Builder, [PersistValue])) -> FromClause
collectIdents :: FromClause -> Set Ident

-- | A part of a <tt>SET</tt> clause.
newtype SetClause
SetClause :: SqlExpr (Value ()) -> SetClause

-- | Collect <a>OnClause</a>s on <a>FromJoin</a>s. Returns the first
--   unmatched <a>OnClause</a>s data on error. Returns a list without
--   <tt>OnClauses</tt> on success.
collectOnClauses :: SqlBackend -> [FromClause] -> Either (SqlExpr (Value Bool)) [FromClause]

-- | A complete <tt>WHERE</tt> clause.
data WhereClause
Where :: SqlExpr (Value Bool) -> WhereClause
NoWhere :: WhereClause

-- | A <tt>GROUP BY</tt> clause.
newtype GroupByClause
GroupBy :: [SomeValue] -> GroupByClause

-- | A <tt>HAVING</tt> cause.
type HavingClause = WhereClause

-- | A <tt>ORDER BY</tt> clause.
type OrderByClause = SqlExpr OrderBy

-- | A <tt>LIMIT</tt> clause.
data LimitClause
Limit :: Maybe Int64 -> Maybe Int64 -> LimitClause

-- | A locking clause.
type LockingClause = Last LockingKind

-- | Identifier used for table names.
newtype Ident
I :: Text -> Ident

-- | List of identifiers already in use and supply of temporary
--   identifiers.
newtype IdentState
IdentState :: HashSet Text -> IdentState
[inUse] :: IdentState -> HashSet Text
initialIdentState :: IdentState

-- | Create a fresh <a>Ident</a>. If possible, use the given <a>DBName</a>.
newIdentFor :: DBName -> SqlQuery Ident

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

-- | Use an identifier.
useIdent :: IdentInfo -> Ident -> Builder

-- | 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
[EEntity] :: Ident -> SqlExpr (Entity val)
[EAliasedEntity] :: Ident -> Ident -> SqlExpr (Entity val)
[EAliasedEntityReference] :: Ident -> Ident -> SqlExpr (Entity val)
[EMaybe] :: SqlExpr a -> SqlExpr (Maybe a)
[ERaw] :: NeedParens -> (IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Value a)
[EAliasedValue] :: Ident -> SqlExpr (Value a) -> SqlExpr (Value a)
[EValueReference] :: Ident -> (IdentInfo -> Ident) -> SqlExpr (Value a)
[ECompositeKey] :: (IdentInfo -> [Builder]) -> SqlExpr (Value a)
[EList] :: SqlExpr (Value a) -> SqlExpr (ValueList a)
[EEmptyList] :: SqlExpr (ValueList a)
[EOrderBy] :: OrderByType -> SqlExpr (Value a) -> SqlExpr OrderBy

-- | <i>Deprecated: Since 2.6.0: <a>rand</a> ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.</i>
[EOrderRandom] :: SqlExpr OrderBy
[EDistinctOn] :: SqlExpr (Value a) -> SqlExpr DistinctOn
[ESet] :: (SqlExpr (Entity val) -> SqlExpr (Value ())) -> SqlExpr (Update val)
[EPreprocessedFrom] :: a -> FromClause -> SqlExpr (PreprocessedFrom a)
[EInsert] :: Proxy a -> (IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Insertion a)
[EInsertFinal] :: PersistEntity a => SqlExpr (Insertion a) -> SqlExpr InsertFinal

-- | Phantom type used to mark a <tt>INSERT INTO</tt> query.
data InsertFinal
data NeedParens
Parens :: NeedParens
Never :: NeedParens
parensM :: NeedParens -> Builder -> Builder
data OrderByType
ASC :: OrderByType
DESC :: OrderByType
fieldName :: (PersistEntity val, PersistField typ) => IdentInfo -> EntityField val typ -> Builder
setAux :: (PersistEntity val, PersistField typ) => EntityField val typ -> (SqlExpr (Entity val) -> SqlExpr (Value typ)) -> SqlExpr (Update val)
sub :: PersistField a => Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
fromDBName :: IdentInfo -> DBName -> Builder
existsHelper :: SqlQuery () -> SqlExpr (Value Bool)
ifNotEmptyList :: SqlExpr (ValueList a) -> Bool -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)

-- | (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 <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 " = "
--   </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)

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

-- | (Internal) An unsafe SQL function to extract a subfield from a
--   compound field, e.g. datetime. See <a>unsafeSqlBinOp</a> for warnings.
--   
--   Since: 1.3.6.
unsafeSqlExtractSubField :: UnsafeSqlFunctionArgument a => Builder -> a -> SqlExpr (Value b)

-- | (Internal) A raw SQL function. Preserves parentheses around arguments.
--   See <a>unsafeSqlBinOp</a> for warnings.
unsafeSqlFunctionParens :: UnsafeSqlFunctionArgument a => Builder -> a -> SqlExpr (Value b)

-- | (Internal) An explicit SQL type cast using CAST(value as type). See
--   <a>unsafeSqlBinOp</a> for warnings.
unsafeSqlCastAs :: Text -> SqlExpr (Value a) -> SqlExpr (Value b)

-- | (Internal) This class allows <a>unsafeSqlFunction</a> to work with
--   different numbers of arguments; specifically it allows providing
--   arguments to a sql function via an n-tuple of <tt>SqlExpr (Value
--   _)</tt> values, which are not all necessarily required to be the same
--   type. There are instances for up to 10-tuples, but for sql functions
--   which take more than 10 arguments, you can also nest tuples, as e.g.
--   <tt>toArgList ((a,b),(c,d))</tt> is the same as <tt>toArgList
--   (a,b,c,d)</tt>.
class UnsafeSqlFunctionArgument a
toArgList :: UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]

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

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

-- | (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, MonadIO m1, MonadIO m2) => Mode -> SqlQuery a -> SqlReadT m1 (Acquire (ConduitT () r m2 ()))

-- | 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, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()

-- | 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>subSelect</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><a>select</a> $ from $ \p -&gt; return p</tt> alone is ambiguous,
--   but in the context of
--   
--   <pre>
--   do ps &lt;- <a>select</a> $
--            <a>from</a> $ \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, MonadIO m) => SqlQuery a -> SqlReadT m [r]

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

-- | (Internal) Execute an <tt>esqueleto</tt> statement inside
--   <tt>persistent</tt>'s <a>SqlPersistT</a> monad.
rawEsqueleto :: (MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> SqlQuery a -> ReaderT backend m Int64

-- | 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>
--   <a>delete</a> $
--   <a>from</a> $ \appointment -&gt;
--   <a>where_</a> (appointment <a>^.</a> AppointmentDate <a>&lt;.</a> <a>val</a> 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>
--   <a>delete</a> $
--   <a>from</a> $ \(appointment :: <a>SqlExpr</a> (<a>Entity</a> Appointment)) -&gt;
--   return ()
--   </pre>
delete :: MonadIO m => SqlQuery () -> SqlWriteT m ()

-- | Same as <a>delete</a>, but returns the number of rows affected.
deleteCount :: MonadIO m => SqlQuery () -> SqlWriteT 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>
--   <a>update</a> $ \p -&gt; do
--   <a>set</a> p [ PersonAge <a>=.</a> <a>just</a> (<a>val</a> thisYear) -. p <a>^.</a> PersonBorn ]
--   <a>where_</a> $ isNothing (p <a>^.</a> PersonAge)
--   </pre>
update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()

-- | Same as <a>update</a>, but returns the number of rows affected.
updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64
builderToText :: Builder -> Text

-- | (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), see the <a>renderQueryToText</a> function
--   (along with <a>renderQuerySelect</a>, <a>renderQueryUpdate</a>, etc).
toRawSql :: (SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryToText :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQuerySelect :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryDelete :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryUpdate :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryInsertInto :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | (Internal) Mode of query being converted by <a>toRawSql</a>.
data Mode
SELECT :: Mode
DELETE :: Mode
UPDATE :: Mode
INSERT_INTO :: Mode
uncommas :: [Builder] -> Builder
intersperseB :: Builder -> [Builder] -> Builder
uncommas' :: Monoid a => [(Builder, a)] -> (Builder, a)
makeInsertInto :: SqlSelect a r => IdentInfo -> Mode -> a -> (Builder, [PersistValue])
makeSelect :: SqlSelect a r => IdentInfo -> Mode -> DistinctClause -> a -> (Builder, [PersistValue])
makeFrom :: IdentInfo -> Mode -> [FromClause] -> (Builder, [PersistValue])
makeSet :: IdentInfo -> [SetClause] -> (Builder, [PersistValue])
makeWhere :: IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeGroupBy :: IdentInfo -> GroupByClause -> (Builder, [PersistValue])
makeHaving :: IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeOrderByNoNewline :: IdentInfo -> [OrderByClause] -> (Builder, [PersistValue])
makeOrderBy :: IdentInfo -> [OrderByClause] -> (Builder, [PersistValue])
makeLimit :: IdentInfo -> LimitClause -> [OrderByClause] -> (Builder, [PersistValue])
makeLocking :: LockingClause -> (Builder, [PersistValue])
parens :: Builder -> Builder
aliasedValueIdentToRawSql :: Ident -> IdentInfo -> (Builder, [PersistValue])
valueReferenceToRawSql :: Ident -> (IdentInfo -> Ident) -> IdentInfo -> (Builder, [PersistValue])
aliasedEntityColumnIdent :: Ident -> FieldDef -> IdentInfo -> Ident
aliasedColumnName :: Ident -> IdentInfo -> Text -> Builder

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

-- | Creates the variable part of the <tt>SELECT</tt> query and returns the
--   list of <a>PersistValue</a>s that will be given to <a>rawQuery</a>.
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 <tt>INSERT INTO</tt> clause instead.
sqlInsertInto :: SqlSelect a r => IdentInfo -> a -> (Builder, [PersistValue])
getEntityVal :: Proxy (SqlExpr (Entity a)) -> Proxy a

-- | Materialize a <tt>SqlExpr (Value a)</tt>.
materializeExpr :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
from3P :: Proxy (a, b, c) -> Proxy ((a, b), c)
from3 :: (a, b, c) -> ((a, b), c)
to3 :: ((a, b), c) -> (a, b, c)
from4P :: Proxy (a, b, c, d) -> Proxy ((a, b), (c, d))
from4 :: (a, b, c, d) -> ((a, b), (c, d))
to4 :: ((a, b), (c, d)) -> (a, b, c, d)
from5P :: Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e)
from5 :: (a, b, c, d, e) -> ((a, b), (c, d), e)
to5 :: ((a, b), (c, d), e) -> (a, b, c, d, e)
from6P :: Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f))
from6 :: (a, b, c, d, e, f) -> ((a, b), (c, d), (e, f))
to6 :: ((a, b), (c, d), (e, f)) -> (a, b, c, d, e, f)
from7P :: Proxy (a, b, c, d, e, f, g) -> Proxy ((a, b), (c, d), (e, f), g)
from7 :: (a, b, c, d, e, f, g) -> ((a, b), (c, d), (e, f), g)
to7 :: ((a, b), (c, d), (e, f), g) -> (a, b, c, d, e, f, g)
from8P :: Proxy (a, b, c, d, e, f, g, h) -> Proxy ((a, b), (c, d), (e, f), (g, h))
from8 :: (a, b, c, d, e, f, g, h) -> ((a, b), (c, d), (e, f), (g, h))
to8 :: ((a, b), (c, d), (e, f), (g, h)) -> (a, b, c, d, e, f, g, h)
from9P :: Proxy (a, b, c, d, e, f, g, h, i) -> Proxy ((a, b), (c, d), (e, f), (g, h), i)
from9 :: (a, b, c, d, e, f, g, h, i) -> ((a, b), (c, d), (e, f), (g, h), i)
to9 :: ((a, b), (c, d), (e, f), (g, h), i) -> (a, b, c, d, e, f, g, h, i)
from10P :: Proxy (a, b, c, d, e, f, g, h, i, j) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
from10 :: (a, b, c, d, e, f, g, h, i, j) -> ((a, b), (c, d), (e, f), (g, h), (i, j))
to10 :: ((a, b), (c, d), (e, f), (g, h), (i, j)) -> (a, b, c, d, e, f, g, h, i, j)
from11P :: Proxy (a, b, c, d, e, f, g, h, i, j, k) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
to11 :: ((a, b), (c, d), (e, f), (g, h), (i, j), k) -> (a, b, c, d, e, f, g, h, i, j, k)
from12P :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
to12 :: ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l)) -> (a, b, c, d, e, f, g, h, i, j, k, l)
from13P :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
to13 :: ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m)
from14P :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
to14 :: ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
from15P :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
to15 :: ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
from16P :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
to16 :: ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)

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

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

-- | Renders an expression into <tt>Text</tt>. Only useful for creating a
--   textual representation of the clauses passed to an <a>On</a> clause.
renderExpr :: SqlBackend -> SqlExpr (Value Bool) -> Text

-- | An exception thrown by <tt>RenderExpr</tt> - it's not designed to
--   handle composite keys, and will blow up if you give it one.
data RenderExprException
RenderExprUnexpectedECompositeKey :: Text -> RenderExprException
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.RenderExprException
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.Ident
instance GHC.Classes.Ord Database.Esqueleto.Internal.Internal.Ident
instance GHC.Classes.Eq Database.Esqueleto.Internal.Internal.Ident
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.EsqueletoError
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.SqlBinOpCompositeError
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.UnexpectedCaseError
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.UnexpectedValueError
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.OnClauseWithoutMatchingJoinException
instance GHC.Classes.Ord Database.Esqueleto.Internal.Internal.OnClauseWithoutMatchingJoinException
instance GHC.Classes.Eq Database.Esqueleto.Internal.Internal.OnClauseWithoutMatchingJoinException
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.JoinKind
instance GHC.Classes.Eq Database.Esqueleto.Internal.Internal.JoinKind
instance GHC.Show.Show a => GHC.Show.Show (Database.Esqueleto.Internal.Internal.ValueList a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.Esqueleto.Internal.Internal.ValueList a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.Esqueleto.Internal.Internal.ValueList a)
instance GHC.Show.Show a => GHC.Show.Show (Database.Esqueleto.Internal.Internal.Value a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.Esqueleto.Internal.Internal.Value a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.Esqueleto.Internal.Internal.Value a)
instance GHC.Exception.Type.Exception Database.Esqueleto.Internal.Internal.RenderExprException
instance Database.Esqueleto.Internal.Internal.SqlSelect (Database.Esqueleto.Internal.Internal.SqlExpr Database.Esqueleto.Internal.Internal.InsertFinal) Database.Esqueleto.Internal.Internal.InsertFinal
instance Database.Esqueleto.Internal.Internal.SqlSelect () ()
instance Database.Persist.Class.PersistEntity.PersistEntity a => Database.Esqueleto.Internal.Internal.SqlSelect (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity a)) (Database.Persist.Class.PersistEntity.Entity a)
instance Database.Persist.Class.PersistEntity.PersistEntity a => Database.Esqueleto.Internal.Internal.SqlSelect (Database.Esqueleto.Internal.Internal.SqlExpr (GHC.Maybe.Maybe (Database.Persist.Class.PersistEntity.Entity a))) (GHC.Maybe.Maybe (Database.Persist.Class.PersistEntity.Entity a))
instance Database.Persist.Class.PersistField.PersistField a => Database.Esqueleto.Internal.Internal.SqlSelect (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value a)) (Database.Esqueleto.Internal.Internal.Value a)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b) (ra, rb)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c) (ra, rb, rc)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d) (ra, rb, rc, rd)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d, e) (ra, rb, rc, rd, re)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d, e, f) (ra, rb, rc, rd, re, rf)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d, e, f, g) (ra, rb, rc, rd, re, rf, rg)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d, e, f, g, h) (ra, rb, rc, rd, re, rf, rg, rh)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri) => Database.Esqueleto.Internal.Internal.SqlSelect (a, b, c, d, e, f, g, h, i) (ra, rb, rc, rd, re, rf, rg, rh, ri)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk, Database.Esqueleto.Internal.Internal.SqlSelect l rl) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk, Database.Esqueleto.Internal.Internal.SqlSelect l rl, Database.Esqueleto.Internal.Internal.SqlSelect m rm) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk, Database.Esqueleto.Internal.Internal.SqlSelect l rl, Database.Esqueleto.Internal.Internal.SqlSelect m rm, Database.Esqueleto.Internal.Internal.SqlSelect n rn) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk, Database.Esqueleto.Internal.Internal.SqlSelect l rl, Database.Esqueleto.Internal.Internal.SqlSelect m rm, Database.Esqueleto.Internal.Internal.SqlSelect n rn, Database.Esqueleto.Internal.Internal.SqlSelect o ro) => Database.Esqueleto.Internal.Internal.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.Internal.SqlSelect a ra, Database.Esqueleto.Internal.Internal.SqlSelect b rb, Database.Esqueleto.Internal.Internal.SqlSelect c rc, Database.Esqueleto.Internal.Internal.SqlSelect d rd, Database.Esqueleto.Internal.Internal.SqlSelect e re, Database.Esqueleto.Internal.Internal.SqlSelect f rf, Database.Esqueleto.Internal.Internal.SqlSelect g rg, Database.Esqueleto.Internal.Internal.SqlSelect h rh, Database.Esqueleto.Internal.Internal.SqlSelect i ri, Database.Esqueleto.Internal.Internal.SqlSelect j rj, Database.Esqueleto.Internal.Internal.SqlSelect k rk, Database.Esqueleto.Internal.Internal.SqlSelect l rl, Database.Esqueleto.Internal.Internal.SqlSelect m rm, Database.Esqueleto.Internal.Internal.SqlSelect n rn, Database.Esqueleto.Internal.Internal.SqlSelect o ro, Database.Esqueleto.Internal.Internal.SqlSelect p rp) => Database.Esqueleto.Internal.Internal.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 Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument ()
instance (a GHC.Types.~ Database.Esqueleto.Internal.Internal.Value b) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (Database.Esqueleto.Internal.Internal.SqlExpr a)
instance Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument [a]
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument f) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e, f)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument f, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument g) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument f, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument g, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument h) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument f, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument g, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument h, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument i) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h, i)
instance (Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument a, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument b, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument c, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument d, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument e, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument f, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument g, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument h, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument i, Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument j) => Database.Esqueleto.Internal.Internal.UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h, i, j)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c, Database.Esqueleto.Internal.Internal.ToSomeValues d) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c, d)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c, Database.Esqueleto.Internal.Internal.ToSomeValues d, Database.Esqueleto.Internal.Internal.ToSomeValues e) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c, d, e)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c, Database.Esqueleto.Internal.Internal.ToSomeValues d, Database.Esqueleto.Internal.Internal.ToSomeValues e, Database.Esqueleto.Internal.Internal.ToSomeValues f) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c, d, e, f)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c, Database.Esqueleto.Internal.Internal.ToSomeValues d, Database.Esqueleto.Internal.Internal.ToSomeValues e, Database.Esqueleto.Internal.Internal.ToSomeValues f, Database.Esqueleto.Internal.Internal.ToSomeValues g) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Internal.Internal.ToSomeValues a, Database.Esqueleto.Internal.Internal.ToSomeValues b, Database.Esqueleto.Internal.Internal.ToSomeValues c, Database.Esqueleto.Internal.Internal.ToSomeValues d, Database.Esqueleto.Internal.Internal.ToSomeValues e, Database.Esqueleto.Internal.Internal.ToSomeValues f, Database.Esqueleto.Internal.Internal.ToSomeValues g, Database.Esqueleto.Internal.Internal.ToSomeValues h) => Database.Esqueleto.Internal.Internal.ToSomeValues (a, b, c, d, e, f, g, h)
instance Database.Esqueleto.Internal.Internal.ToSomeValues (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value a))
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity val)) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity val))
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.SqlExpr (GHC.Maybe.Maybe (Database.Persist.Class.PersistEntity.Entity val))) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.SqlExpr (GHC.Maybe.Maybe (Database.Persist.Class.PersistEntity.Entity val)))
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.InnerJoin a b) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.InnerJoin a b)
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.CrossJoin a b) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.CrossJoin a b)
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.LeftOuterJoin a b) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.LeftOuterJoin a b)
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.RightOuterJoin a b) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.RightOuterJoin a b)
instance Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.FullOuterJoin a b) => Database.Esqueleto.Internal.Internal.From (Database.Esqueleto.Internal.Internal.FullOuterJoin a b)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b) => Database.Esqueleto.Internal.Internal.From (a, b)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c) => Database.Esqueleto.Internal.Internal.From (a, b, c)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c, Database.Esqueleto.Internal.Internal.From d) => Database.Esqueleto.Internal.Internal.From (a, b, c, d)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c, Database.Esqueleto.Internal.Internal.From d, Database.Esqueleto.Internal.Internal.From e) => Database.Esqueleto.Internal.Internal.From (a, b, c, d, e)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c, Database.Esqueleto.Internal.Internal.From d, Database.Esqueleto.Internal.Internal.From e, Database.Esqueleto.Internal.Internal.From f) => Database.Esqueleto.Internal.Internal.From (a, b, c, d, e, f)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c, Database.Esqueleto.Internal.Internal.From d, Database.Esqueleto.Internal.Internal.From e, Database.Esqueleto.Internal.Internal.From f, Database.Esqueleto.Internal.Internal.From g) => Database.Esqueleto.Internal.Internal.From (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Internal.Internal.From a, Database.Esqueleto.Internal.Internal.From b, Database.Esqueleto.Internal.Internal.From c, Database.Esqueleto.Internal.Internal.From d, Database.Esqueleto.Internal.Internal.From e, Database.Esqueleto.Internal.Internal.From f, Database.Esqueleto.Internal.Internal.From g, Database.Esqueleto.Internal.Internal.From h) => Database.Esqueleto.Internal.Internal.From (a, b, c, d, e, f, g, h)
instance (Database.Persist.Class.PersistEntity.PersistEntity val, Database.Persist.Class.PersistStore.BackendCompatible Database.Persist.Sql.Types.Internal.SqlBackend (Database.Persist.Class.PersistEntity.PersistEntityBackend val)) => Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity val))
instance (Database.Persist.Class.PersistEntity.PersistEntity val, Database.Persist.Class.PersistStore.BackendCompatible Database.Persist.Sql.Types.Internal.SqlBackend (Database.Persist.Class.PersistEntity.PersistEntityBackend val)) => Database.Esqueleto.Internal.Internal.FromPreprocess (Database.Esqueleto.Internal.Internal.SqlExpr (GHC.Maybe.Maybe (Database.Persist.Class.PersistEntity.Entity val)))
instance (Database.Esqueleto.Internal.Internal.FromPreprocess a, Database.Esqueleto.Internal.Internal.FromPreprocess b, Database.Esqueleto.Internal.Internal.IsJoinKind join) => Database.Esqueleto.Internal.Internal.FromPreprocess (join a b)
instance GHC.Base.Functor Database.Esqueleto.Internal.Internal.SqlQuery
instance GHC.Base.Monad Database.Esqueleto.Internal.Internal.SqlQuery
instance GHC.Base.Applicative Database.Esqueleto.Internal.Internal.SqlQuery
instance GHC.Base.Semigroup Database.Esqueleto.Internal.Internal.SideData
instance GHC.Base.Monoid Database.Esqueleto.Internal.Internal.SideData
instance GHC.Base.Semigroup Database.Esqueleto.Internal.Internal.GroupByClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Internal.GroupByClause
instance GHC.Base.Semigroup Database.Esqueleto.Internal.Internal.DistinctClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Internal.DistinctClause
instance GHC.Base.Semigroup Database.Esqueleto.Internal.Internal.WhereClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Internal.WhereClause
instance GHC.Show.Show Database.Esqueleto.Internal.Internal.FromClause
instance GHC.Base.Semigroup Database.Esqueleto.Internal.Internal.LimitClause
instance GHC.Base.Monoid Database.Esqueleto.Internal.Internal.LimitClause
instance GHC.Exception.Type.Exception Database.Esqueleto.Internal.Internal.EsqueletoError
instance (a GHC.Types.~ GHC.Types.Char) => Database.Esqueleto.Internal.Internal.SqlString [a]
instance Database.Esqueleto.Internal.Internal.SqlString Data.Text.Internal.Text
instance Database.Esqueleto.Internal.Internal.SqlString Data.Text.Internal.Lazy.Text
instance Database.Esqueleto.Internal.Internal.SqlString Data.ByteString.Internal.ByteString
instance Database.Esqueleto.Internal.Internal.SqlString Text.Blaze.Html.Html
instance Database.Esqueleto.Internal.Internal.SqlString a => Database.Esqueleto.Internal.Internal.SqlString (GHC.Maybe.Maybe a)
instance GHC.Exception.Type.Exception Database.Esqueleto.Internal.Internal.OnClauseWithoutMatchingJoinException
instance Database.Esqueleto.Internal.Internal.IsJoinKind Database.Esqueleto.Internal.Internal.InnerJoin
instance Database.Esqueleto.Internal.Internal.IsJoinKind Database.Esqueleto.Internal.Internal.CrossJoin
instance Database.Esqueleto.Internal.Internal.IsJoinKind Database.Esqueleto.Internal.Internal.LeftOuterJoin
instance Database.Esqueleto.Internal.Internal.IsJoinKind Database.Esqueleto.Internal.Internal.RightOuterJoin
instance Database.Esqueleto.Internal.Internal.IsJoinKind Database.Esqueleto.Internal.Internal.FullOuterJoin
instance Database.Esqueleto.Internal.Internal.FinalResult (Database.Persist.Class.PersistEntity.Unique val)
instance Database.Esqueleto.Internal.Internal.FinalResult b => Database.Esqueleto.Internal.Internal.FinalResult (a -> b)
instance GHC.Base.Functor Database.Esqueleto.Internal.Internal.Value
instance GHC.Base.Applicative Database.Esqueleto.Internal.Internal.Value
instance GHC.Base.Monad Database.Esqueleto.Internal.Internal.Value


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

-- | <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 left fixity.</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>
--   <a>from</a> $ \person -&gt; ...
--   <a>from</a> $ \(person, blogPost) -&gt; ...
--   <a>from</a> $ \(p `<a>LeftOuterJoin</a>` mb) -&gt; ...
--   <a>from</a> $ \(p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2) -&gt; ...
--   <a>from</a> $ \((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
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   (p1 `<a>InnerJoin</a>` (f `<a>InnerJoin</a>` p2)) ::
--     :: (...) =&gt; InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   </pre>
--   
--   Note that some backends may not support all kinds of <tt>JOIN</tt>s.
from :: From a => (a -> SqlQuery b) -> SqlQuery 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>.
newtype Value a
Value :: a -> Value a
[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 <a>subList_select</a>,
--   <a>valList</a>, <a>in_</a> and <a>exists</a>).
newtype ValueList a
ValueList :: a -> ValueList a

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

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

-- | 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
infixl 2 `InnerJoin`
infixl 2 `InnerJoin`

-- | 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
infixl 2 `CrossJoin`
infixl 2 `CrossJoin`

-- | Data type that represents a <tt>LEFT OUTER JOIN</tt>. For example,
--   
--   <pre>
--   select $
--   <a>from</a> $ \(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
infixl 2 `LeftOuterJoin`
infixl 2 `LeftOuterJoin`

-- | 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
infixl 2 `RightOuterJoin`
infixl 2 `RightOuterJoin`

-- | 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
infixl 2 `FullOuterJoin`
infixl 2 `FullOuterJoin`

-- | 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 used by <a>distinctOn</a> and <a>don</a>.
data DistinctOn

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

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

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

-- | <tt>FOR UPDATE</tt> syntax. Supported by MySQL, Oracle and PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdate :: LockingKind

-- | <tt>FOR UPDATE SKIP LOCKED</tt> syntax. Supported by MySQL, Oracle and
--   PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdateSkipLocked :: LockingKind

-- | <tt>FOR SHARE</tt> syntax. Supported by PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForShare :: LockingKind

-- | <tt>LOCK IN SHARE MODE</tt> syntax. Supported by MySQL.
--   
--   <i>Since: 2.2.7</i>
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 <tt>newtype</tt>, feel free to make
--   it an instance of this class.
--   
--   <i>Since: 2.4.0</i>
class PersistField a => SqlString a

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

-- | Convert from the key of the BaseEnt(ity) to the key of the child
--   entity. This function is not actually called, but that it typechecks
--   proves this operation is safe.
toBaseIdWitness :: ToBaseId ent => Key (BaseEnt ent) -> Key ent

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

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

-- | (Internal) Reify a <tt>JoinKind</tt> from a <tt>JOIN</tt>. This
--   function is non-strict.
reifyJoinKind :: IsJoinKind join => join a b -> JoinKind
class BackendCompatible sup sub
projectBackend :: BackendCompatible sup sub => sub -> sup

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

-- | (Internal) Class that implements the <tt>JOIN</tt> <a>from</a> magic
--   (see <a>fromStart</a>).
class FromPreprocess a

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

-- | Syntax sugar for <a>case_</a>.
--   
--   <i>Since: 2.1.2</i>
then_ :: ()

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

-- | <tt>WHERE</tt> clause: restrict the query's result.
where_ :: SqlExpr (Value Bool) -> SqlQuery ()

-- | An <tt>ON</tt> clause, useful to describe how two tables are related.
--   Cross joins and tuple-joins do not need an <a>on</a> clause, but
--   <a>InnerJoin</a> and the various outer joins do.
--   
--   If you don't include an <a>on</a> clause (or include too many!) then a
--   runtime exception will be thrown.
--   
--   As an example, consider this simple join:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   We need to specify the clause for joining the two columns together. If
--   we had this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>CrossJoin</a>` bar) -&gt; do
--     ...
--   </pre>
--   
--   Then we can safely omit the <a>on</a> clause, because the cross join
--   will make pairs of all records possible.
--   
--   You can do multiple <a>on</a> clauses in a query. This query joins
--   three tables, and has two <a>on</a> clauses:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   Old versions of esqueleto required that you provide the <a>on</a>
--   clauses in reverse order. This restriction has been lifted - you can
--   now provide <a>on</a> clauses in any order, and the SQL should work
--   itself out. The above query is now totally equivalent to this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     ...
--   </pre>
on :: SqlExpr (Value Bool) -> SqlQuery ()

-- | <tt>GROUP BY</tt> clause. You can enclose multiple columns in a tuple.
--   
--   <pre>
--   select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> (bar <a>^.</a> BarId, bar <a>^.</a> BarName)
--     return (bar <a>^.</a> BarId, bar <a>^.</a> BarName, countRows)
--   </pre>
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   <tt>let</tt> to restrict the more general <a>countRows</a> to
--   <tt>SqlSqlExpr (Value Int)</tt> to avoid ambiguity---the second use of
--   <a>countRows</a> has its type restricted by the <tt>:: Int</tt>
--   below):
--   
--   <pre>
--   r &lt;- select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> $ bar <a>^.</a> BarName
--     let countRows' = <a>countRows</a>
--     <a>orderBy</a> [<a>asc</a> countRows']
--     return (bar <a>^.</a> BarName, countRows')
--   forM_ r $ \(<a>Value</a> name, <a>Value</a> count) -&gt; do
--     print name
--     print (count :: Int)
--   </pre>
--   
--   <h3>Need more columns?</h3>
--   
--   The <a>ToSomeValues</a> class is defined for <a>SqlExpr</a> and tuples
--   of <a>SqlExpr</a>s. We only have definitions for up to 8 elements in a
--   tuple right now, so it's possible that you may need to have more than
--   8 elements.
--   
--   For example, consider a query with a <a>groupBy</a> call like this:
--   
--   <pre>
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   </pre>
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   <pre>
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   </pre>
groupBy :: ToSomeValues a => a -> SqlQuery ()

-- | <tt>ORDER BY</tt> clause. See also <a>asc</a> and <a>desc</a>.
--   
--   Multiple calls to <a>orderBy</a> get concatenated on the final query,
--   including <a>distinctOnOrderBy</a>.
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()

-- | <tt>ORDER BY random()</tt> clause.
--   
--   <i>Since: 1.3.10</i>

-- | <i>Deprecated: Since 2.6.0: <a>rand</a> ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.</i>
rand :: SqlExpr OrderBy

-- | Ascending order of this field or SqlExpression.
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | Descending order of this field or SqlExpression.
desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | <tt>LIMIT</tt>. Limit the number of returned rows.
limit :: Int64 -> SqlQuery ()

-- | <tt>OFFSET</tt>. Usually used with <a>limit</a>.
offset :: Int64 -> SqlQuery ()

-- | <tt>DISTINCT</tt>. Change the current <tt>SELECT</tt> into <tt>SELECT
--   DISTINCT</tt>. For example:
--   
--   <pre>
--   select $ distinct $
--     <a>from</a> \foo -&gt; do
--     ...
--   </pre>
--   
--   Note that this also has the same effect:
--   
--   <pre>
--   select $
--     <a>from</a> \foo -&gt; do
--     distinct (return ())
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinct :: SqlQuery a -> SqlQuery a

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

-- | Erase an SqlExpression's type so that it's suitable to be used by
--   <a>distinctOn</a>.
--   
--   <i>Since: 2.2.4</i>
don :: SqlExpr (Value a) -> SqlExpr DistinctOn

-- | A convenience function that calls both <a>distinctOn</a> and
--   <a>orderBy</a>. In other words,
--   
--   <pre>
--   <a>distinctOnOrderBy</a> [asc foo, desc bar, desc quux] $ do
--     ...
--   </pre>
--   
--   is the same as:
--   
--   <pre>
--   <a>distinctOn</a> [don foo, don  bar, don  quux] $ do
--     <a>orderBy</a>  [asc foo, desc bar, desc quux]
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a

-- | <tt>HAVING</tt>.
--   
--   <i>Since: 1.2.2</i>
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a
--   simple value so should be used only when the <tt>SELECT</tt> query is
--   guaranteed to return just one row.
--   
--   Deprecated in 3.2.0.

-- | <i>Deprecated: sub_select sub_select is an unsafe function to use. If
--   used with a SqlQuery that returns 0 results, then it may return NULL
--   despite not mentioning Maybe in the return type. If it returns more
--   than 1 result, then it will throw a SQL error. Instead, consider using
--   one of the following alternatives: - subSelect: attaches a LIMIT 1 and
--   the Maybe return type, totally safe. - subSelectMaybe: Attaches a
--   LIMIT 1, useful for a query that already has a Maybe in the return
--   type. - subSelectCount: Performs a count of the query - this is always
--   safe. - subSelectUnsafe: Performs no checks or guarantees. Safe to use
--   with countRows and friends.</i>
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Project a field of an entity.
(^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
infixl 9 ^.

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

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

-- | <tt>IS NULL</tt> comparison.
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)

-- | Analogous to <a>Just</a>, promotes a value of type <tt>typ</tt> into
--   one of type <tt>Maybe typ</tt>. It should hold that <tt><a>val</a> .
--   Just === just . <a>val</a></tt>.
just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))

-- | <tt>NULL</tt> value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested <a>Maybe</a>s in a <a>Value</a> into one. This is useful
--   when calling aggregate functions on nullable fields.
joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))

-- | Project an SqlExpression that may be null, guarding against null
--   cases.
withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a

-- | <tt>COUNT(*)</tt> value.
countRows :: Num a => SqlExpr (Value a)

-- | <tt>COUNT</tt>.
count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)

-- | <tt>COUNT(DISTINCT x)</tt>.
--   
--   <i>Since: 2.4.1</i>
countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 ==.
(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >=.
(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >.
(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <=.
(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <.
(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 !=.
(&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 3 &&.
(||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 2 ||.

-- | <tt>BETWEEN</tt>.
--   
--   @since: 3.1.0
between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 +.
(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 -.
(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 /.
(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 *.

-- | <i>Deprecated: Since 2.6.0: <a>random_</a> is not uniform across all
--   databases! Please use a specific one such as <a>random_</a>,
--   <a>random_</a>, or <a>random_</a></i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (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.
--   
--   <i>Caveat</i>: Trying to use <tt>castNum</tt> from <tt>Double</tt> to
--   <tt>Int</tt> will not result in an integer, the original fractional
--   number will still be used! Use <a>round_</a>, <a>ceiling_</a> or
--   <a>floor_</a> instead.
--   
--   <i>Safety</i>: This operation is mostly safe due to the <a>Num</a>
--   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
--   <tt>persistent</tt> not being able to parse it.
--   
--   <i>Since: 2.2.9</i>
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

-- | Same as <a>castNum</a>, but for nullable values.
--   
--   <i>Since: 2.2.9</i>
castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))

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

-- | Like <tt>coalesce</tt>, but takes a non-nullable SqlExpression placed
--   at the end of the SqlExpression list, which guarantees a non-NULL
--   result.
--   
--   <i>Since: 1.4.3</i>
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)

-- | <tt>LOWER</tt> function.
lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>UPPER</tt> function. <i>Since: 3.3.0</i>
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>TRIM</tt> function. <i>Since: 3.3.0</i>
trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LTRIM</tt> function. <i>Since: 3.3.0</i>
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>RTRIM</tt> function. <i>Since: 3.3.0</i>
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LENGTH</tt> function. <i>Since: 3.3.0</i>
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)

-- | <tt>LEFT</tt> function. <i>Since: 3.3.0</i>
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>RIGHT</tt> function. <i>Since: 3.3.0</i>
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>LIKE</tt> operator.
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `like`

-- | <tt>ILIKE</tt> operator (case-insensitive <tt>LIKE</tt>).
--   
--   Supported by PostgreSQL only.
--   
--   <i>Since: 2.2.3</i>
ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `ilike`

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

-- | The <tt>CONCAT</tt> function with a variable number of parameters.
--   Supported by MySQL and PostgreSQL.
concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)

-- | The <tt>||</tt> string concatenation operator (named after Haskell's
--   <a>++</a> in order to avoid naming clash with <a>||.</a>). Supported
--   by SQLite and PostgreSQL.
(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
infixr 5 ++.

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a list
--   of values.
subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

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

-- | Same as <a>just</a> but for <a>ValueList</a>. Most of the time you
--   won't need it, though, because you can use <a>just</a> from inside
--   <a>subList_select</a> or <a>Just</a> from inside <a>valList</a>.
--   
--   <i>Since: 2.2.12</i>
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

-- | <tt>NOT IN</tt> operator.
notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)

-- | <tt>EXISTS</tt> operator. For example:
--   
--   <pre>
--   select $
--   <a>from</a> $ \person -&gt; do
--   <a>where_</a> $ <a>exists</a> $
--            <a>from</a> $ \post -&gt; do
--            <a>where_</a> (post <a>^.</a> BlogPostAuthorId <a>==.</a> person <a>^.</a> PersonId)
--   return person
--   </pre>
exists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>NOT EXISTS</tt> operator.
notExists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>SET</tt> clause used on <tt>UPDATE</tt>s. Note that while it's not
--   a type error to use this function on a <tt>SELECT</tt>, it will most
--   certainly result in a runtime error.
set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Update val)] -> SqlQuery ()
(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Update val)
infixr 3 =.
(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 +=.
(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 -=.
(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 *=.
(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 /=.

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

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

-- | Apply a <a>PersistField</a> constructor to <tt>SqlExpr Value</tt>
--   arguments.
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

-- | Apply extra <tt>SqlExpr Value</tt> arguments to a <a>PersistField</a>
--   constructor
(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. The query
--   passed to this function will only return a single result - it has a
--   <tt>LIMIT 1</tt> passed in to the query to make it safe, and the
--   return type is <a>Maybe</a> to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing <tt><a>joinV</a> . <a>subSelect</a></tt>,
--   then consider using <a>subSelectMaybe</a>.
--   
--   If you're performing a <a>countRows</a>, then you can use
--   <a>subSelectCount</a> which is safe.
--   
--   If you know that the subquery will always return exactly one row (eg a
--   foreign key constraint guarantees that you'll get exactly one row),
--   then consider <a>subSelectUnsafe</a>, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is a shorthand for the common <tt><a>joinV</a> . <a>subSelect</a></tt>
--   idiom, where you are calling <a>subSelect</a> on an expression that
--   would be <a>Maybe</a> already.
--   
--   As an example, you would use this function when calling <a>sum_</a> or
--   <a>max_</a>, which have <a>Maybe</a> in the result type (for a 0 row
--   query).
subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))

-- | Performs a <tt>COUNT</tt> of the given query in a <tt>subSelect</tt>
--   manner. This is always guaranteed to return a result value, and is
--   completely safe.
subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a> that returns a
--   list. This is an alias for <a>subList_select</a> and is provided for
--   symmetry with the other safe subselect functions.
subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

-- | Performs a sub-select using the given foreign key on the entity. This
--   is useful to extract values that are known to be present by the
--   database schema.
--   
--   As an example, consider the following persistent definition:
--   
--   <pre>
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   </pre>
--   
--   The following query will return the name of the user.
--   
--   <pre>
--   getUserWithName =
--       <a>select</a> $
--       <a>from</a> $ user -&gt;
--       <a>pure</a> (user, <a>subSelectForeign</a> user UserProfile (^. ProfileName)
--   </pre>
subSelectForeign :: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) => SqlExpr (Entity val2) -> EntityField val2 (Key val1) -> (SqlExpr (Entity val1) -> SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is unsafe, because it can throw runtime exceptions in two cases:
--   
--   <ol>
--   <li>If the query passed has 0 result rows, then it will return a
--   <tt>NULL</tt> value. The <tt>persistent</tt> parsing operations will
--   fail on an unexpected <tt>NULL</tt>.</li>
--   <li>If the query passed returns more than one row, then the SQL engine
--   will fail with an error like "More than one row returned by a subquery
--   used as an expression".</li>
--   </ol>
--   
--   This function is safe if you guarantee that exactly one row will be
--   returned, or if the result already has a <a>Maybe</a> type for some
--   reason.
--   
--   For variants with the safety encoded already, see <a>subSelect</a> and
--   <a>subSelectMaybe</a>. For the most common safe use of this, see
--   <a>subSelectCount</a>.
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

module Database.Esqueleto.Experimental

-- | Data type that represents SQL set operations. This includes
--   <tt>UNION</tt>, <tt>UNION</tt> <tt>ALL</tt>, <tt>EXCEPT</tt>, and
--   <tt>INTERSECT</tt>. This data type is defined as a binary tree, with
--   <tt>SelectQuery</tt> on the leaves.
--   
--   Each constructor corresponding to the aforementioned set operations
--   can be used as an infix function in a <tt>from</tt> to help with
--   readability and lead to code that closely resembles the underlying
--   SQL. For example,
--   
--   <pre>
--   select $ from $
--     (SelectQuery ...)
--     `Union`
--     (SelectQuery ...)
--   </pre>
--   
--   is translated into
--   
--   <pre>
--   SELECT * FROM (
--     (SELECT * FROM ...)
--     UNION
--     (SELECT * FROM ...)
--   )
--   </pre>
--   
--   <tt>SelectQuery</tt> can be used without any of the set operations to
--   construct a subquery. This can be used in <tt>JOIN</tt> trees. For
--   example,
--   
--   <pre>
--   select $ from $
--     Table @SomeTable
--     `InnerJoin` (SelectQuery ...)
--     `on` ...
--   </pre>
--   
--   is translated into
--   
--   <pre>
--   SELECT *
--   FROM SomeTable
--   INNER JOIN (SELECT * FROM ...)
--   ON ...
--   </pre>
data SqlSetOperation a
Union :: SqlSetOperation a -> SqlSetOperation a -> SqlSetOperation a
UnionAll :: SqlSetOperation a -> SqlSetOperation a -> SqlSetOperation a
Except :: SqlSetOperation a -> SqlSetOperation a -> SqlSetOperation a
Intersect :: SqlSetOperation a -> SqlSetOperation a -> SqlSetOperation a
SelectQuery :: SqlQuery a -> SqlSetOperation a

-- | Data type that represents the syntax of a <tt>JOIN</tt> tree. In
--   practice, only the <tt>Table</tt> constructor is used directly when
--   writing queries. For example,
--   
--   <pre>
--   select $ from $ Table @People
--   </pre>
data From a
[Table] :: PersistEntity ent => From (SqlExpr (Entity ent))
[SubQuery] :: (SqlSelect a' r, SqlSelect a'' r', ToAlias a, a' ~ ToAliasT a, ToAliasReference a', ToAliasReferenceT a' ~ a'') => SqlQuery a -> From a''
[SqlSetOperation] :: (SqlSelect a' r, ToAlias a, a' ~ ToAliasT a, ToAliasReference a', ToAliasReferenceT a' ~ a'') => SqlSetOperation a -> From a''
[InnerJoinFrom] :: From a -> (From b, (a :& b) -> SqlExpr (Value Bool)) -> From (a :& b)
[CrossJoinFrom] :: From a -> From b -> From (a :& b)
[LeftJoinFrom] :: ToMaybe b => From a -> (From b, (a :& ToMaybeT b) -> SqlExpr (Value Bool)) -> From (a :& ToMaybeT b)
[RightJoinFrom] :: ToMaybe a => From a -> (From b, (ToMaybeT a :& b) -> SqlExpr (Value Bool)) -> From (ToMaybeT a :& b)
[FullJoinFrom] :: (ToMaybe a, ToMaybe b) => From a -> (From b, (ToMaybeT a :& ToMaybeT b) -> SqlExpr (Value Bool)) -> From (ToMaybeT a :& ToMaybeT b)

-- | An <tt>ON</tt> clause that describes how two tables are related. This
--   should be used as an infix operator after a <tt>JOIN</tt>. For
--   example,
--   
--   <pre>
--   select $
--   from $ Table @Person
--   `InnerJoin` Table @BlogPost
--   `on` (\(p :&amp; bP) -&gt;
--           p ^. PersonId ==. bP ^. BlogPostAuthorId)
--   </pre>
on :: ToFrom a => a -> (b -> SqlExpr (Value Bool)) -> (a, b -> SqlExpr (Value Bool))
infix 9 `on`

-- | <tt>FROM</tt> clause, used to bring entities into scope.
--   
--   Internally, this function uses the <a>From</a> datatype and the
--   <a>ToFrom</a> typeclass. Unlike the old <a>from</a>, this does not
--   take a function as a parameter, but rather a value that represents a
--   <tt>JOIN</tt> tree constructed out of instances of <a>ToFrom</a>. This
--   implementation eliminates certain types of runtime errors by
--   preventing the construction of invalid SQL (e.g. illegal
--   nested-<tt>from</tt>).
from :: ToFrom a => a -> SqlQuery (ToFromT a)

-- | A left-precedence pair. Pronounced "and". Used to represent
--   expressions that have been joined together.
--   
--   The precedence behavior can be demonstrated by:
--   
--   <pre>
--   a :&amp; b :&amp; c == ((a :&amp; b) :&amp; c)
--   </pre>
--   
--   See the examples at the beginning of this module to see how this
--   operator is used in <tt>JOIN</tt> operations.
data (:&) a b
(:&) :: a -> b -> (:&) a b
infixl 2 :&
infixl 2 :&
class ToFrom a
toFrom :: ToFrom a => a -> From (ToFromT a)
type family ToFromT a
class ToMaybe a
toMaybe :: ToMaybe a => a -> ToMaybeT a
type family ToMaybeT a
class ToAlias a
toAlias :: ToAlias a => a -> SqlQuery (ToAliasT a)
type family ToAliasT a
class ToAliasReference a
toAliasReference :: ToAliasReference a => Ident -> a -> SqlQuery (ToAliasReferenceT a)
type family ToAliasReferenceT a
instance Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Experimental.From a)
instance Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.InnerJoin a b)
instance Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.LeftOuterJoin a b)
instance Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.RightOuterJoin a b)
instance Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.FullOuterJoin a b)
instance (Database.Esqueleto.Internal.Internal.SqlSelect a' r, Database.Esqueleto.Internal.Internal.SqlSelect a'' r', Database.Esqueleto.Experimental.ToAlias a, a' GHC.Types.~ Database.Esqueleto.Experimental.ToAliasT a, Database.Esqueleto.Experimental.ToAliasReference a', Database.Esqueleto.Experimental.ToAliasReferenceT a' GHC.Types.~ a'') => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Experimental.SqlSetOperation a)
instance (Database.Esqueleto.Experimental.ToFrom a, Database.Esqueleto.Experimental.ToFromT a GHC.Types.~ a', Database.Esqueleto.Experimental.ToFrom b, Database.Esqueleto.Experimental.ToFromT b GHC.Types.~ b', Database.Esqueleto.Experimental.ToMaybe b', mb GHC.Types.~ Database.Esqueleto.Experimental.ToMaybeT b') => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.LeftOuterJoin a (b, (a' Database.Esqueleto.Experimental.:& mb) -> Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value GHC.Types.Bool)))
instance (Database.Esqueleto.Experimental.ToFrom a, Database.Esqueleto.Experimental.ToFromT a GHC.Types.~ a', Database.Esqueleto.Experimental.ToFrom b, Database.Esqueleto.Experimental.ToFromT b GHC.Types.~ b', Database.Esqueleto.Experimental.ToMaybe a', ma GHC.Types.~ Database.Esqueleto.Experimental.ToMaybeT a', Database.Esqueleto.Experimental.ToMaybe b', mb GHC.Types.~ Database.Esqueleto.Experimental.ToMaybeT b') => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.FullOuterJoin a (b, (ma Database.Esqueleto.Experimental.:& mb) -> Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value GHC.Types.Bool)))
instance (Database.Esqueleto.Experimental.ToFrom a, Database.Esqueleto.Experimental.ToFromT a GHC.Types.~ a', Database.Esqueleto.Experimental.ToFrom b, Database.Esqueleto.Experimental.ToFromT b GHC.Types.~ b', Database.Esqueleto.Experimental.ToMaybe a', ma GHC.Types.~ Database.Esqueleto.Experimental.ToMaybeT a') => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.RightOuterJoin a (b, (ma Database.Esqueleto.Experimental.:& b') -> Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value GHC.Types.Bool)))
instance (Database.Esqueleto.Experimental.ToFrom a, Database.Esqueleto.Experimental.ToFromT a GHC.Types.~ a', Database.Esqueleto.Experimental.ToFrom b, Database.Esqueleto.Experimental.ToFromT b GHC.Types.~ b') => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.InnerJoin a (b, (a' Database.Esqueleto.Experimental.:& b') -> Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value GHC.Types.Bool)))
instance (Database.Esqueleto.Experimental.ToFrom a, Database.Esqueleto.Experimental.ToFrom b) => Database.Esqueleto.Experimental.ToFrom (Database.Esqueleto.Internal.Internal.CrossJoin a b)
instance Database.Esqueleto.Experimental.ToAliasReference (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value a))
instance Database.Esqueleto.Experimental.ToAliasReference (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity a))
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b) => Database.Esqueleto.Experimental.ToAliasReference (a, b)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c, Database.Esqueleto.Experimental.ToAliasReference d) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c, d)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c, Database.Esqueleto.Experimental.ToAliasReference d, Database.Esqueleto.Experimental.ToAliasReference e) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c, d, e)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c, Database.Esqueleto.Experimental.ToAliasReference d, Database.Esqueleto.Experimental.ToAliasReference e, Database.Esqueleto.Experimental.ToAliasReference f) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c, d, e, f)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c, Database.Esqueleto.Experimental.ToAliasReference d, Database.Esqueleto.Experimental.ToAliasReference e, Database.Esqueleto.Experimental.ToAliasReference f, Database.Esqueleto.Experimental.ToAliasReference g) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Experimental.ToAliasReference a, Database.Esqueleto.Experimental.ToAliasReference b, Database.Esqueleto.Experimental.ToAliasReference c, Database.Esqueleto.Experimental.ToAliasReference d, Database.Esqueleto.Experimental.ToAliasReference e, Database.Esqueleto.Experimental.ToAliasReference f, Database.Esqueleto.Experimental.ToAliasReference g, Database.Esqueleto.Experimental.ToAliasReference h) => Database.Esqueleto.Experimental.ToAliasReference (a, b, c, d, e, f, g, h)
instance Database.Esqueleto.Experimental.ToAlias (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value a))
instance Database.Esqueleto.Experimental.ToAlias (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity a))
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b) => Database.Esqueleto.Experimental.ToAlias (a, b)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c) => Database.Esqueleto.Experimental.ToAlias (a, b, c)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c, Database.Esqueleto.Experimental.ToAlias d) => Database.Esqueleto.Experimental.ToAlias (a, b, c, d)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c, Database.Esqueleto.Experimental.ToAlias d, Database.Esqueleto.Experimental.ToAlias e) => Database.Esqueleto.Experimental.ToAlias (a, b, c, d, e)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c, Database.Esqueleto.Experimental.ToAlias d, Database.Esqueleto.Experimental.ToAlias e, Database.Esqueleto.Experimental.ToAlias f) => Database.Esqueleto.Experimental.ToAlias (a, b, c, d, e, f)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c, Database.Esqueleto.Experimental.ToAlias d, Database.Esqueleto.Experimental.ToAlias e, Database.Esqueleto.Experimental.ToAlias f, Database.Esqueleto.Experimental.ToAlias g) => Database.Esqueleto.Experimental.ToAlias (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Experimental.ToAlias a, Database.Esqueleto.Experimental.ToAlias b, Database.Esqueleto.Experimental.ToAlias c, Database.Esqueleto.Experimental.ToAlias d, Database.Esqueleto.Experimental.ToAlias e, Database.Esqueleto.Experimental.ToAlias f, Database.Esqueleto.Experimental.ToAlias g, Database.Esqueleto.Experimental.ToAlias h) => Database.Esqueleto.Experimental.ToAlias (a, b, c, d, e, f, g, h)
instance Database.Esqueleto.Experimental.ToMaybe (Database.Esqueleto.Internal.Internal.SqlExpr (GHC.Maybe.Maybe a))
instance Database.Esqueleto.Experimental.ToMaybe (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Persist.Class.PersistEntity.Entity a))
instance Database.Esqueleto.Experimental.ToMaybe (Database.Esqueleto.Internal.Internal.SqlExpr (Database.Esqueleto.Internal.Internal.Value a))
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b) => Database.Esqueleto.Experimental.ToMaybe (a Database.Esqueleto.Experimental.:& b)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b) => Database.Esqueleto.Experimental.ToMaybe (a, b)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c) => Database.Esqueleto.Experimental.ToMaybe (a, b, c)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c, Database.Esqueleto.Experimental.ToMaybe d) => Database.Esqueleto.Experimental.ToMaybe (a, b, c, d)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c, Database.Esqueleto.Experimental.ToMaybe d, Database.Esqueleto.Experimental.ToMaybe e) => Database.Esqueleto.Experimental.ToMaybe (a, b, c, d, e)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c, Database.Esqueleto.Experimental.ToMaybe d, Database.Esqueleto.Experimental.ToMaybe e, Database.Esqueleto.Experimental.ToMaybe f) => Database.Esqueleto.Experimental.ToMaybe (a, b, c, d, e, f)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c, Database.Esqueleto.Experimental.ToMaybe d, Database.Esqueleto.Experimental.ToMaybe e, Database.Esqueleto.Experimental.ToMaybe f, Database.Esqueleto.Experimental.ToMaybe g) => Database.Esqueleto.Experimental.ToMaybe (a, b, c, d, e, f, g)
instance (Database.Esqueleto.Experimental.ToMaybe a, Database.Esqueleto.Experimental.ToMaybe b, Database.Esqueleto.Experimental.ToMaybe c, Database.Esqueleto.Experimental.ToMaybe d, Database.Esqueleto.Experimental.ToMaybe e, Database.Esqueleto.Experimental.ToMaybe f, Database.Esqueleto.Experimental.ToMaybe g, Database.Esqueleto.Experimental.ToMaybe h) => Database.Esqueleto.Experimental.ToMaybe (a, b, c, d, e, f, g, h)


-- | 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.
--   
--   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
[EEntity] :: Ident -> SqlExpr (Entity val)
[EAliasedEntity] :: Ident -> Ident -> SqlExpr (Entity val)
[EAliasedEntityReference] :: Ident -> Ident -> SqlExpr (Entity val)
[EMaybe] :: SqlExpr a -> SqlExpr (Maybe a)
[ERaw] :: NeedParens -> (IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Value a)
[EAliasedValue] :: Ident -> SqlExpr (Value a) -> SqlExpr (Value a)
[EValueReference] :: Ident -> (IdentInfo -> Ident) -> SqlExpr (Value a)
[ECompositeKey] :: (IdentInfo -> [Builder]) -> SqlExpr (Value a)
[EList] :: SqlExpr (Value a) -> SqlExpr (ValueList a)
[EEmptyList] :: SqlExpr (ValueList a)
[EOrderBy] :: OrderByType -> SqlExpr (Value a) -> SqlExpr OrderBy

-- | <i>Deprecated: Since 2.6.0: <a>rand</a> ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.</i>
[EOrderRandom] :: SqlExpr OrderBy
[EDistinctOn] :: SqlExpr (Value a) -> SqlExpr DistinctOn
[ESet] :: (SqlExpr (Entity val) -> SqlExpr (Value ())) -> SqlExpr (Update val)
[EPreprocessedFrom] :: a -> FromClause -> SqlExpr (PreprocessedFrom a)
[EInsert] :: Proxy a -> (IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Insertion a)
[EInsertFinal] :: PersistEntity a => SqlExpr (Insertion a) -> SqlExpr InsertFinal

-- | 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>subSelect</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><a>select</a> $ from $ \p -&gt; return p</tt> alone is ambiguous,
--   but in the context of
--   
--   <pre>
--   do ps &lt;- <a>select</a> $
--            <a>from</a> $ \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, MonadIO m) => SqlQuery a -> SqlReadT 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, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()

-- | 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>
--   <a>delete</a> $
--   <a>from</a> $ \appointment -&gt;
--   <a>where_</a> (appointment <a>^.</a> AppointmentDate <a>&lt;.</a> <a>val</a> 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>
--   <a>delete</a> $
--   <a>from</a> $ \(appointment :: <a>SqlExpr</a> (<a>Entity</a> Appointment)) -&gt;
--   return ()
--   </pre>
delete :: MonadIO m => SqlQuery () -> SqlWriteT m ()

-- | Same as <a>delete</a>, but returns the number of rows affected.
deleteCount :: MonadIO m => SqlQuery () -> SqlWriteT 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>
--   <a>update</a> $ \p -&gt; do
--   <a>set</a> p [ PersonAge <a>=.</a> <a>just</a> (<a>val</a> thisYear) -. p <a>^.</a> PersonBorn ]
--   <a>where_</a> $ isNothing (p <a>^.</a> PersonAge)
--   </pre>
update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()

-- | Same as <a>update</a>, but returns the number of rows affected.
updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64

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

-- | Insert a <a>PersistField</a> 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 <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 " = "
--   </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)

-- | Similar to <a>unsafeSqlBinOp</a>, but may also be applied to composite
--   keys. Uses the operator given as the second argument whenever applied
--   to composite keys.
--   
--   Usage example:
--   
--   <pre>
--   (==.) :: SqlExpr (Value a) -&gt; SqlExpr (Value a) -&gt; SqlExpr (Value Bool)
--   (==.) = unsafeSqlBinOpComposite " = " " AND "
--   </pre>
--   
--   Persistent has a hack for implementing composite keys (see
--   <a>ECompositeKey</a> doc for more details), so we're forced to use a
--   hack here as well. We deconstruct <a>ERaw</a> values based on two
--   rules:
--   
--   <ul>
--   <li>If it is a single placeholder, then it's assumed to be coming from
--   a <a>PersistList</a> and thus its components are separated so that
--   they may be applied to a composite key.</li>
--   <li>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.</li>
--   </ul>
unsafeSqlBinOpComposite :: Builder -> 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) An explicit SQL type cast using CAST(value as type). See
--   <a>unsafeSqlBinOp</a> for warnings.
unsafeSqlCastAs :: Text -> SqlExpr (Value a) -> SqlExpr (Value b)

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

-- | (Internal) An unsafe SQL function to extract a subfield from a
--   compound field, e.g. datetime. See <a>unsafeSqlBinOp</a> for warnings.
--   
--   Since: 1.3.6.
unsafeSqlExtractSubField :: UnsafeSqlFunctionArgument a => Builder -> a -> SqlExpr (Value b)

-- | (Internal) This class allows <a>unsafeSqlFunction</a> to work with
--   different numbers of arguments; specifically it allows providing
--   arguments to a sql function via an n-tuple of <tt>SqlExpr (Value
--   _)</tt> values, which are not all necessarily required to be the same
--   type. There are instances for up to 10-tuples, but for sql functions
--   which take more than 10 arguments, you can also nest tuples, as e.g.
--   <tt>toArgList ((a,b),(c,d))</tt> is the same as <tt>toArgList
--   (a,b,c,d)</tt>.
class UnsafeSqlFunctionArgument a

-- | A <tt>ORDER BY</tt> clause.
type OrderByClause = SqlExpr OrderBy

-- | (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, MonadIO m1, MonadIO m2) => Mode -> SqlQuery a -> SqlReadT m1 (Acquire (ConduitT () r m2 ()))

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

-- | (Internal) Execute an <tt>esqueleto</tt> statement inside
--   <tt>persistent</tt>'s <a>SqlPersistT</a> monad.
rawEsqueleto :: (MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> SqlQuery a -> ReaderT backend 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), see the <a>renderQueryToText</a> function
--   (along with <a>renderQuerySelect</a>, <a>renderQueryUpdate</a>, etc).
toRawSql :: (SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])

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

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

-- | Renders an expression into <tt>Text</tt>. Only useful for creating a
--   textual representation of the clauses passed to an <a>On</a> clause.
renderExpr :: SqlBackend -> SqlExpr (Value Bool) -> Text
initialIdentState :: IdentState

-- | Information needed to escape and use identifiers.
type IdentInfo = (SqlBackend, 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

-- | Creates the variable part of the <tt>SELECT</tt> query and returns the
--   list of <a>PersistValue</a>s that will be given to <a>rawQuery</a>.
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 <tt>INSERT INTO</tt> 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 <i>not</i> 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)

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryToText :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQuerySelect :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryUpdate :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryDelete :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryInsertInto :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
makeOrderByNoNewline :: IdentInfo -> [OrderByClause] -> (Builder, [PersistValue])
uncommas' :: Monoid a => [(Builder, a)] -> (Builder, a)
parens :: Builder -> Builder
toArgList :: UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
builderToText :: Builder -> Text

-- | Identifier used for table names.
newtype Ident
I :: Text -> Ident


-- | 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.Persist as P
--   </pre>
--   
--   or import <tt>esqueleto</tt> itself qualified:
--   
--   <pre>
--   -- For a module that uses esqueleto just on some queries.
--   import Database.Persist
--   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

-- | <tt>WHERE</tt> clause: restrict the query's result.
where_ :: SqlExpr (Value Bool) -> SqlQuery ()

-- | An <tt>ON</tt> clause, useful to describe how two tables are related.
--   Cross joins and tuple-joins do not need an <a>on</a> clause, but
--   <a>InnerJoin</a> and the various outer joins do.
--   
--   If you don't include an <a>on</a> clause (or include too many!) then a
--   runtime exception will be thrown.
--   
--   As an example, consider this simple join:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   We need to specify the clause for joining the two columns together. If
--   we had this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>CrossJoin</a>` bar) -&gt; do
--     ...
--   </pre>
--   
--   Then we can safely omit the <a>on</a> clause, because the cross join
--   will make pairs of all records possible.
--   
--   You can do multiple <a>on</a> clauses in a query. This query joins
--   three tables, and has two <a>on</a> clauses:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     ...
--   </pre>
--   
--   Old versions of esqueleto required that you provide the <a>on</a>
--   clauses in reverse order. This restriction has been lifted - you can
--   now provide <a>on</a> clauses in any order, and the SQL should work
--   itself out. The above query is now totally equivalent to this:
--   
--   <pre>
--   <a>select</a> $
--   <a>from</a> $ \(foo `<a>InnerJoin</a>` bar `<a>InnerJoin</a>` baz) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooId <a>==.</a> bar <a>^.</a> BarFooId)
--     <a>on</a> (baz <a>^.</a> BazId <a>==.</a> bar <a>^.</a> BarBazId)
--     ...
--   </pre>
on :: SqlExpr (Value Bool) -> SqlQuery ()

-- | <tt>GROUP BY</tt> clause. You can enclose multiple columns in a tuple.
--   
--   <pre>
--   select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> (bar <a>^.</a> BarId, bar <a>^.</a> BarName)
--     return (bar <a>^.</a> BarId, bar <a>^.</a> BarName, countRows)
--   </pre>
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   <tt>let</tt> to restrict the more general <a>countRows</a> to
--   <tt>SqlSqlExpr (Value Int)</tt> to avoid ambiguity---the second use of
--   <a>countRows</a> has its type restricted by the <tt>:: Int</tt>
--   below):
--   
--   <pre>
--   r &lt;- select $ <a>from</a> \(foo `<a>InnerJoin</a>` bar) -&gt; do
--     <a>on</a> (foo <a>^.</a> FooBarId <a>==.</a> bar <a>^.</a> BarId)
--     <a>groupBy</a> $ bar <a>^.</a> BarName
--     let countRows' = <a>countRows</a>
--     <a>orderBy</a> [<a>asc</a> countRows']
--     return (bar <a>^.</a> BarName, countRows')
--   forM_ r $ \(<a>Value</a> name, <a>Value</a> count) -&gt; do
--     print name
--     print (count :: Int)
--   </pre>
--   
--   <h3>Need more columns?</h3>
--   
--   The <a>ToSomeValues</a> class is defined for <a>SqlExpr</a> and tuples
--   of <a>SqlExpr</a>s. We only have definitions for up to 8 elements in a
--   tuple right now, so it's possible that you may need to have more than
--   8 elements.
--   
--   For example, consider a query with a <a>groupBy</a> call like this:
--   
--   <pre>
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   </pre>
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   <pre>
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   </pre>
groupBy :: ToSomeValues a => a -> SqlQuery ()

-- | <tt>ORDER BY</tt> clause. See also <a>asc</a> and <a>desc</a>.
--   
--   Multiple calls to <a>orderBy</a> get concatenated on the final query,
--   including <a>distinctOnOrderBy</a>.
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()

-- | <tt>ORDER BY random()</tt> clause.
--   
--   <i>Since: 1.3.10</i>

-- | <i>Deprecated: Since 2.6.0: <a>rand</a> ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.</i>
rand :: SqlExpr OrderBy

-- | Ascending order of this field or SqlExpression.
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | Descending order of this field or SqlExpression.
desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy

-- | <tt>LIMIT</tt>. Limit the number of returned rows.
limit :: Int64 -> SqlQuery ()

-- | <tt>OFFSET</tt>. Usually used with <a>limit</a>.
offset :: Int64 -> SqlQuery ()

-- | <tt>DISTINCT</tt>. Change the current <tt>SELECT</tt> into <tt>SELECT
--   DISTINCT</tt>. For example:
--   
--   <pre>
--   select $ distinct $
--     <a>from</a> \foo -&gt; do
--     ...
--   </pre>
--   
--   Note that this also has the same effect:
--   
--   <pre>
--   select $
--     <a>from</a> \foo -&gt; do
--     distinct (return ())
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinct :: SqlQuery a -> SqlQuery a

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

-- | Erase an SqlExpression's type so that it's suitable to be used by
--   <a>distinctOn</a>.
--   
--   <i>Since: 2.2.4</i>
don :: SqlExpr (Value a) -> SqlExpr DistinctOn

-- | A convenience function that calls both <a>distinctOn</a> and
--   <a>orderBy</a>. In other words,
--   
--   <pre>
--   <a>distinctOnOrderBy</a> [asc foo, desc bar, desc quux] $ do
--     ...
--   </pre>
--   
--   is the same as:
--   
--   <pre>
--   <a>distinctOn</a> [don foo, don  bar, don  quux] $ do
--     <a>orderBy</a>  [asc foo, desc bar, desc quux]
--     ...
--   </pre>
--   
--   <i>Since: 2.2.4</i>
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a

-- | <tt>HAVING</tt>.
--   
--   <i>Since: 1.2.2</i>
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a
--   simple value so should be used only when the <tt>SELECT</tt> query is
--   guaranteed to return just one row.
--   
--   Deprecated in 3.2.0.

-- | <i>Deprecated: sub_select sub_select is an unsafe function to use. If
--   used with a SqlQuery that returns 0 results, then it may return NULL
--   despite not mentioning Maybe in the return type. If it returns more
--   than 1 result, then it will throw a SQL error. Instead, consider using
--   one of the following alternatives: - subSelect: attaches a LIMIT 1 and
--   the Maybe return type, totally safe. - subSelectMaybe: Attaches a
--   LIMIT 1, useful for a query that already has a Maybe in the return
--   type. - subSelectCount: Performs a count of the query - this is always
--   safe. - subSelectUnsafe: Performs no checks or guarantees. Safe to use
--   with countRows and friends.</i>
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Project a field of an entity.
(^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
infixl 9 ^.

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

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

-- | <tt>IS NULL</tt> comparison.
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)

-- | Analogous to <a>Just</a>, promotes a value of type <tt>typ</tt> into
--   one of type <tt>Maybe typ</tt>. It should hold that <tt><a>val</a> .
--   Just === just . <a>val</a></tt>.
just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))

-- | <tt>NULL</tt> value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested <a>Maybe</a>s in a <a>Value</a> into one. This is useful
--   when calling aggregate functions on nullable fields.
joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))

-- | Project an SqlExpression that may be null, guarding against null
--   cases.
withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a

-- | <tt>COUNT(*)</tt> value.
countRows :: Num a => SqlExpr (Value a)

-- | <tt>COUNT</tt>.
count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)

-- | <tt>COUNT(DISTINCT x)</tt>.
--   
--   <i>Since: 2.4.1</i>
countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 ==.
(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >=.
(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 >.
(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <=.
(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 <.
(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
infix 4 !=.
(&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 3 &&.
(||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
infixr 2 ||.

-- | <tt>BETWEEN</tt>.
--   
--   @since: 3.1.0
between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 +.
(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 6 -.
(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 /.
(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
infixl 7 *.

-- | <i>Deprecated: Since 2.6.0: <a>random_</a> is not uniform across all
--   databases! Please use a specific one such as <a>random_</a>,
--   <a>random_</a>, or <a>random_</a></i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (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.
--   
--   <i>Caveat</i>: Trying to use <tt>castNum</tt> from <tt>Double</tt> to
--   <tt>Int</tt> will not result in an integer, the original fractional
--   number will still be used! Use <a>round_</a>, <a>ceiling_</a> or
--   <a>floor_</a> instead.
--   
--   <i>Safety</i>: This operation is mostly safe due to the <a>Num</a>
--   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
--   <tt>persistent</tt> not being able to parse it.
--   
--   <i>Since: 2.2.9</i>
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

-- | Same as <a>castNum</a>, but for nullable values.
--   
--   <i>Since: 2.2.9</i>
castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))

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

-- | Like <tt>coalesce</tt>, but takes a non-nullable SqlExpression placed
--   at the end of the SqlExpression list, which guarantees a non-NULL
--   result.
--   
--   <i>Since: 1.4.3</i>
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)

-- | <tt>LOWER</tt> function.
lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>UPPER</tt> function. <i>Since: 3.3.0</i>
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>TRIM</tt> function. <i>Since: 3.3.0</i>
trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LTRIM</tt> function. <i>Since: 3.3.0</i>
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>RTRIM</tt> function. <i>Since: 3.3.0</i>
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)

-- | <tt>LENGTH</tt> function. <i>Since: 3.3.0</i>
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)

-- | <tt>LEFT</tt> function. <i>Since: 3.3.0</i>
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>RIGHT</tt> function. <i>Since: 3.3.0</i>
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)

-- | <tt>LIKE</tt> operator.
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `like`

-- | <tt>ILIKE</tt> operator (case-insensitive <tt>LIKE</tt>).
--   
--   Supported by PostgreSQL only.
--   
--   <i>Since: 2.2.3</i>
ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
infixr 2 `ilike`

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

-- | The <tt>CONCAT</tt> function with a variable number of parameters.
--   Supported by MySQL and PostgreSQL.
concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)

-- | The <tt>||</tt> string concatenation operator (named after Haskell's
--   <a>++</a> in order to avoid naming clash with <a>||.</a>). Supported
--   by SQLite and PostgreSQL.
(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
infixr 5 ++.

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

-- | Execute a subquery <tt>SELECT</tt> in an SqlExpression. Returns a list
--   of values.
subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

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

-- | Same as <a>just</a> but for <a>ValueList</a>. Most of the time you
--   won't need it, though, because you can use <a>just</a> from inside
--   <a>subList_select</a> or <a>Just</a> from inside <a>valList</a>.
--   
--   <i>Since: 2.2.12</i>
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

-- | <tt>NOT IN</tt> operator.
notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)

-- | <tt>EXISTS</tt> operator. For example:
--   
--   <pre>
--   select $
--   <a>from</a> $ \person -&gt; do
--   <a>where_</a> $ <a>exists</a> $
--            <a>from</a> $ \post -&gt; do
--            <a>where_</a> (post <a>^.</a> BlogPostAuthorId <a>==.</a> person <a>^.</a> PersonId)
--   return person
--   </pre>
exists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>NOT EXISTS</tt> operator.
notExists :: SqlQuery () -> SqlExpr (Value Bool)

-- | <tt>SET</tt> clause used on <tt>UPDATE</tt>s. Note that while it's not
--   a type error to use this function on a <tt>SELECT</tt>, it will most
--   certainly result in a runtime error.
set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Update val)] -> SqlQuery ()
(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Update val)
infixr 3 =.
(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 +=.
(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 -=.
(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 *=.
(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
infixr 3 /=.

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

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

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. The query
--   passed to this function will only return a single result - it has a
--   <tt>LIMIT 1</tt> passed in to the query to make it safe, and the
--   return type is <a>Maybe</a> to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing <tt><a>joinV</a> . <a>subSelect</a></tt>,
--   then consider using <a>subSelectMaybe</a>.
--   
--   If you're performing a <a>countRows</a>, then you can use
--   <a>subSelectCount</a> which is safe.
--   
--   If you know that the subquery will always return exactly one row (eg a
--   foreign key constraint guarantees that you'll get exactly one row),
--   then consider <a>subSelectUnsafe</a>, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is a shorthand for the common <tt><a>joinV</a> . <a>subSelect</a></tt>
--   idiom, where you are calling <a>subSelect</a> on an expression that
--   would be <a>Maybe</a> already.
--   
--   As an example, you would use this function when calling <a>sum_</a> or
--   <a>max_</a>, which have <a>Maybe</a> in the result type (for a 0 row
--   query).
subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))

-- | Performs a <tt>COUNT</tt> of the given query in a <tt>subSelect</tt>
--   manner. This is always guaranteed to return a result value, and is
--   completely safe.
subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a)

-- | Performs a sub-select using the given foreign key on the entity. This
--   is useful to extract values that are known to be present by the
--   database schema.
--   
--   As an example, consider the following persistent definition:
--   
--   <pre>
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   </pre>
--   
--   The following query will return the name of the user.
--   
--   <pre>
--   getUserWithName =
--       <a>select</a> $
--       <a>from</a> $ user -&gt;
--       <a>pure</a> (user, <a>subSelectForeign</a> user UserProfile (^. ProfileName)
--   </pre>
subSelectForeign :: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) => SqlExpr (Entity val2) -> EntityField val2 (Key val1) -> (SqlExpr (Entity val1) -> SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a> that returns a
--   list. This is an alias for <a>subList_select</a> and is provided for
--   symmetry with the other safe subselect functions.
subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

-- | Execute a subquery <tt>SELECT</tt> in a <a>SqlExpr</a>. This function
--   is unsafe, because it can throw runtime exceptions in two cases:
--   
--   <ol>
--   <li>If the query passed has 0 result rows, then it will return a
--   <tt>NULL</tt> value. The <tt>persistent</tt> parsing operations will
--   fail on an unexpected <tt>NULL</tt>.</li>
--   <li>If the query passed returns more than one row, then the SQL engine
--   will fail with an error like "More than one row returned by a subquery
--   used as an expression".</li>
--   </ol>
--   
--   This function is safe if you guarantee that exactly one row will be
--   returned, or if the result already has a <a>Maybe</a> type for some
--   reason.
--   
--   For variants with the safety encoded already, see <a>subSelect</a> and
--   <a>subSelectMaybe</a>. For the most common safe use of this, see
--   <a>subSelectCount</a>.
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

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

-- | Convert from the key of the BaseEnt(ity) to the key of the child
--   entity. This function is not actually called, but that it typechecks
--   proves this operation is safe.
toBaseIdWitness :: ToBaseId ent => Key (BaseEnt ent) -> Key ent

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

-- | Syntax sugar for <a>case_</a>.
--   
--   <i>Since: 2.1.2</i>
then_ :: ()

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

-- | <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 left fixity.</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>
--   <a>from</a> $ \person -&gt; ...
--   <a>from</a> $ \(person, blogPost) -&gt; ...
--   <a>from</a> $ \(p `<a>LeftOuterJoin</a>` mb) -&gt; ...
--   <a>from</a> $ \(p1 `<a>InnerJoin</a>` f `<a>InnerJoin</a>` p2) -&gt; ...
--   <a>from</a> $ \((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
--                   (InnerJoin (expr (Entity Person))
--                              (expr (Entity Follow)))
--                   (expr (Entity Person))
--   (p1 `<a>InnerJoin</a>` (f `<a>InnerJoin</a>` p2)) ::
--     :: (...) =&gt; InnerJoin
--                   (expr (Entity Person))
--                   (InnerJoin (expr (Entity Follow))
--                              (expr (Entity Person)))
--   </pre>
--   
--   Note that some backends may not support all kinds of <tt>JOIN</tt>s.
from :: From a => (a -> SqlQuery b) -> SqlQuery 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>.
newtype Value a
Value :: a -> Value a
[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 <a>subList_select</a>,
--   <a>valList</a>, <a>in_</a> and <a>exists</a>).
newtype ValueList a
ValueList :: a -> ValueList a

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

-- | Phantom type used by <a>distinctOn</a> and <a>don</a>.
data DistinctOn

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

-- | <tt>FOR UPDATE</tt> syntax. Supported by MySQL, Oracle and PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdate :: LockingKind

-- | <tt>FOR UPDATE SKIP LOCKED</tt> syntax. Supported by MySQL, Oracle and
--   PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForUpdateSkipLocked :: LockingKind

-- | <tt>FOR SHARE</tt> syntax. Supported by PostgreSQL.
--   
--   <i>Since: 2.2.7</i>
ForShare :: LockingKind

-- | <tt>LOCK IN SHARE MODE</tt> syntax. Supported by MySQL.
--   
--   <i>Since: 2.2.7</i>
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 <tt>newtype</tt>, feel free to make
--   it an instance of this class.
--   
--   <i>Since: 2.4.0</i>
class PersistField a => SqlString a

-- | 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
infixl 2 `InnerJoin`
infixl 2 `InnerJoin`

-- | 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
infixl 2 `CrossJoin`
infixl 2 `CrossJoin`

-- | Data type that represents a <tt>LEFT OUTER JOIN</tt>. For example,
--   
--   <pre>
--   select $
--   <a>from</a> $ \(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
infixl 2 `LeftOuterJoin`
infixl 2 `LeftOuterJoin`

-- | 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
infixl 2 `RightOuterJoin`
infixl 2 `RightOuterJoin`

-- | 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
infixl 2 `FullOuterJoin`
infixl 2 `FullOuterJoin`

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

-- | 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.
--   
--   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 <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>subSelect</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><a>select</a> $ from $ \p -&gt; return p</tt> alone is ambiguous,
--   but in the context of
--   
--   <pre>
--   do ps &lt;- <a>select</a> $
--            <a>from</a> $ \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, MonadIO m) => SqlQuery a -> SqlReadT 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, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()

-- | 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>
--   <a>delete</a> $
--   <a>from</a> $ \appointment -&gt;
--   <a>where_</a> (appointment <a>^.</a> AppointmentDate <a>&lt;.</a> <a>val</a> 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>
--   <a>delete</a> $
--   <a>from</a> $ \(appointment :: <a>SqlExpr</a> (<a>Entity</a> Appointment)) -&gt;
--   return ()
--   </pre>
delete :: MonadIO m => SqlQuery () -> SqlWriteT m ()

-- | Same as <a>delete</a>, but returns the number of rows affected.
deleteCount :: MonadIO m => SqlQuery () -> SqlWriteT 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>
--   <a>update</a> $ \p -&gt; do
--   <a>set</a> p [ PersonAge <a>=.</a> <a>just</a> (<a>val</a> thisYear) -. p <a>^.</a> PersonBorn ]
--   <a>where_</a> $ isNothing (p <a>^.</a> PersonAge)
--   </pre>
update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()

-- | Same as <a>update</a>, but returns the number of rows affected.
updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64

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

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

-- | Apply a <a>PersistField</a> constructor to <tt>SqlExpr Value</tt>
--   arguments.
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

-- | Apply extra <tt>SqlExpr Value</tt> arguments to a <a>PersistField</a>
--   constructor
(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryToText :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQuerySelect :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryUpdate :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryDelete :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

-- | Renders a <a>SqlQuery</a> into a <tt>Text</tt> value along with the
--   list of <a>PersistValue</a>s that would be supplied to the database
--   for <tt>?</tt> placeholders.
--   
--   You must ensure that the <a>Mode</a> you pass to this function
--   corresponds with the actual <a>SqlQuery</a>. If you pass a query that
--   uses incompatible features (like an <tt>INSERT</tt> statement with a
--   <tt>SELECT</tt> mode) then you'll get a weird result.
renderQueryInsertInto :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])

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

-- | <tt>valkey i = <a>val</a> . <a>toSqlKey</a></tt>
--   (<a>https://github.com/prowdsponsor/esqueleto/issues/9</a>).
valkey :: (ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> SqlExpr (Value (Key entity))

-- | <tt>valJ</tt> is like <tt>val</tt> but for something that is already a
--   <tt>Value</tt>. The use case it was written for was, given a
--   <tt>Value</tt> lift the <tt>Key</tt> for that <tt>Value</tt> into the
--   query expression in a type safe way. However, the implementation is
--   more generic than that so we call it <tt>valJ</tt>.
--   
--   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
--   (<a>https://github.com/prowdsponsor/esqueleto/pull/69</a>).
--   
--   <i>Since: 1.4.2</i>
valJ :: PersistField (Key entity) => Value (Key entity) -> SqlExpr (Value (Key entity))

-- | Avoid N+1 queries and join entities into a map structure <tt>
--   getFoosAndNestedBarsFromParent :: ParentId -&gt; (Map (Key Foo) (Foo,
--   [Maybe (Entity Bar)])) getFoosAndNestedBarsFromParent parentId =
--   <a>fmap</a> associateJoin $ <a>select</a> $ <a>from</a> $ \(foo
--   `<a>LeftOuterJoin</a>` bar) -&gt; do <a>on</a> (bar <a>?.</a> BarFooId
--   <a>==.</a> foo <a>^.</a> FooId) <a>where_</a> (foo <a>^.</a>
--   FooParentId <a>==.</a> <a>val</a> parentId) <a>pure</a> (foo, bar)
--   </tt>
associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1])

-- | Synonym for <a>delete</a> that does not clash with
--   <tt>esqueleto</tt>'s <a>delete</a>.
deleteKey :: (PersistStore backend, BaseBackend backend ~ PersistEntityBackend val, MonadIO m, PersistEntity val) => Key val -> ReaderT backend m ()
toJsonText :: ToJSON j => j -> Text
entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
entityValues :: PersistEntity record => Entity record -> [PersistValue]
fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a
keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
toPersistValueJSON :: ToJSON a => a -> PersistValue
selectKeys :: forall backend (m :: Type -> Type) record. (PersistQueryRead backend, MonadResource m, PersistRecordBackend record backend, MonadReader backend m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m ()
belongsTo :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Maybe (Key ent2)) -> ent1 -> ReaderT backend m (Maybe ent2)
belongsToJust :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Key ent2) -> ent1 -> ReaderT backend m ent2
getEntity :: forall backend e (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e))
getJust :: forall backend record (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record
getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record)
insertEntity :: forall backend e (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, MonadIO m) => e -> ReaderT backend m (Entity e)
insertRecord :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, PersistEntity record, MonadIO m, PersistStoreWrite backend) => record -> ReaderT backend m record
liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b
checkUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record))
getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record))
insertBy :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Either (Entity record) (Key record))
insertUniqueEntity :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend) => record -> ReaderT backend m (Maybe (Entity record))
onlyUnique :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record)
replaceUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, Eq (Unique record), PersistRecordBackend record backend, PersistUniqueWrite backend) => Key record -> record -> ReaderT backend m (Maybe (Unique record))
transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
defaultAttribute :: [Attr] -> Maybe Text
mkColumns :: [EntityDef] -> EntityDef -> ([Column], [UniqueDef], [ForeignDef])
getMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Sql]
migrate :: [EntityDef] -> EntityDef -> Migration
parseMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration)
parseMigration' :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m CautiousMigration
printMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text]
runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
showMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text]
decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Bool -> Text -> Text
fieldDBName :: PersistEntity record => EntityField record typ -> DBName
fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64
getFieldName :: forall record typ (m :: Type -> Type) backend. (PersistEntity record, PersistEntityBackend record ~ SqlBackend, BackendCompatible SqlBackend backend, Monad m) => EntityField record typ -> ReaderT backend m Text
getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text
tableDBName :: PersistEntity record => record -> DBName
toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record
withRawQuery :: forall (m :: Type -> Type) a. MonadIO m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> ReaderT SqlBackend m a
getStmtConn :: SqlBackend -> Text -> IO Statement
rawExecute :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m ()
rawExecuteCount :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m Int64
rawQuery :: forall (m :: Type -> Type) env. (MonadResource m, MonadReader env m, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ConduitM () [PersistValue] m ()
rawQueryRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) env. (MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ()))
rawSql :: forall a (m :: Type -> Type) backend. (RawSql a, MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m [a]
askLogFunc :: (MonadUnliftIO m, MonadLogger m) => m LogFunc
close' :: BackendCompatible SqlBackend backend => backend -> IO ()
createSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend)
liftSqlPersistMPool :: (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a
runSqlConn :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a
runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a
runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a
runSqlPool :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
withSqlConn :: (MonadUnliftIO m, MonadLogger m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a
withSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> (Pool backend -> m a) -> m a
readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a
readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a
writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a
entityKeyFields :: EntityDef -> [FieldDef]
entityPrimary :: EntityDef -> Maybe CompositeDef
fromPersistValueText :: PersistValue -> Either Text Text
keyAndEntityFields :: EntityDef -> [FieldDef]
toEmbedEntityDef :: EntityDef -> EmbedEntityDef
type PersistStore a = PersistStoreWrite a
type PersistUnique a = PersistUniqueWrite a
class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend
deleteCascade :: forall (m :: Type -> Type). (DeleteCascade record backend, MonadIO m) => Key record -> ReaderT backend m ()
class PersistConfig c where {
    type family PersistConfigBackend c :: Type -> Type -> Type -> Type;
    type family PersistConfigPool c;
}
loadConfig :: PersistConfig c => Value -> Parser c
applyEnv :: PersistConfig c => c -> IO c
createPoolConfig :: PersistConfig c => c -> IO (PersistConfigPool c)
runPool :: (PersistConfig c, MonadUnliftIO m) => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a
type family BackendSpecificUpdate backend record
data Entity record
Entity :: Key record -> record -> Entity record
[entityKey] :: Entity record -> Key record
[entityVal] :: Entity record -> record
class (PersistField Key record, ToJSON Key record, FromJSON Key record, Show Key record, Read Key record, Eq Key record, Ord Key record) => PersistEntity record where {
    type family PersistEntityBackend record;
    data family Key record;
    data family EntityField record :: Type -> Type;
    data family Unique record;
}
keyToValues :: PersistEntity record => Key record -> [PersistValue]
keyFromValues :: PersistEntity record => [PersistValue] -> Either Text (Key record)
persistIdField :: PersistEntity record => EntityField record (Key record)
entityDef :: (PersistEntity record, Monad m) => m record -> EntityDef
persistFieldDef :: PersistEntity record => EntityField record typ -> FieldDef
toPersistFields :: PersistEntity record => record -> [SomePersistField]
fromPersistValues :: PersistEntity record => [PersistValue] -> Either Text record
persistUniqueKeys :: PersistEntity record => record -> [Unique record]
persistUniqueToFieldNames :: PersistEntity record => Unique record -> [(HaskellName, DBName)]
persistUniqueToValues :: PersistEntity record => Unique record -> [PersistValue]
fieldLens :: PersistEntity record => EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record)
class PersistField a
toPersistValue :: PersistField a => a -> PersistValue
fromPersistValue :: PersistField a => PersistValue -> Either Text a
data SomePersistField
SomePersistField :: a -> SomePersistField
class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend
selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistQueryRead backend, PersistRecordBackend record backend, MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ()))
selectFirst :: forall (m :: Type -> Type) record. (PersistQueryRead backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))
selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (PersistQueryRead backend, MonadIO m1, MonadIO m2, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ()))
class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend
updateWhere :: forall (m :: Type -> Type) record. (PersistQueryWrite backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m ()
deleteWhere :: forall (m :: Type -> Type) record. (PersistQueryWrite backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m ()
class BackendCompatible sup sub
projectBackend :: BackendCompatible sup sub => sub -> sup
data family BackendKey backend
class HasPersistBackend backend where {
    type family BaseBackend backend;
}
persistBackend :: HasPersistBackend backend => backend -> BaseBackend backend
class HasPersistBackend backend => IsPersistBackend backend
class PersistCore backend where {
    data family BackendKey backend;
}
type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)
class (Show BackendKey backend, Read BackendKey backend, Eq BackendKey backend, Ord BackendKey backend, PersistCore backend, PersistField BackendKey backend, ToJSON BackendKey backend, FromJSON BackendKey backend) => PersistStoreRead backend
get :: forall (m :: Type -> Type) record. (PersistStoreRead backend, MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record)
getMany :: forall (m :: Type -> Type) record. (PersistStoreRead backend, MonadIO m, PersistRecordBackend record backend) => [Key record] -> ReaderT backend m (Map (Key record) record)
class (Show BackendKey backend, Read BackendKey backend, Eq BackendKey backend, Ord BackendKey backend, PersistStoreRead backend, PersistField BackendKey backend, ToJSON BackendKey backend, FromJSON BackendKey backend) => PersistStoreWrite backend
insert :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Key record)
insert_ :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m ()
insertMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m [Key record]
insertMany_ :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()
insertEntityMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m ()
insertKey :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
repsert :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
repsertMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m ()
replace :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
updateGet :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record
class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record
toBackendKey :: ToBackendKey backend record => Key record -> BackendKey backend
fromBackendKey :: ToBackendKey backend record => BackendKey backend -> Key record
class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend
getBy :: forall (m :: Type -> Type) record. (PersistUniqueRead backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record))
class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend
deleteBy :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m ()
insertUnique :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Maybe (Key record))
upsert :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> [Update record] -> ReaderT backend m (Entity record)
upsertBy :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> ReaderT backend m (Entity record)
putMany :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()
class PersistField a => PersistFieldSql a
sqlType :: PersistFieldSql a => Proxy a -> SqlType
class RawSql a
rawSqlCols :: RawSql a => (DBName -> Text) -> a -> (Int, [Text])
rawSqlColCountReason :: RawSql a => a -> String
rawSqlProcessRow :: RawSql a => [PersistValue] -> Either Text a
type CautiousMigration = [(Bool, Sql)]
data Column
Column :: !DBName -> !Bool -> !SqlType -> !Maybe Text -> !Maybe DBName -> !Maybe Integer -> !Maybe (DBName, DBName) -> Column
[cName] :: Column -> !DBName
[cNull] :: Column -> !Bool
[cSqlType] :: Column -> !SqlType
[cDefault] :: Column -> !Maybe Text
[cDefaultConstraintName] :: Column -> !Maybe DBName
[cMaxLen] :: Column -> !Maybe Integer
[cReference] :: Column -> !Maybe (DBName, DBName)
type ConnectionPool = Pool SqlBackend
type Migration = WriterT [Text] WriterT CautiousMigration ReaderT SqlBackend IO ()
data PersistentSqlException
StatementAlreadyFinalized :: Text -> PersistentSqlException
Couldn'tGetSQLConnection :: PersistentSqlException
newtype Single a
Single :: a -> Single a
[unSingle] :: Single a -> a
type Sql = Text
type SqlPersistM = SqlPersistT NoLoggingT ResourceT IO
type SqlPersistT = ReaderT SqlBackend
data InsertSqlResult
ISRSingle :: Text -> InsertSqlResult
ISRInsertGet :: Text -> Text -> InsertSqlResult
ISRManyKeys :: Text -> [PersistValue] -> InsertSqlResult
type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend)
type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
data SqlBackend
SqlBackend :: (Text -> IO Statement) -> (EntityDef -> [PersistValue] -> InsertSqlResult) -> Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult) -> Maybe (EntityDef -> NonEmpty UniqueDef -> Text -> Text) -> Maybe (EntityDef -> Int -> Text) -> IORef (Map Text Statement) -> IO () -> ([EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)])) -> ((Text -> IO Statement) -> Maybe IsolationLevel -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> (DBName -> Text) -> Text -> Text -> ((Int, Int) -> Bool -> Text -> Text) -> LogFunc -> Maybe Int -> Maybe (EntityDef -> Int -> Text) -> SqlBackend
[connPrepare] :: SqlBackend -> Text -> IO Statement
[connInsertSql] :: SqlBackend -> EntityDef -> [PersistValue] -> InsertSqlResult
[connInsertManySql] :: SqlBackend -> Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
[connUpsertSql] :: SqlBackend -> Maybe (EntityDef -> NonEmpty UniqueDef -> Text -> Text)
[connPutManySql] :: SqlBackend -> Maybe (EntityDef -> Int -> Text)
[connStmtMap] :: SqlBackend -> IORef (Map Text Statement)
[connClose] :: SqlBackend -> IO ()
[connMigrateSql] :: SqlBackend -> [EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)])
[connBegin] :: SqlBackend -> (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
[connCommit] :: SqlBackend -> (Text -> IO Statement) -> IO ()
[connRollback] :: SqlBackend -> (Text -> IO Statement) -> IO ()
[connEscapeName] :: SqlBackend -> DBName -> Text
[connNoLimit] :: SqlBackend -> Text
[connRDBMS] :: SqlBackend -> Text
[connLimitOffset] :: SqlBackend -> (Int, Int) -> Bool -> Text -> Text
[connLogFunc] :: SqlBackend -> LogFunc
[connMaxParams] :: SqlBackend -> Maybe Int
[connRepsertManySql] :: SqlBackend -> Maybe (EntityDef -> Int -> Text)
type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend)
type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend)
newtype SqlReadBackend
SqlReadBackend :: SqlBackend -> SqlReadBackend
[unSqlReadBackend] :: SqlReadBackend -> SqlBackend
type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a
newtype SqlWriteBackend
SqlWriteBackend :: SqlBackend -> SqlWriteBackend
[unSqlWriteBackend] :: SqlWriteBackend -> SqlBackend
type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a
data Statement
Statement :: IO () -> IO () -> ([PersistValue] -> IO Int64) -> (forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())) -> Statement
[stmtFinalize] :: Statement -> IO ()
[stmtReset] :: Statement -> IO ()
[stmtExecute] :: Statement -> [PersistValue] -> IO Int64
[stmtQuery] :: Statement -> forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())
type Attr = Text
data Checkmark
Active :: Checkmark
Inactive :: Checkmark
data CompositeDef
CompositeDef :: ![FieldDef] -> ![Attr] -> CompositeDef
[compositeFields] :: CompositeDef -> ![FieldDef]
[compositeAttrs] :: CompositeDef -> ![Attr]
newtype DBName
DBName :: Text -> DBName
[unDBName] :: DBName -> Text
data EmbedEntityDef
EmbedEntityDef :: !HaskellName -> ![EmbedFieldDef] -> EmbedEntityDef
[embeddedHaskell] :: EmbedEntityDef -> !HaskellName
[embeddedFields] :: EmbedEntityDef -> ![EmbedFieldDef]
data EmbedFieldDef
EmbedFieldDef :: !DBName -> Maybe EmbedEntityDef -> Maybe HaskellName -> EmbedFieldDef
[emFieldDB] :: EmbedFieldDef -> !DBName
[emFieldEmbed] :: EmbedFieldDef -> Maybe EmbedEntityDef
[emFieldCycle] :: EmbedFieldDef -> Maybe HaskellName
data EntityDef
EntityDef :: !HaskellName -> !DBName -> !FieldDef -> ![Attr] -> ![FieldDef] -> ![UniqueDef] -> ![ForeignDef] -> ![Text] -> !Map Text [ExtraLine] -> !Bool -> !Maybe Text -> EntityDef
[entityHaskell] :: EntityDef -> !HaskellName
[entityDB] :: EntityDef -> !DBName
[entityId] :: EntityDef -> !FieldDef
[entityAttrs] :: EntityDef -> ![Attr]
[entityFields] :: EntityDef -> ![FieldDef]
[entityUniques] :: EntityDef -> ![UniqueDef]
[entityForeigns] :: EntityDef -> ![ForeignDef]
[entityDerives] :: EntityDef -> ![Text]
[entityExtra] :: EntityDef -> !Map Text [ExtraLine]
[entitySum] :: EntityDef -> !Bool
[entityComments] :: EntityDef -> !Maybe Text
type ExtraLine = [Text]
data FieldDef
FieldDef :: !HaskellName -> !DBName -> !FieldType -> !SqlType -> ![Attr] -> !Bool -> !ReferenceDef -> !Maybe Text -> FieldDef
[fieldHaskell] :: FieldDef -> !HaskellName
[fieldDB] :: FieldDef -> !DBName
[fieldType] :: FieldDef -> !FieldType
[fieldSqlType] :: FieldDef -> !SqlType
[fieldAttrs] :: FieldDef -> ![Attr]
[fieldStrict] :: FieldDef -> !Bool
[fieldReference] :: FieldDef -> !ReferenceDef
[fieldComments] :: FieldDef -> !Maybe Text
data FieldType
FTTypeCon :: Maybe Text -> Text -> FieldType
FTApp :: FieldType -> FieldType -> FieldType
FTList :: FieldType -> FieldType
data ForeignDef
ForeignDef :: !HaskellName -> !DBName -> !HaskellName -> !DBName -> ![(ForeignFieldDef, ForeignFieldDef)] -> ![Attr] -> Bool -> ForeignDef
[foreignRefTableHaskell] :: ForeignDef -> !HaskellName
[foreignRefTableDBName] :: ForeignDef -> !DBName
[foreignConstraintNameHaskell] :: ForeignDef -> !HaskellName
[foreignConstraintNameDBName] :: ForeignDef -> !DBName
[foreignFields] :: ForeignDef -> ![(ForeignFieldDef, ForeignFieldDef)]
[foreignAttrs] :: ForeignDef -> ![Attr]
[foreignNullable] :: ForeignDef -> Bool
type ForeignFieldDef = (HaskellName, DBName)
newtype HaskellName
HaskellName :: Text -> HaskellName
[unHaskellName] :: HaskellName -> Text
data IsNullable
Nullable :: !WhyNullable -> IsNullable
NotNullable :: IsNullable
data OnlyUniqueException
OnlyUniqueException :: String -> OnlyUniqueException
data PersistException
PersistError :: Text -> PersistException
PersistMarshalError :: Text -> PersistException
PersistInvalidField :: Text -> PersistException
PersistForeignConstraintUnmet :: Text -> PersistException
PersistMongoDBError :: Text -> PersistException
PersistMongoDBUnsupported :: Text -> PersistException
data PersistFilter
Eq :: PersistFilter
Ne :: PersistFilter
Gt :: PersistFilter
Lt :: PersistFilter
Ge :: PersistFilter
Le :: PersistFilter
In :: PersistFilter
NotIn :: PersistFilter
data PersistUpdate
Assign :: PersistUpdate
Add :: PersistUpdate
Subtract :: PersistUpdate
Multiply :: PersistUpdate
Divide :: PersistUpdate
BackendSpecificUpdate :: Text -> PersistUpdate
data PersistValue
PersistText :: Text -> PersistValue
PersistByteString :: ByteString -> PersistValue
PersistInt64 :: Int64 -> PersistValue
PersistDouble :: Double -> PersistValue
PersistRational :: Rational -> PersistValue
PersistBool :: Bool -> PersistValue
PersistDay :: Day -> PersistValue
PersistTimeOfDay :: TimeOfDay -> PersistValue
PersistUTCTime :: UTCTime -> PersistValue
PersistNull :: PersistValue
PersistList :: [PersistValue] -> PersistValue
PersistMap :: [(Text, PersistValue)] -> PersistValue
PersistObjectId :: ByteString -> PersistValue
PersistArray :: [PersistValue] -> PersistValue
PersistDbSpecific :: ByteString -> PersistValue
data ReferenceDef
NoReference :: ReferenceDef
ForeignRef :: !HaskellName -> !FieldType -> ReferenceDef
EmbedRef :: EmbedEntityDef -> ReferenceDef
CompositeRef :: CompositeDef -> ReferenceDef
SelfReference :: ReferenceDef
data SqlType
SqlString :: SqlType
SqlInt32 :: SqlType
SqlInt64 :: SqlType
SqlReal :: SqlType
SqlNumeric :: Word32 -> Word32 -> SqlType
SqlBool :: SqlType
SqlDay :: SqlType
SqlTime :: SqlType
SqlDayTime :: SqlType
SqlBlob :: SqlType
SqlOther :: Text -> SqlType
data UniqueDef
UniqueDef :: !HaskellName -> !DBName -> ![(HaskellName, DBName)] -> ![Attr] -> UniqueDef
[uniqueHaskell] :: UniqueDef -> !HaskellName
[uniqueDBName] :: UniqueDef -> !DBName
[uniqueFields] :: UniqueDef -> ![(HaskellName, DBName)]
[uniqueAttrs] :: UniqueDef -> ![Attr]
data UpdateException
KeyNotFound :: String -> UpdateException
UpsertError :: String -> UpdateException
data WhyNullable
ByMaybeAttr :: WhyNullable
ByNullableAttr :: WhyNullable


-- | This module contain MySQL-specific functions.
--   
--   <i>Since: 2.2.8</i>
module Database.Esqueleto.MySQL

-- | (<tt>random()</tt>) Split out into database specific modules because
--   MySQL uses `rand()`.
--   
--   <i>Since: 2.6.0</i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)


-- | This module contain PostgreSQL-specific functions.
--   
--   <i>Since: 2.2.8</i>
module Database.Esqueleto.PostgreSQL

-- | Aggregate mode
data AggMode

-- | ALL
AggModeAll :: AggMode

-- | DISTINCT
AggModeDistinct :: AggMode

-- | (<tt>array_agg</tt>) Concatenate distinct input values, including
--   <tt>NULL</tt>s, into an array.
--   
--   <i>Since: 2.5.3</i>
arrayAggDistinct :: (PersistField a, PersistField [a]) => SqlExpr (Value a) -> SqlExpr (Value (Maybe [a]))
arrayAgg :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe [a]))
arrayAggWith :: AggMode -> SqlExpr (Value a) -> [OrderByClause] -> SqlExpr (Value (Maybe [a]))

-- | (<tt>array_remove</tt>) Remove all elements equal to the given value
--   from the array.
--   
--   <i>Since: 2.5.3</i>
arrayRemove :: SqlExpr (Value [a]) -> SqlExpr (Value a) -> SqlExpr (Value [a])

-- | Remove <tt>NULL</tt> values from an array
arrayRemoveNull :: SqlExpr (Value [Maybe a]) -> SqlExpr (Value [a])

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

-- | (<tt>string_agg</tt>) Concatenate input values separated by a
--   delimiter.
stringAggWith :: SqlString s => AggMode -> SqlExpr (Value s) -> SqlExpr (Value s) -> [OrderByClause] -> SqlExpr (Value (Maybe s))

-- | Coalesce an array with an empty default value
maybeArray :: (PersistField a, PersistField [a]) => SqlExpr (Value (Maybe [a])) -> SqlExpr (Value [a])

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

-- | (<tt>random()</tt>) Split out into database specific modules because
--   MySQL uses `rand()`.
--   
--   <i>Since: 2.6.0</i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
upsert :: (MonadIO m, PersistEntity record, OnlyOneUniqueKey record, PersistRecordBackend record SqlBackend, IsPersistBackend (PersistEntityBackend record)) => record -> [SqlExpr (Update record)] -> ReaderT SqlBackend m (Entity record)
upsertBy :: (MonadIO m, PersistEntity record, IsPersistBackend (PersistEntityBackend record)) => Unique record -> record -> [SqlExpr (Update record)] -> ReaderT SqlBackend m (Entity record)

-- | Inserts into a table the results of a query similar to
--   <a>insertSelect</a> but allows to update values that violate a
--   constraint during insertions.
--   
--   Example of usage:
--   
--   <pre>
--   share [ mkPersist sqlSettings
--         , mkDeleteCascade sqlSettings
--         , mkMigrate "migrate"
--         ] [persistLowerCase|
--     Bar
--       num Int
--       deriving Eq Show
--     Foo
--       num Int
--       UniqueFoo num
--       deriving Eq Show
--   |]
--   
--   insertSelectWithConflict
--     UniqueFoo -- (UniqueFoo undefined) or (UniqueFoo anyNumber) would also work
--     (from $ b -&gt;
--       return $ Foo &lt;# (b ^. BarNum)
--     )
--     (current excluded -&gt;
--       [FooNum =. (current ^. FooNum) +. (excluded ^. FooNum)]
--     )
--   </pre>
--   
--   Inserts to table Foo all Bar.num values and in case of conflict
--   SomeFooUnique, the conflicting value is updated to the current plus
--   the excluded.
insertSelectWithConflict :: forall a m val. (FinalResult a, KnowResult a ~ Unique val, MonadIO m, PersistEntity val) => a -> SqlQuery (SqlExpr (Insertion val)) -> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)]) -> SqlWriteT m ()

-- | Same as <a>insertSelectWithConflict</a> but returns the number of rows
--   affected.
insertSelectWithConflictCount :: forall a val m. (FinalResult a, KnowResult a ~ Unique val, MonadIO m, PersistEntity val) => a -> SqlQuery (SqlExpr (Insertion val)) -> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)]) -> SqlWriteT m Int64

-- | (Internal) Create a custom aggregate functions with aggregate mode
--   
--   <i>Do</i> <i>not</i> use this function directly, instead define a new
--   function and give it a type (see <a>unsafeSqlBinOp</a>)
unsafeSqlAggregateFunction :: UnsafeSqlFunctionArgument a => Builder -> AggMode -> a -> [OrderByClause] -> SqlExpr (Value b)
instance GHC.Show.Show Database.Esqueleto.PostgreSQL.AggMode


-- | This module contains PostgreSQL-specific JSON functions.
--   
--   A couple of things to keep in mind about this module:
--   
--   <ul>
--   <li>The <tt>Type</tt> column in the PostgreSQL documentation tables
--   are the types of the right operand, the left is always
--   <tt>jsonb</tt>.</li>
--   <li>Since these operators can all take <tt>NULL</tt> values as their
--   input, and most can also output <tt>NULL</tt> values (even when the
--   inputs are guaranteed to not be NULL), all <a>JSONB</a> values are
--   wrapped in <a>Maybe</a>. This also makes it easier to chain them. (cf.
--   <a>JSONBExpr</a>) Just use the <a>just</a> function to lift any
--   non-<a>Maybe</a> JSONB values in case it doesn't type check.</li>
--   <li>As long as the previous operator's resulting value is a
--   <a>JSONBExpr</a>, any other JSON operator can be used to transform the
--   JSON further. (e.g. <tt>[1,2,3] -&gt; 1 @&gt; 2</tt>)</li>
--   </ul>
--   
--   <i>The PostgreSQL version the functions work with are included</i>
--   <i>in their description.</i>
module Database.Esqueleto.PostgreSQL.JSON

-- | Newtype wrapper around any type with a JSON representation.
newtype JSONB a
JSONB :: a -> JSONB a
[unJSONB] :: JSONB a -> a

-- | <a>SqlExpr</a> of a NULL-able <a>JSONB</a> value. Hence the
--   <a>Maybe</a>.
--   
--   Note: NULL here is a PostgreSQL NULL, not a JSON <a>null</a>
type JSONBExpr a = SqlExpr (Value (Maybe (JSONB a)))

-- | Convenience function to lift a regular value into a <a>JSONB</a>
--   expression.
jsonbVal :: (FromJSON a, ToJSON a) => a -> JSONBExpr a

-- | Used with certain JSON operators.
--   
--   This data type has <a>Num</a> and <a>IsString</a> instances for ease
--   of use by using integer and string literals.
--   
--   <pre>
--   &gt;&gt;&gt; 3 :: JSONAccessor
--   JSONIndex 3
--   
--   &gt;&gt;&gt; -3 :: JSONAccessor
--   JSONIndex -3
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; "name" :: JSONAccessor
--   JSONKey "name"
--   </pre>
--   
--   NOTE: DO NOT USE ANY OF THE <a>Num</a> METHODS ON THIS TYPE!
data JSONAccessor
JSONIndex :: Int -> JSONAccessor
JSONKey :: Text -> JSONAccessor

-- | <i>Requires PostgreSQL version &gt;= 9.3</i>
--   
--   This function extracts the jsonb value from a JSON array or object,
--   depending on whether you use an <tt>int</tt> or a <tt>text</tt>. (cf.
--   <a>JSONAccessor</a>)
--   
--   As long as the left operand is <tt>jsonb</tt>, this function will not
--   throw an exception, but will return <tt>NULL</tt> when an <tt>int</tt>
--   is used on anything other than a JSON array, or a <tt>text</tt> is
--   used on anything other than a JSON object.
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type | Description                                |  Example                                         | Example Result
--   ----+------+--------------------------------------------+--------------------------------------------------+----------------
--    -&gt; | int  | Get JSON array element (indexed from zero) | '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json-&gt;2 | {"c":"baz"}
--    -&gt; | text | Get JSON object field by key               | '{"a": {"b":"foo"}}'::json-&gt;<tt>a</tt>                  | {"b":"foo"}
--   </pre>
(->.) :: JSONBExpr a -> JSONAccessor -> JSONBExpr b
infixl 6 ->.

-- | <i>Requires PostgreSQL version &gt;= 9.3</i>
--   
--   Identical to <a>-&gt;.</a>, but the resulting DB type is a
--   <tt>text</tt>, so it could be chained with anything that uses
--   <tt>text</tt>.
--   
--   <b>CAUTION: if the "scalar" JSON value <tt>null</tt> is the result</b>
--   <b>of this function, PostgreSQL will interpret it as a</b>
--   <b>PostgreSQL <tt>NULL</tt> value, and will therefore be
--   <a>Nothing</a></b> <b>instead of (Just "null")</b>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--        | Type | Description                    |  Example                    | Example Result
--   -----+------+--------------------------------+-----------------------------+----------------
--    -&gt;&gt; | int  | Get JSON array element as text | '[1,2,3]'::json-&gt;&gt;2         | 3
--    -&gt;&gt; | text | Get JSON object field as text  | '{"a":1,"b":2}'::json-&gt;&gt;<tt>b</tt> | 2
--   </pre>
(->>.) :: JSONBExpr a -> JSONAccessor -> SqlExpr (Value (Maybe Text))
infixl 6 ->>.

-- | <i>Requires PostgreSQL version &gt;= 9.3</i>
--   
--   This operator can be used to select a JSON value from deep inside
--   another one. It only works on objects and arrays and will result in
--   <tt>NULL</tt> (<a>Nothing</a>) when encountering any other JSON type.
--   
--   The <a>Text</a>s used in the right operand list will always select an
--   object field, but can also select an index from a JSON array if that
--   text is parsable as an integer.
--   
--   Consider the following:
--   
--   <pre>
--   x ^. TestBody #&gt;. ["0","1"]
--   </pre>
--   
--   The following JSON values in the <tt>test</tt> table's <tt>body</tt>
--   column will be affected:
--   
--   <pre>
--    Values in column                     | Resulting value
--   --------------------------------------+----------------------------
--   {"0":{"1":"Got it!"}}                 | "Got it!"
--   {"0":[null,["Got it!","Even here!"]]} | ["Got it!", "Even here!"]
--   [{"1":"Got it again!"}]               | "Got it again!"
--   [[null,{"Wow":"so deep!"}]]           | {"Wow": "so deep!"}
--   false                                 | NULL
--   "nope"                                | NULL
--   3.14                                  | NULL
--   </pre>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--        | Type   | Description                       |  Example                                   | Example Result
--   -----+--------+-----------------------------------+--------------------------------------------+----------------
--    #&gt;  | text[] | Get JSON object at specified path | '{"a": {"b":{"c": "foo"}}}'::json#&gt;'{a,b}' | {"c": "foo"}
--   </pre>
(#>.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 #>.

-- | <i>Requires PostgreSQL version &gt;= 9.3</i>
--   
--   This function is to <a>#&gt;.</a> as <a>-&gt;&gt;.</a> is to
--   <a>-&gt;.</a>
--   
--   <b>CAUTION: if the "scalar" JSON value <tt>null</tt> is the result</b>
--   <b>of this function, PostgreSQL will interpret it as a</b>
--   <b>PostgreSQL <tt>NULL</tt> value, and will therefore be
--   <a>Nothing</a></b> <b>instead of (Just "null")</b>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--        | Type   | Description                               |  Example                                    | Example Result
--   -----+--------+-------------------------------------------+---------------------------------------------+----------------
--    #&gt;&gt; | text[] | Get JSON object at specified path as text | '{"a":[1,2,3],"b":[4,5,6]}'::json#&gt;&gt;'{a,2}' | 3
--   </pre>
(#>>.) :: JSONBExpr a -> [Text] -> SqlExpr (Value (Maybe Text))
infixl 6 #>>.

-- | <i>Requires PostgreSQL version &gt;= 9.4</i>
--   
--   This operator checks for the JSON value on the right to be a subset of
--   the JSON value on the left.
--   
--   Examples of the usage of this operator can be found in the
--   Database.Persist.Postgresql.JSON module.
--   
--   (here:
--   <a>https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html</a>)
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type  | Description                                                 |  Example
--   ----+-------+-------------------------------------------------------------+---------------------------------------------
--    @&gt; | jsonb | Does the left JSON value contain within it the right value? | '{"a":1, "b":2}'::jsonb @&gt; '{"b":2}'::jsonb
--   </pre>
(@>.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)
infixl 6 @>.

-- | <i>Requires PostgreSQL version &gt;= 9.4</i>
--   
--   This operator works the same as <a>@&gt;.</a>, just with the arguments
--   flipped. So it checks for the JSON value on the left to be a subset of
--   JSON value on the right.
--   
--   Examples of the usage of this operator can be found in the
--   Database.Persist.Postgresql.JSON module.
--   
--   (here:
--   <a>https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html</a>)
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type  | Description                                              |  Example
--   ----+-------+----------------------------------------------------------+---------------------------------------------
--    &lt;@ | jsonb | Is the left JSON value contained within the right value? | '{"b":2}'::jsonb &lt;@ '{"a":1, "b":2}'::jsonb
--   </pre>
(<@.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)
infixl 6 <@.

-- | <i>Requires PostgreSQL version &gt;= 9.4</i>
--   
--   This operator checks if the given text is a top-level member of the
--   JSON value on the left. This means a top-level field in an object, a
--   top-level string in an array or just a string value.
--   
--   Examples of the usage of this operator can be found in the
--   Database.Persist.Postgresql.JSON module.
--   
--   (here:
--   <a>https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html</a>)
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--      | Type | Description                                                     |  Example
--   ---+------+-----------------------------------------------------------------+-------------------------------
--    ? | text | Does the string exist as a top-level key within the JSON value? | '{"a":1, "b":2}'::jsonb ? <tt>b</tt>
--   </pre>
(?.) :: JSONBExpr a -> Text -> SqlExpr (Value Bool)
infixl 6 ?.

-- | <i>Requires PostgreSQL version &gt;= 9.4</i>
--   
--   This operator checks if <b>ANY</b> of the given texts is a top-level
--   member of the JSON value on the left. This means any top-level field
--   in an object, any top-level string in an array or just a string value.
--   
--   Examples of the usage of this operator can be found in the
--   Database.Persist.Postgresql.JSON module.
--   
--   (here:
--   <a>https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html</a>)
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type   | Description                                            |  Example
--   ----+--------+--------------------------------------------------------+---------------------------------------------------
--    ?| | text[] | Do any of these array strings exist as top-level keys? | '{"a":1, "b":2, "c":3}'::jsonb ?| array[<tt>b</tt>, <tt>c</tt>]
--   </pre>
(?|.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)
infixl 6 ?|.

-- | <i>Requires PostgreSQL version &gt;= 9.4</i>
--   
--   This operator checks if <b>ALL</b> of the given texts are top-level
--   members of the JSON value on the left. This means a top-level field in
--   an object, a top-level string in an array or just a string value.
--   
--   Examples of the usage of this operator can be found in the
--   Database.Persist.Postgresql.JSON module.
--   
--   (here:
--   <a>https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html</a>)
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type   | Description                                            |  Example
--   ----+--------+--------------------------------------------------------+----------------------------------------
--    ?&amp; | text[] | Do all of these array strings exist as top-level keys? | '["a", "b"]'::jsonb ?&amp; array[<tt>a</tt>, <tt>b</tt>]
--   </pre>
(?&.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)
infixl 6 ?&.

-- | <i>Requires PostgreSQL version &gt;= 9.5</i>
--   
--   This operator can remove a key from an object or a string element from
--   an array when using text, and remove certain elements by index from an
--   array when using integers.
--   
--   Negative integers delete counting from the end of the array. (e.g.
--   <tt>-1</tt> being the last element, <tt>-2</tt> being the second to
--   last, etc.)
--   
--   <b>CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN USED ON ANYTHING
--   OTHER</b> <b>THAN OBJECTS OR ARRAYS WHEN USING TEXT, AND ANYTHING
--   OTHER THAN ARRAYS</b> <b>WHEN USING INTEGERS!</b>
--   
--   <h3><b>Objects and arrays</b></h3>
--   
--   <pre>
--   {"a": 3.14}            - "a"         == {}
--   {"a": "b"}             - "b"         == {"a": "b"}
--   {"a": 3.14}            - "a"         == {}
--   {"a": 3.14, "c": true} - "a"         == {"c": true}
--   ["a", 2, "c"]          - "a"         == [2, "c"] -- can remove strings from arrays
--   [true, "b", 5]         - 0           == ["b", 5]
--   [true, "b", 5]         - 3           == [true, "b", 5]
--   [true, "b", 5]         - -1          == [true, "b"]
--   [true, "b", 5]         - -4          == [true, "b", 5]
--   []                     - 1           == []
--   {"1": true}            - 1           == ERROR: cannot delete from object using integer index
--   1                      - &lt;anything&gt;  == ERROR: cannot delete from scalar
--   "a"                    - &lt;anything&gt;  == ERROR: cannot delete from scalar
--   true                   - &lt;anything&gt;  == ERROR: cannot delete from scalar
--   null                   - &lt;anything&gt;  == ERROR: cannot delete from scalar
--   </pre>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--      | Type    | Description                                                            |  Example
--   ---+---------+------------------------------------------------------------------------+-------------------------------------------------
--    - | text    | Delete key/value pair or string element from left operand.             | '{"a": "b"}'::jsonb - <tt>a</tt>
--      |         | Key/value pairs are matched based on their key value.                  |
--    - | integer | Delete the array element with specified index (Negative integers count | '["a", "b"]'::jsonb - 1
--      |         | from the end). Throws an error if top level container is not an array. |
--   </pre>
(-.) :: JSONBExpr a -> JSONAccessor -> JSONBExpr b
infixl 6 -.

-- | <i>Requires PostgreSQL version &gt;= 10</i>
--   
--   Removes a set of keys from an object, or string elements from an
--   array.
--   
--   This is the same operator internally as <a>-.</a>, but the option to
--   use a <tt>text array</tt>, instead of <tt>text</tt> or
--   <tt>integer</tt> was only added in version 10. That's why this
--   function is seperate from <a>-.</a>
--   
--   NOTE: The following is equivalent:
--   
--   <pre>
--   {some JSON expression} -. "a" -. "b"
--   </pre>
--   
--   is equivalent to
--   
--   <pre>
--   {some JSON expression} --. ["a","b"]
--   </pre>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--      | Type    | Description                                                            |  Example
--   ---+---------+------------------------------------------------------------------------+-------------------------------------------------
--    - | text[]  | Delete multiple key/value pairs or string elements from left operand.  | '{"a": "b", "c": "d"}'::jsonb - '{a,c}'::text[]
--      |         | Key/value pairs are matched based on their key value.                  |
--   </pre>
(--.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 --.

-- | <i>Requires PostgreSQL version &gt;= 9.5</i>
--   
--   This operator can remove elements nested in an object.
--   
--   If a <a>Text</a> is not parsable as a number when selecting in an
--   array (even when halfway through the selection) an exception will be
--   thrown.
--   
--   Negative integers delete counting from the end of an array. (e.g.
--   <tt>-1</tt> being the last element, <tt>-2</tt> being the second to
--   last, etc.)
--   
--   <b>CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN USED</b> <b>ON
--   ANYTHING OTHER THAN OBJECTS OR ARRAYS, AND WILL</b> <b>ALSO THROW WHEN
--   TRYING TO SELECT AN ARRAY ELEMENT WITH</b> <b>A NON-INTEGER TEXT</b>
--   
--   <h3><b>Objects</b></h3>
--   
--   <pre>
--   {"a": 3.14, "b": null}        #- []        == {"a": 3.14, "b": null}
--   {"a": 3.14, "b": null}        #- ["a"]     == {"b": null}
--   {"a": 3.14, "b": null}        #- ["a","b"] == {"a": 3.14, "b": null}
--   {"a": {"b":false}, "b": null} #- ["a","b"] == {"a": {}, "b": null}
--   </pre>
--   
--   <h3><b>Arrays</b></h3>
--   
--   <pre>
--   [true, {"b":null}, 5]       #- []            == [true, {"b":null}, 5]
--   [true, {"b":null}, 5]       #- ["0"]         == [{"b":null}, 5]
--   [true, {"b":null}, 5]       #- ["b"]         == ERROR: path element at position 1 is not an integer: "b"
--   [true, {"b":null}, 5]       #- ["1","b"]     == [true, {}, 5]
--   [true, {"b":null}, 5]       #- ["-2","b"]    == [true, {}, 5]
--   {"a": {"b":[false,4,null]}} #- ["a","b","2"] == {"a": {"b":[false,4]}}
--   {"a": {"b":[false,4,null]}} #- ["a","b","c"] == ERROR: path element at position 3 is not an integer: "c"
--   </pre>
--   
--   <h3><b>Other values</b></h3>
--   
--   <pre>
--   1    #- {anything} == ERROR: cannot delete from scalar
--   "a"  #- {anything} == ERROR: cannot delete from scalar
--   true #- {anything} == ERROR: cannot delete from scalar
--   null #- {anything} == ERROR: cannot delete from scalar
--   </pre>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type   | Description                                             |  Example
--   ----+--------+---------------------------------------------------------+------------------------------------
--    #- | text[] | Delete the field or element with specified path         | '["a", {"b":1}]'::jsonb #- '{1,b}'
--       |        | (for JSON arrays, negative integers count from the end) |
--   </pre>
(#-.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 #-.

-- | <i>Requires PostgreSQL version &gt;= 9.5</i>
--   
--   This operator concatenates two JSON values. The behaviour is
--   self-evident when used on two arrays, but the behaviour on different
--   combinations of JSON values might behave unexpectedly.
--   
--   <b>CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN CONCATENATING</b>
--   <b>A JSON OBJECT WITH A JSON SCALAR VALUE!</b>
--   
--   <h3><b>Arrays</b></h3>
--   
--   This operator is a standard concatenation function when used on
--   arrays:
--   
--   <pre>
--   [1,2]   || [2,3]   == [1,2,2,3]
--   []      || [1,2,3] == [1,2,3]
--   [1,2,3] || []      == [1,2,3]
--   </pre>
--   
--   <h3><b>Objects</b></h3>
--   
--   When concatenating JSON objects with other JSON objects, the fields
--   from the JSON object on the right are added to the JSON object on the
--   left. When concatenating a JSON object with a JSON array, the object
--   will be inserted into the array; either on the left or right,
--   depending on the position relative to the operator.
--   
--   When concatening an object with a scalar value, an exception is
--   thrown.
--   
--   <pre>
--   {"a": 3.14}                    || {"b": true}         == {"a": 3.14, "b": true}
--   {"a": "b"}                     || {"a": null}         == {"a": null}
--   {"a": {"b": true, "c": false}} || {"a": {"b": false}} == {"a": {"b": false}}
--   {"a": 3.14}                    || [1,null]            == [{"a": 3.14},1,null]
--   [1,null]                       || {"a": 3.14}         == [1,null,{"a": 3.14}]
--   1                              || {"a": 3.14}         == ERROR: invalid concatenation of jsonb objects
--   {"a": 3.14}                    || false               == ERROR: invalid concatenation of jsonb objects
--   </pre>
--   
--   <h3><b>Scalar values</b></h3>
--   
--   Scalar values can be thought of as being singleton arrays when used
--   with this operator. This rule does not apply when concatenating with
--   JSON objects.
--   
--   <pre>
--   1          || null       == [1,null]
--   true       || "a"        == [true,"a"]
--   [1,2]      || false      == [1,2,false]
--   null       || [1,"a"]    == [null,1,"a"]
--   {"a":3.14} || true       == ERROR: invalid concatenation of jsonb objects
--   3.14       || {"a":3.14} == ERROR: invalid concatenation of jsonb objects
--   {"a":3.14} || [true]     == [{"a":3.14},true]
--   [false]    || {"a":3.14} == [false,{"a":3.14}]
--   </pre>
--   
--   <h3><b>PostgreSQL Documentation</b></h3>
--   
--   <pre>
--       | Type  | Description                                         |  Example
--   ----+-------+-----------------------------------------------------+--------------------------------------------
--    || | jsonb | Concatenate two jsonb values into a new jsonb value | '["a", "b"]'::jsonb || '["c", "d"]'::jsonb
--   </pre>
--   
--   <i>Note: The <tt>||</tt> operator concatenates the elements at the top
--   level of</i> <i>each of its operands. It does not operate
--   recursively.</i>
--   
--   <i>For example, if both operands are objects with a common key field
--   name,</i> <i>the value of the field in the result will just be the
--   value from the right</i> <i>hand operand.</i>
(||.) :: JSONBExpr a -> JSONBExpr b -> JSONBExpr c
infixl 6 ||.


-- | This module contain SQLite-specific functions.
--   
--   <i>Since: 2.2.8</i>
module Database.Esqueleto.SQLite

-- | (<tt>random()</tt>) Split out into database specific modules because
--   MySQL uses `rand()`.
--   
--   <i>Since: 2.6.0</i>
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
