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

-- | Type-safe EDSL for SQL queries on persistent backends.
--   
--   esqueleto is a bare bones, type-safe EDSL for SQL queries
--   that works with unmodified persistent SQL backends. Its
--   language closely resembles SQL, so you don't have to learn new
--   concepts, just new syntax, and it's fairly easy to predict the
--   generated SQL and optimize it for your backend. Most kinds of errors
--   committed when writing SQL are caught as compile-time
--   errors---although it is possible to write type-checked
--   esqueleto queries that fail at runtime.
--   
--   persistent is a library for type-safe data serialization. It
--   has many kinds of backends, such as SQL backends
--   (persistent-mysql, persistent-postgresql,
--   persistent-sqlite) and NoSQL backends
--   (persistent-mongoDB). While persistent is a nice
--   library for storing and retrieving records, including with filters, it
--   does not try to support some of the features that are specific to SQL
--   backends. In particular, esqueleto is the recommended library
--   for type-safe JOINs on persistent SQL backends. (The
--   alternative is using raw SQL, but that's error prone and does not
--   offer any composability.)
--   
--   Currently, SELECTs, UPDATEs, INSERTs and
--   DELETEs are supported. Not all SQL features are available,
--   but most of them can be easily added (especially functions), so please
--   open an issue or send a pull request if you need anything that is not
--   covered by esqueleto on
--   https://github.com/bitemyapp/esqueleto.
--   
--   The name of this library means "skeleton" in Portuguese and contains
--   all three SQL letters in the correct order =). It was inspired by
--   Scala's Squeryl but created from scratch.
@package esqueleto
@version 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:
--   
--   
--   escape-char [character] escape-char . escape-char [character] escape-char
--               ^^^^^^^^^^^                           ^^^^^^^^^^^
--               table name                            column name
--   
data TableAccess
TableAccess :: Text -> Text -> TableAccess
[tableAccessTable] :: TableAccess -> Text
[tableAccessColumn] :: TableAccess -> Text

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

-- | This function uses the connEscapeName function in the
--   SqlBackend 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
--   Database.Esqueleto 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 from query with an entity. from does
--   two kinds of magic using fromStart, fromJoin and
--   fromFinish:
--   
--   
--   
- The simple but tedious magic of allowing tuples to be used.
--   
- The more advanced magic of creating JOINs. The
--   JOIN is processed from right to left. The rightmost entity of
--   the JOIN is created with fromStart. Each JOIN
--   step is then translated into a call to fromJoin. In the end,
--   fromFinish is called to materialize the JOIN.
--   
fromStart :: (PersistEntity a, BackendCompatible SqlBackend (PersistEntityBackend a)) => SqlQuery (SqlExpr (PreprocessedFrom (SqlExpr (Entity a))))

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

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

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

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

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

-- | GROUP BY clause. You can enclose multiple columns in a tuple.
--   
--   
--   select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy (bar ^. BarId, bar ^. BarName)
--     return (bar ^. BarId, bar ^. BarName, countRows)
--   
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   let to restrict the more general countRows to
--   SqlSqlExpr (Value Int) to avoid ambiguity---the second use of
--   countRows has its type restricted by the :: Int
--   below):
--   
--   
--   r <- select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy $ bar ^. BarName
--     let countRows' = countRows
--     orderBy [asc countRows']
--     return (bar ^. BarName, countRows')
--   forM_ r $ \(Value name, Value count) -> do
--     print name
--     print (count :: Int)
--   
--   
--   
Need more columns?
--   
--   The ToSomeValues class is defined for SqlExpr and tuples
--   of SqlExprs. 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 groupBy call like this:
--   
--   
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   
groupBy :: ToSomeValues a => a -> SqlQuery ()

-- | ORDER BY clause. See also asc and desc.
--   
--   Multiple calls to orderBy get concatenated on the final query,
--   including distinctOnOrderBy.
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

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

-- | OFFSET. Usually used with limit.
offset :: Int64 -> SqlQuery ()

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

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

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

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

-- | ORDER BY random() clause.
--   
--   Since: 1.3.10

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

-- | HAVING.
--   
--   Since: 1.2.2
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

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

-- | 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.
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

-- | Execute a subquery SELECT in a SqlExpr. The query
--   passed to this function will only return a single result - it has a
--   LIMIT 1 passed in to the query to make it safe, and the
--   return type is Maybe to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing joinV . subSelect,
--   then consider using subSelectMaybe.
--   
--   If you're performing a countRows, then you can use
--   subSelectCount 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 subSelectUnsafe, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

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

-- | Performs a COUNT of the given query in a subSelect
--   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 SELECT in a SqlExpr that returns a
--   list. This is an alias for subList_select 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:
--   
--   
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   
--   
--   The following query will return the name of the user.
--   
--   
--   getUserWithName =
--       select $
--       from $ user ->
--       pure (user, subSelectForeign user UserProfile (^. ProfileName)
--   
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 SELECT in a SqlExpr. This function
--   is unsafe, because it can throw runtime exceptions in two cases:
--   
--   
--   
- If the query passed has 0 result rows, then it will return a
--   NULL value. The persistent parsing operations will
--   fail on an unexpected NULL.
--   
- 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".
--   
--   
--   This function is safe if you guarantee that exactly one row will be
--   returned, or if the result already has a Maybe type for some
--   reason.
--   
--   For variants with the safety encoded already, see subSelect and
--   subSelectMaybe. For the most common safe use of this, see
--   subSelectCount.
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)

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

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

-- | NULL value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested Maybes in a Value 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)

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

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

-- | COUNT(DISTINCT x).
--   
--   Since: 2.4.1
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 *.

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

-- | Deprecated: Since 2.6.0: random_ is not uniform across all
--   databases! Please use a specific one such as random_,
--   random_, or random_
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.
--   
--   Caveat: Trying to use castNum from Double to
--   Int will not result in an integer, the original fractional
--   number will still be used! Use round_, ceiling_ or
--   floor_ instead.
--   
--   Safety: This operation is mostly safe due to the Num
--   constraint between the types and the fact that RDBMSs usually allow
--   numbers of different types to be used interchangeably. However, there
--   may still be issues with the query not being accepted by the RDBMS or
--   persistent not being able to parse it.
--   
--   Since: 2.2.9
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

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

-- | COALESCE 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.
--   
--   Since: 1.4.3
coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Execute a subquery SELECT 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 just but for ValueList. Most of the time you
--   won't need it, though, because you can use just from inside
--   subList_select or Just from inside valList.
--   
--   Since: 2.2.12
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

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

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

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

-- | SET clause used on UPDATEs. Note that while it's not
--   a type error to use this function on a SELECT, it will most
--   certainly result in a runtime error.
set :: 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 PersistField constructor to SqlExpr Value
--   arguments.
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)

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

-- | CASE statement. For example:
--   
--   
--   select $
--   return $
--   case_
--      [ when_
--          (exists $
--          from $ \p -> do
--          where_ (p ^. PersonName ==. val "Mike"))
--        then_
--          (sub_select $
--          from $ \v -> do
--          let sub =
--                  from $ \c -> do
--                  where_ (c ^. PersonName ==. val "Mike")
--                  return (c ^. PersonFavNum)
--          where_ (v ^. PersonFavNum >. sub_select sub)
--          return $ count (v ^. PersonName) +. val (1 :: Int)) ]
--      (else_ $ val (-1))
--   
--   
--   This query is a bit complicated, but basically it checks if a person
--   named "Mike" exists, and if that person does, run the
--   subquery to find out how many people have a ranking (by Fav Num)
--   higher than "Mike".
--   
--   NOTE: There are a few things to be aware about this statement.
--   
--   
--   
- This only implements the full CASE statement, it does not
--   implement the "simple" CASE statement.
--   
- At least one when_ and then_ is mandatory otherwise
--   it will emit an error.
--   
- The else_ is also mandatory, unlike the SQL statement in
--   which if the ELSE is omitted it will return a NULL.
--   You can reproduce this via nothing.
--   
--   
--   Since: 2.1.2
case_ :: 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 Id to
--   be that of another entity. For example:
--   
--   
--   Bar
--     barNum Int
--   Foo
--     bar BarId
--     fooNum Int
--     Primary bar
--   
--   
--   In this example, Bar is said to be the BaseEnt(ity), and Foo the
--   child. To model this in Esqueleto, declare:
--   
--   
--   instance ToBaseId Foo where
--     type BaseEnt Foo = Bar
--     toBaseIdWitness barId = FooKey barId
--   
--   
--   Now you're able to write queries such as:
--   
--   
--   select $
--   from $ (bar `<a>InnerJoin</a>` foo) -> do
--   on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
--   return (bar, foo)
--   
--   
--   Note: this function may be unsafe to use in conditions not like the
--   one of the example above.
--   
--   Since: 2.4.3
toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))

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

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

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

-- | A single value (as opposed to a whole entity). You may use
--   (^.) or (?.) to get a Value
--   from an Entity.
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 subList_select,
--   valList, in_ and exists).
newtype ValueList a
ValueList :: a -> ValueList a

-- | A wrapper type for for any expr (Value a) 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 groupBy can take
--   tuples, like groupBy (foo ^. FooId, foo ^.
--   FooName, foo ^. FooType).
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 Unique key on a record to the
--   UniqueDef 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 INNER JOIN (see
--   LeftOuterJoin for an example).
data InnerJoin a b
InnerJoin :: a -> b -> InnerJoin a b
infixl 2 `InnerJoin`
infixl 2 `InnerJoin`

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

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

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

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

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

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

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

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

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

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

-- | (Internal) Functions that operate on types (that should be) of kind
--   JoinKind.
class IsJoinKind join

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Class that enables one to use toBaseId to convert an entity's
--   key on a query into another (cf. toBaseId).
class ToBaseId ent where {
    
    -- | 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

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

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

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

-- | Exception data type for esqueleto 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 esqueleto using SqlPersistT.
newtype SqlQuery a
Q :: WriterT SideData (State IdentState) a -> SqlQuery a
[unQ] :: SqlQuery a -> WriterT SideData (State IdentState) a

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

-- | Side data written by SqlQuery.
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 DISTINCT "clause".
data DistinctClause

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

-- | Only DISTINCT, SQL standard.
DistinctStandard :: DistinctClause

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

-- | A part of a FROM 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 SET clause.
newtype SetClause
SetClause :: SqlExpr (Value ()) -> SetClause

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

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

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

-- | A HAVING cause.
type HavingClause = WhereClause

-- | A ORDER BY clause.
type OrderByClause = SqlExpr OrderBy

-- | A LIMIT 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 Ident. If possible, use the given DBName.
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

-- | Deprecated: Since 2.6.0: rand ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.
[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 INSERT INTO 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 should
--   not use this function directly since its type is very general,
--   you should always use it with an explicit type signature. For example:
--   
--   
--   (==.) :: SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value Bool)
--   (==.) = unsafeSqlBinOp " = "
--   
--   
--   In the example above, we constraint the arguments to be of the same
--   type and constraint the result to be a boolean value.
unsafeSqlBinOp :: Builder -> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)

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

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

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

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

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

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

-- | (Internal) This class allows unsafeSqlFunction to work with
--   different numbers of arguments; specifically it allows providing
--   arguments to a sql function via an n-tuple of SqlExpr (Value
--   _) 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.
--   toArgList ((a,b),(c,d)) is the same as toArgList
--   (a,b,c,d).
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 not use this function unless you know
--   what you're doing!
veryUnsafeCoerceSqlExprValue :: SqlExpr (Value a) -> SqlExpr (Value b)

-- | (Internal) Coerce a value's type from 'SqlExpr (ValueList a)' to
--   'SqlExpr (Value a)'. Does not work with empty lists.
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)

-- | (Internal) Execute an esqueleto SELECT
--   SqlQuery inside persistent's SqlPersistT monad.
rawSelectSource :: (SqlSelect a r, MonadIO m1, MonadIO m2) => Mode -> SqlQuery a -> SqlReadT m1 (Acquire (ConduitT () r m2 ()))

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

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

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

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

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

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

-- | Same as update, 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 SqlQuery into a SQL query.
--   
--   Note: if you're curious about the SQL query being generated by
--   esqueleto, instead of manually using this function (which is
--   possible but tedious), see the renderQueryToText function
--   (along with renderQuerySelect, renderQueryUpdate, etc).
toRawSql :: (SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])

-- | Renders a SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 toRawSql.
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 SqlQuery into
--   actual results.
--   
--   This looks very similar to RawSql, and it is! However, there
--   are some crucial differences and ultimately they're different classes.
class SqlSelect a r | a -> r, r -> a

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

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

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

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

-- | Materialize a SqlExpr (Value a).
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 PersistField for every selected value.
--   
--   Since: 2.4.2
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

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

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

-- | An exception thrown by RenderExpr - 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
--   Database.Esqueleto if possible.
module Database.Esqueleto.Internal.Language

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

-- | A single value (as opposed to a whole entity). You may use
--   (^.) or (?.) to get a Value
--   from an Entity.
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 subList_select,
--   valList, in_ and exists).
newtype ValueList a
ValueList :: a -> ValueList a

-- | A wrapper type for for any expr (Value a) 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 groupBy can take
--   tuples, like groupBy (foo ^. FooId, foo ^.
--   FooName, foo ^. FooType).
class ToSomeValues a
toSomeValues :: ToSomeValues a => a -> [SomeValue]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Class that enables one to use toBaseId to convert an entity's
--   key on a query into another (cf. toBaseId).
class ToBaseId ent where {
    
    -- | 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 JOIN.
data JoinKind

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

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

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

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

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

-- | (Internal) Functions that operate on types (that should be) of kind
--   JoinKind.
class IsJoinKind join

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

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

-- | This class witnesses that two backend are compatible, and that you can
--   convert from the sub backend into the sup backend.
--   This is similar to the HasPersistBackend and
--   IsPersistBackend classes, but where you don't want to fix the
--   type associated with the PersistEntityBackend of a record.
--   
--   Generally speaking, where you might have:
--   
--   
--   foo ::
--     ( PersistEntity record
--     , PeristEntityBackend record ~ BaseBackend backend
--     , IsSqlBackend backend
--     )
--   
--   
--   this can be replaced with:
--   
--   
--   foo ::
--     ( PersistEntity record,
--     , PersistEntityBackend record ~ backend
--     , BackendCompatible SqlBackend backend
--     )
--   
--   
--   This works for SqlReadBackend because of the instance
--   BackendCompatible SqlBackend
--   SqlReadBackend, without needing to go through the
--   BaseBackend type family.
--   
--   Likewise, functions that are currently hardcoded to use
--   SqlBackend can be generalized:
--   
--   
--   -- before:
--   asdf :: ReaderT SqlBackend m ()
--   asdf = pure ()
--   
--   -- after:
--   asdf' :: BackendCompatible SqlBackend backend => ReaderT backend m ()
--   asdf' = withReaderT projectBackend asdf
--   
class BackendCompatible sup sub
projectBackend :: BackendCompatible sup sub => sub -> sup

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

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

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

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

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

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

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

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

-- | GROUP BY clause. You can enclose multiple columns in a tuple.
--   
--   
--   select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy (bar ^. BarId, bar ^. BarName)
--     return (bar ^. BarId, bar ^. BarName, countRows)
--   
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   let to restrict the more general countRows to
--   SqlSqlExpr (Value Int) to avoid ambiguity---the second use of
--   countRows has its type restricted by the :: Int
--   below):
--   
--   
--   r <- select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy $ bar ^. BarName
--     let countRows' = countRows
--     orderBy [asc countRows']
--     return (bar ^. BarName, countRows')
--   forM_ r $ \(Value name, Value count) -> do
--     print name
--     print (count :: Int)
--   
--   
--   
Need more columns?
--   
--   The ToSomeValues class is defined for SqlExpr and tuples
--   of SqlExprs. 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 groupBy call like this:
--   
--   
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   
groupBy :: ToSomeValues a => a -> SqlQuery ()

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

-- | ORDER BY random() clause.
--   
--   Since: 1.3.10

-- | Deprecated: Since 2.6.0: rand ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.
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

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

-- | OFFSET. Usually used with limit.
offset :: Int64 -> SqlQuery ()

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

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

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

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

-- | HAVING.
--   
--   Since: 1.2.2
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

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

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

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

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

-- | NULL value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested Maybes in a Value 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

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

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

-- | COUNT(DISTINCT x).
--   
--   Since: 2.4.1
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 ||.

-- | BETWEEN.
--   
--   @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 *.

-- | Deprecated: Since 2.6.0: random_ is not uniform across all
--   databases! Please use a specific one such as random_,
--   random_, or random_
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.
--   
--   Caveat: Trying to use castNum from Double to
--   Int will not result in an integer, the original fractional
--   number will still be used! Use round_, ceiling_ or
--   floor_ instead.
--   
--   Safety: This operation is mostly safe due to the Num
--   constraint between the types and the fact that RDBMSs usually allow
--   numbers of different types to be used interchangeably. However, there
--   may still be issues with the query not being accepted by the RDBMS or
--   persistent not being able to parse it.
--   
--   Since: 2.2.9
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

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

-- | COALESCE 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.
--   
--   Since: 1.4.3
coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Execute a subquery SELECT 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 just but for ValueList. Most of the time you
--   won't need it, though, because you can use just from inside
--   subList_select or Just from inside valList.
--   
--   Since: 2.2.12
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

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

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

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

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

-- | CASE statement. For example:
--   
--   
--   select $
--   return $
--   case_
--      [ when_
--          (exists $
--          from $ \p -> do
--          where_ (p ^. PersonName ==. val "Mike"))
--        then_
--          (sub_select $
--          from $ \v -> do
--          let sub =
--                  from $ \c -> do
--                  where_ (c ^. PersonName ==. val "Mike")
--                  return (c ^. PersonFavNum)
--          where_ (v ^. PersonFavNum >. sub_select sub)
--          return $ count (v ^. PersonName) +. val (1 :: Int)) ]
--      (else_ $ val (-1))
--   
--   
--   This query is a bit complicated, but basically it checks if a person
--   named "Mike" exists, and if that person does, run the
--   subquery to find out how many people have a ranking (by Fav Num)
--   higher than "Mike".
--   
--   NOTE: There are a few things to be aware about this statement.
--   
--   
--   
- This only implements the full CASE statement, it does not
--   implement the "simple" CASE statement.
--   
- At least one when_ and then_ is mandatory otherwise
--   it will emit an error.
--   
- The else_ is also mandatory, unlike the SQL statement in
--   which if the ELSE is omitted it will return a NULL.
--   You can reproduce this via nothing.
--   
--   
--   Since: 2.1.2
case_ :: 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 Id to
--   be that of another entity. For example:
--   
--   
--   Bar
--     barNum Int
--   Foo
--     bar BarId
--     fooNum Int
--     Primary bar
--   
--   
--   In this example, Bar is said to be the BaseEnt(ity), and Foo the
--   child. To model this in Esqueleto, declare:
--   
--   
--   instance ToBaseId Foo where
--     type BaseEnt Foo = Bar
--     toBaseIdWitness barId = FooKey barId
--   
--   
--   Now you're able to write queries such as:
--   
--   
--   select $
--   from $ (bar `<a>InnerJoin</a>` foo) -> do
--   on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
--   return (bar, foo)
--   
--   
--   Note: this function may be unsafe to use in conditions not like the
--   one of the example above.
--   
--   Since: 2.4.3
toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))

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

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

-- | Execute a subquery SELECT in a SqlExpr. The query
--   passed to this function will only return a single result - it has a
--   LIMIT 1 passed in to the query to make it safe, and the
--   return type is Maybe to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing joinV . subSelect,
--   then consider using subSelectMaybe.
--   
--   If you're performing a countRows, then you can use
--   subSelectCount 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 subSelectUnsafe, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

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

-- | Performs a COUNT of the given query in a subSelect
--   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 SELECT in a SqlExpr that returns a
--   list. This is an alias for subList_select 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:
--   
--   
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   
--   
--   The following query will return the name of the user.
--   
--   
--   getUserWithName =
--       select $
--       from $ user ->
--       pure (user, subSelectForeign user UserProfile (^. ProfileName)
--   
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 SELECT in a SqlExpr. This function
--   is unsafe, because it can throw runtime exceptions in two cases:
--   
--   
--   
- If the query passed has 0 result rows, then it will return a
--   NULL value. The persistent parsing operations will
--   fail on an unexpected NULL.
--   
- 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".
--   
--   
--   This function is safe if you guarantee that exactly one row will be
--   returned, or if the result already has a Maybe type for some
--   reason.
--   
--   For variants with the safety encoded already, see subSelect and
--   subSelectMaybe. For the most common safe use of this, see
--   subSelectCount.
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)

module Database.Esqueleto.Experimental

-- | Data type that represents SQL set operations. This includes
--   UNION, UNION ALL, EXCEPT, and
--   INTERSECT. This data type is defined as a binary tree, with
--   SelectQuery on the leaves.
--   
--   Each constructor corresponding to the aforementioned set operations
--   can be used as an infix function in a from to help with
--   readability and lead to code that closely resembles the underlying
--   SQL. For example,
--   
--   
--   select $ from $
--     (SelectQuery ...)
--     `Union`
--     (SelectQuery ...)
--   
--   
--   is translated into
--   
--   
--   SELECT * FROM (
--     (SELECT * FROM ...)
--     UNION
--     (SELECT * FROM ...)
--   )
--   
--   
--   SelectQuery can be used without any of the set operations to
--   construct a subquery. This can be used in JOIN trees. For
--   example,
--   
--   
--   select $ from $
--     Table @SomeTable
--     `InnerJoin` (SelectQuery ...)
--     `on` ...
--   
--   
--   is translated into
--   
--   
--   SELECT *
--   FROM SomeTable
--   INNER JOIN (SELECT * FROM ...)
--   ON ...
--   
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 JOIN tree. In
--   practice, only the Table constructor is used directly when
--   writing queries. For example,
--   
--   
--   select $ from $ Table @People
--   
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 ON clause that describes how two tables are related. This
--   should be used as an infix operator after a JOIN. For
--   example,
--   
--   
--   select $
--   from $ Table @Person
--   `InnerJoin` Table @BlogPost
--   `on` (\(p :& bP) ->
--           p ^. PersonId ==. bP ^. BlogPostAuthorId)
--   
on :: ToFrom a => a -> (b -> SqlExpr (Value Bool)) -> (a, b -> SqlExpr (Value Bool))
infix 9 `on`

-- | FROM clause, used to bring entities into scope.
--   
--   Internally, this function uses the From datatype and the
--   ToFrom typeclass. Unlike the old from, this does not
--   take a function as a parameter, but rather a value that represents a
--   JOIN tree constructed out of instances of ToFrom. This
--   implementation eliminates certain types of runtime errors by
--   preventing the construction of invalid SQL (e.g. illegal
--   nested-from).
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:
--   
--   
--   a :& b :& c == ((a :& b) :& c)
--   
--   
--   See the examples at the beginning of this module to see how this
--   operator is used in JOIN 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
--   Database.Esqueleto if possible.
module Database.Esqueleto.Internal.Sql

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

-- | An expression on the SQL backend.
--   
--   There are many comments describing the constructors of this data type.
--   However, Haddock doesn't like GADTs, so you'll have to read them by
--   hitting "Source".
data SqlExpr a
[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

-- | Deprecated: Since 2.6.0: rand ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.
[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 persistent entities whose backend is
--   SqlPersistT.
type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)

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

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()

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

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

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

-- | Same as update, 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 PersistField for every selected value.
--   
--   Since: 2.4.2
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

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

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

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

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

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

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

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

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

-- | (Internal) This class allows unsafeSqlFunction to work with
--   different numbers of arguments; specifically it allows providing
--   arguments to a sql function via an n-tuple of SqlExpr (Value
--   _) 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.
--   toArgList ((a,b),(c,d)) is the same as toArgList
--   (a,b,c,d).
class UnsafeSqlFunctionArgument a

-- | A ORDER BY clause.
type OrderByClause = SqlExpr OrderBy

-- | (Internal) Execute an esqueleto SELECT
--   SqlQuery inside persistent's SqlPersistT monad.
rawSelectSource :: (SqlSelect a r, MonadIO m1, MonadIO m2) => Mode -> SqlQuery a -> SqlReadT m1 (Acquire (ConduitT () r m2 ()))

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

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

-- | (Internal) Pretty prints a SqlQuery into a SQL query.
--   
--   Note: if you're curious about the SQL query being generated by
--   esqueleto, instead of manually using this function (which is
--   possible but tedious), see the renderQueryToText function
--   (along with renderQuerySelect, renderQueryUpdate, etc).
toRawSql :: (SqlSelect a r, BackendCompatible SqlBackend backend) => Mode -> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])

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

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

-- | Renders an expression into Text. Only useful for creating a
--   textual representation of the clauses passed to an On 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 SqlQuery into
--   actual results.
--   
--   This looks very similar to RawSql, and it is! However, there
--   are some crucial differences and ultimately they're different classes.
class SqlSelect a r | a -> r, r -> a

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

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

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

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

-- | (Internal) Coerce a value's type from 'SqlExpr (Value a)' to 'SqlExpr
--   (Value b)'. You should not use this function unless you know
--   what you're doing!
veryUnsafeCoerceSqlExprValue :: SqlExpr (Value a) -> SqlExpr (Value b)

-- | (Internal) Coerce a value's type from 'SqlExpr (ValueList a)' to
--   'SqlExpr (Value a)'. Does not work with empty lists.
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)

-- | Renders a SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 esqueleto EDSL (embedded domain specific language). This
--   module replaces Database.Persist, so instead of importing
--   that module you should just import this one:
--   
--   
--   -- For a module using just esqueleto.
--   import Database.Esqueleto
--   
--   
--   If you need to use persistent's default support for queries
--   as well, either import it qualified:
--   
--   
--   -- For a module that mostly uses esqueleto.
--   import Database.Esqueleto
--   import qualified Database.Persist as P
--   
--   
--   or import esqueleto itself qualified:
--   
--   
--   -- For a module that uses esqueleto just on some queries.
--   import Database.Persist
--   import qualified Database.Esqueleto as E
--   
--   
--   Other than identifier name clashes, esqueleto does not
--   conflict with persistent in any way.
module Database.Esqueleto

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

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

-- | GROUP BY clause. You can enclose multiple columns in a tuple.
--   
--   
--   select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy (bar ^. BarId, bar ^. BarName)
--     return (bar ^. BarId, bar ^. BarName, countRows)
--   
--   
--   With groupBy you can sort by aggregate functions, like so (we used
--   let to restrict the more general countRows to
--   SqlSqlExpr (Value Int) to avoid ambiguity---the second use of
--   countRows has its type restricted by the :: Int
--   below):
--   
--   
--   r <- select $ from \(foo `<a>InnerJoin</a>` bar) -> do
--     on (foo ^. FooBarId ==. bar ^. BarId)
--     groupBy $ bar ^. BarName
--     let countRows' = countRows
--     orderBy [asc countRows']
--     return (bar ^. BarName, countRows')
--   forM_ r $ \(Value name, Value count) -> do
--     print name
--     print (count :: Int)
--   
--   
--   
Need more columns?
--   
--   The ToSomeValues class is defined for SqlExpr and tuples
--   of SqlExprs. 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 groupBy call like this:
--   
--   
--   groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
--   
--   
--   This is the biggest you can get with a single tuple. However, you can
--   easily nest the tuples to add more:
--   
--   
--   groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
--   
groupBy :: ToSomeValues a => a -> SqlQuery ()

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

-- | ORDER BY random() clause.
--   
--   Since: 1.3.10

-- | Deprecated: Since 2.6.0: rand ordering function is not
--   uniform across all databases! To avoid accidental partiality it will
--   be removed in the next major version.
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

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

-- | OFFSET. Usually used with limit.
offset :: Int64 -> SqlQuery ()

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

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

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

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

-- | HAVING.
--   
--   Since: 1.2.2
having :: SqlExpr (Value Bool) -> SqlQuery ()

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

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

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

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

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

-- | NULL value.
nothing :: SqlExpr (Value (Maybe typ))

-- | Join nested Maybes in a Value 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

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

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

-- | COUNT(DISTINCT x).
--   
--   Since: 2.4.1
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 ||.

-- | BETWEEN.
--   
--   @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 *.

-- | Deprecated: Since 2.6.0: random_ is not uniform across all
--   databases! Please use a specific one such as random_,
--   random_, or random_
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.
--   
--   Caveat: Trying to use castNum from Double to
--   Int will not result in an integer, the original fractional
--   number will still be used! Use round_, ceiling_ or
--   floor_ instead.
--   
--   Safety: This operation is mostly safe due to the Num
--   constraint between the types and the fact that RDBMSs usually allow
--   numbers of different types to be used interchangeably. However, there
--   may still be issues with the query not being accepted by the RDBMS or
--   persistent not being able to parse it.
--   
--   Since: 2.2.9
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)

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

-- | COALESCE 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.
--   
--   Since: 1.4.3
coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Execute a subquery SELECT 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 just but for ValueList. Most of the time you
--   won't need it, though, because you can use just from inside
--   subList_select or Just from inside valList.
--   
--   Since: 2.2.12
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))

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

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

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

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

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

-- | CASE statement. For example:
--   
--   
--   select $
--   return $
--   case_
--      [ when_
--          (exists $
--          from $ \p -> do
--          where_ (p ^. PersonName ==. val "Mike"))
--        then_
--          (sub_select $
--          from $ \v -> do
--          let sub =
--                  from $ \c -> do
--                  where_ (c ^. PersonName ==. val "Mike")
--                  return (c ^. PersonFavNum)
--          where_ (v ^. PersonFavNum >. sub_select sub)
--          return $ count (v ^. PersonName) +. val (1 :: Int)) ]
--      (else_ $ val (-1))
--   
--   
--   This query is a bit complicated, but basically it checks if a person
--   named "Mike" exists, and if that person does, run the
--   subquery to find out how many people have a ranking (by Fav Num)
--   higher than "Mike".
--   
--   NOTE: There are a few things to be aware about this statement.
--   
--   
--   
- This only implements the full CASE statement, it does not
--   implement the "simple" CASE statement.
--   
- At least one when_ and then_ is mandatory otherwise
--   it will emit an error.
--   
- The else_ is also mandatory, unlike the SQL statement in
--   which if the ELSE is omitted it will return a NULL.
--   You can reproduce this via nothing.
--   
--   
--   Since: 2.1.2
case_ :: 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 Id to
--   be that of another entity. For example:
--   
--   
--   Bar
--     barNum Int
--   Foo
--     bar BarId
--     fooNum Int
--     Primary bar
--   
--   
--   In this example, Bar is said to be the BaseEnt(ity), and Foo the
--   child. To model this in Esqueleto, declare:
--   
--   
--   instance ToBaseId Foo where
--     type BaseEnt Foo = Bar
--     toBaseIdWitness barId = FooKey barId
--   
--   
--   Now you're able to write queries such as:
--   
--   
--   select $
--   from $ (bar `<a>InnerJoin</a>` foo) -> do
--   on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
--   return (bar, foo)
--   
--   
--   Note: this function may be unsafe to use in conditions not like the
--   one of the example above.
--   
--   Since: 2.4.3
toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))

-- | Execute a subquery SELECT in a SqlExpr. The query
--   passed to this function will only return a single result - it has a
--   LIMIT 1 passed in to the query to make it safe, and the
--   return type is Maybe to indicate that the subquery might result
--   in 0 rows.
--   
--   If you find yourself writing joinV . subSelect,
--   then consider using subSelectMaybe.
--   
--   If you're performing a countRows, then you can use
--   subSelectCount 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 subSelectUnsafe, along with a comment explaining
--   why it is safe.
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))

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

-- | Performs a COUNT of the given query in a subSelect
--   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:
--   
--   
--   User
--     profile ProfileId
--   
--   Profile
--     name    Text
--   
--   
--   The following query will return the name of the user.
--   
--   
--   getUserWithName =
--       select $
--       from $ user ->
--       pure (user, subSelectForeign user UserProfile (^. ProfileName)
--   
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 SELECT in a SqlExpr that returns a
--   list. This is an alias for subList_select and is provided for
--   symmetry with the other safe subselect functions.
subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)

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

-- | Class that enables one to use toBaseId to convert an entity's
--   key on a query into another (cf. toBaseId).
class ToBaseId ent where {
    
    -- | 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 case_.
--   
--   Since: 2.1.2
when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)

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

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

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

-- | A single value (as opposed to a whole entity). You may use
--   (^.) or (?.) to get a Value
--   from an Entity.
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 subList_select,
--   valList, in_ and exists).
newtype ValueList a
ValueList :: a -> ValueList a

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | An expression on the SQL backend.
--   
--   There are many comments describing the constructors of this data type.
--   However, Haddock doesn't like GADTs, so you'll have to read them by
--   hitting "Source".
data SqlExpr a

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

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

-- | Execute an esqueleto SELECT query inside
--   persistent's SqlPersistT monad and return a
--   Source of rows.
selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()

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

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

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

-- | Same as update, 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 PersistField for every selected value.
--   
--   Since: 2.4.2
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()

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

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

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

-- | Renders a SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 SqlQuery into a Text value along with the
--   list of PersistValues that would be supplied to the database
--   for ? placeholders.
--   
--   You must ensure that the Mode you pass to this function
--   corresponds with the actual SqlQuery. If you pass a query that
--   uses incompatible features (like an INSERT statement with a
--   SELECT 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 from magic (see
--   fromStart).
class From a

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

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

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

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

-- | A more general way to convert instances of ToJSON type class to
--   strict text Text.
toJsonText :: ToJSON j => j -> Text

-- | Predefined parseJSON. The input JSON looks like {"id": 1,
--   "name": ...}.
--   
--   The typical usage is:
--   
--   
--   instance FromJSON (Entity User) where
--       parseJSON = entityIdFromJSON
--   
entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)

-- | Predefined toJSON. The resulting JSON looks like {"id":
--   1, "name": ...}.
--   
--   The typical usage is:
--   
--   
--   instance ToJSON (Entity User) where
--       toJSON = entityIdToJSON
--   
entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value

-- | Get list of values corresponding to given entity.
entityValues :: PersistEntity record => Entity record -> [PersistValue]

-- | Convenience function for getting a free PersistField instance
--   from a type with JSON instances. The JSON parser used will accept JSON
--   values other that object and arrays. So, if your instance serializes
--   the data to a JSON string, this will still work.
--   
--   Example usage in combination with toPersistValueJSON:
--   
--   
--   instance PersistField MyData where
--     fromPersistValue = fromPersistValueJSON
--     toPersistValue = toPersistValueJSON
--   
fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a

-- | Predefined parseJSON. The input JSON looks like {"key":
--   1, "value": {"name": ...}}.
--   
--   The typical usage is:
--   
--   
--   instance FromJSON (Entity User) where
--       parseJSON = keyValueEntityFromJSON
--   
keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)

-- | Predefined toJSON. The resulting JSON looks like {"key":
--   1, "value": {"name": ...}}.
--   
--   The typical usage is:
--   
--   
--   instance ToJSON (Entity User) where
--       toJSON = keyValueEntityToJSON
--   
keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value

-- | Convenience function for getting a free PersistField instance
--   from a type with JSON instances.
--   
--   Example usage in combination with fromPersistValueJSON:
--   
--   
--   instance PersistField MyData where
--     fromPersistValue = fromPersistValueJSON
--     toPersistValue = toPersistValueJSON
--   
toPersistValueJSON :: ToJSON a => a -> PersistValue

-- | Get the Keys of all records matching the given criterion.
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 ()

-- | Curry this to make a convenience function that loads an associated
--   model.
--   
--   
--   foreign = belongsTo foreignId
--   
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)

-- | Same as belongsTo, but uses getJust and therefore is
--   similarly unsafe.
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

-- | Like get, but returns the complete Entity.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   getSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
--   getSpjEntity = getEntity spjId
--   
--   
--   
--   mSpjEnt <- getSpjEntity
--   
--   
--   The above query when applied on dataset-1, will get this
--   entity:
--   
--   
--   +----+------+-----+
--   | id | name | age |
--   +----+------+-----+
--   |  1 | SPJ  |  40 |
--   +----+------+-----+
--   
getEntity :: forall backend e (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e))

-- | Same as get, but for a non-null (not Maybe) foreign key. Unsafe
--   unless your database is enforcing that the foreign key is valid.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   getJustSpj :: MonadIO m => ReaderT SqlBackend m User
--   getJustSpj = getJust spjId
--   
--   
--   
--   spj <- getJust spjId
--   
--   
--   The above query when applied on dataset-1, will get this
--   record:
--   
--   
--   +----+------+-----+
--   | id | name | age |
--   +----+------+-----+
--   |  1 | SPJ  |  40 |
--   +----+------+-----+
--   
--   
--   
--   getJustUnknown :: MonadIO m => ReaderT SqlBackend m User
--   getJustUnknown = getJust unknownId
--   
--   
--   mrx <- getJustUnknown
--   
--   This just throws an error.
getJust :: forall backend record (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record

-- | Same as getJust, but returns an Entity instead of just
--   the record.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   getJustEntitySpj :: MonadIO m => ReaderT SqlBackend m (Entity User)
--   getJustEntitySpj = getJustEntity spjId
--   
--   
--   
--   spjEnt <- getJustEntitySpj
--   
--   
--   The above query when applied on dataset-1, will get this
--   entity:
--   
--   
--   +----+------+-----+
--   | id | name | age |
--   +----+------+-----+
--   |  1 | SPJ  |  40 |
--   +----+------+-----+
--   
getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record)

-- | Like insert, but returns the complete Entity.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   insertHaskellEntity :: MonadIO m => ReaderT SqlBackend m (Entity User)
--   insertHaskellEntity = insertEntity $ User "Haskell" 81
--   
--   
--   
--   haskellEnt <- insertHaskellEntity
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +----+---------+-----+
--   | id |  name   | age |
--   +----+---------+-----+
--   |  1 | SPJ     |  40 |
--   +----+---------+-----+
--   |  2 | Simon   |  41 |
--   +----+---------+-----+
--   |  3 | Haskell |  81 |
--   +----+---------+-----+
--   
insertEntity :: forall backend e (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, MonadIO m) => e -> ReaderT backend m (Entity e)

-- | Like insertEntity but just returns the record instead of
--   Entity.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   insertDaveRecord :: MonadIO m => ReaderT SqlBackend m User
--   insertDaveRecord = insertRecord $ User "Dave" 50
--   
--   
--   
--   dave <- insertDaveRecord
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Dave  |50   |
--   +-----+------+-----+
--   
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

-- | Check whether there are any conflicts for unique keys with this entity
--   and existing entities in the database.
--   
--   Returns Nothing if the entity would be unique, and could thus
--   safely be inserted. on a conflict returns the conflicting key
--   
--   
Example usage
--   
--   We use schema-1 and dataset-1 here.
--   
--   This would be Nothing:
--   
--   
--   mAlanConst <- checkUnique $ User "Alan" 70
--   
--   
--   While this would be Just because SPJ already exists:
--   
--   
--   mSpjConst <- checkUnique $ User "SPJ" 60
--   
checkUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record))

-- | A modification of getBy, which takes the PersistEntity
--   itself instead of a Unique record. Returns a record matching
--   one of the unique keys. This function makes the most sense on
--   entities with a single Unique constructor.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   getBySpjValue :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity
--   User)) getBySpjValue = getByValue $ User SPJ 999
--   
--   
--   mSpjEnt <- getBySpjValue
--   
--   
--   The above query when applied on dataset-1, will get this
--   record:
--   
--   
--   +----+------+-----+
--   | id | name | age |
--   +----+------+-----+
--   |  1 | SPJ  |  40 |
--   +----+------+-----+
--   
getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record))

-- | Insert a value, checking for conflicts with any unique constraints. If
--   a duplicate exists in the database, it is returned as Left.
--   Otherwise, the new 'Key is returned as Right.
--   
--   
Example usage
--   
--   With schema-2 and dataset-1, we have following lines of
--   code:
--   
--   
--   l1 <- insertBy $ User "SPJ" 20
--   l2 <- insertBy $ User "XXX" 41
--   l3 <- insertBy $ User "SPJ" 40
--   r1 <- insertBy $ User "XXX" 100
--   
--   
--   First three lines return Left because there're duplicates in
--   given record's uniqueness constraints. While the last line returns a
--   new key as Right.
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))

-- | Like insertEntity, but returns Nothing when the record
--   couldn't be inserted because of a uniqueness constraint.
--   
--   
Example usage
--   
--   We use schema-2 and dataset-1 here.
--   
--   
--   insertUniqueSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
--   insertUniqueSpjEntity = insertUniqueEntity $ User "SPJ" 50
--   
--   
--   
--   mSpjEnt <- insertUniqueSpjEntity
--   
--   
--   The above query results Nothing as SPJ already exists.
--   
--   
--   insertUniqueAlexaEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
--   insertUniqueAlexaEntity = insertUniqueEntity $ User "Alexa" 3
--   
--   
--   
--   mAlexaEnt <- insertUniqueSpjEntity
--   
--   
--   Because there's no such unique keywords of the given record, the above
--   query when applied on dataset-1, will produce this:
--   
--   
--   +----+-------+-----+
--   | id | name  | age |
--   +----+-------+-----+
--   |  1 | SPJ   |  40 |
--   +----+-------+-----+
--   |  2 | Simon |  41 |
--   +----+-------+-----+
--   |  3 | Alexa |   3 |
--   +----+-------+-----+
--   
insertUniqueEntity :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend) => record -> ReaderT backend m (Maybe (Entity record))

-- | Return the single unique key for a record.
--   
--   
Example usage
--   
--   We use shcema-1 and dataset-1 here.
--   
--   
--   onlySimonConst :: MonadIO m => ReaderT SqlBackend m (Unique User)
--   onlySimonConst = onlyUnique $ User "Simon" 999
--   
--   
--   
--   mSimonConst <- onlySimonConst
--   
--   
--   mSimonConst would be Simon's uniqueness constraint. Note that
--   onlyUnique doesn't work if there're more than two
--   constraints. It will fail with a type error instead.
onlyUnique :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record)

-- | Attempt to replace the record of the given key with the given new
--   record. First query the unique fields to make sure the replacement
--   maintains uniqueness constraints.
--   
--   Return Nothing if the replacement was made. If uniqueness is
--   violated, return a Just with the Unique violation
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))

-- | Commit the current transaction and begin a new one. This is used when
--   a transaction commit is required within the context of
--   runSqlConn (which brackets its provided action with a
--   transaction begin/commit pair).
transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()

-- | Roll back the current transaction and begin a new one. This rolls back
--   to the state of the last call to transactionSave or the
--   enclosing runSqlConn call.
transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
defaultAttribute :: [Attr] -> Maybe Text

-- | Create the list of columns for the given entity.
mkColumns :: [EntityDef] -> EntityDef -> ([Column], [UniqueDef], [ForeignDef])

-- | Return all of the Sql values associated with the given
--   migration. Calls error if there's a parse error on any
--   migration.
getMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Sql]

-- | Given a list of old entity definitions and a new EntityDef in
--   val, this creates a Migration to update the old list
--   of definitions with the new one.
migrate :: [EntityDef] -> EntityDef -> Migration

-- | Given a Migration, this parses it and returns either a list of
--   errors associated with the migration or a list of migrations to do.
parseMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration)

-- | Like parseMigration, but instead of returning the value in an
--   Either value, it calls error on the error values.
parseMigration' :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m CautiousMigration

-- | Prints a migration.
printMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()

-- | Runs a migration. If the migration fails to parse or if any of the
--   migrations are unsafe, then this calls error to halt the
--   program.
runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()

-- | Same as runMigration, but returns a list of the SQL commands
--   executed instead of printing them to stderr.
--   
--   This function silences the migration by remapping stderr. As a
--   result, it is not thread-safe and can clobber output from other parts
--   of the program. This implementation method was chosen to also silence
--   postgresql migration output on stderr, but is not recommended!
runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text]

-- | Like runMigration, but this will perform the unsafe database
--   migrations instead of erroring out.
runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()

-- | Convert a Migration to a list of Text values
--   corresponding to their Sql statements.
showMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text]

-- | Generates sql for limit and offset for postgres, sqlite and mysql.
decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Bool -> Text -> Text

-- | useful for a backend to implement fieldName by adding escaping
fieldDBName :: PersistEntity record => EntityField record typ -> DBName
fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64

-- | get the SQL string for the field that an EntityField represents Useful
--   for raw SQL queries
--   
--   Your backend may provide a more convenient fieldName function which
--   does not operate in a Monad
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

-- | get the SQL string for the table that a PeristEntity represents Useful
--   for raw SQL queries
--   
--   Your backend may provide a more convenient tableName function which
--   does not operate in a Monad
getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text

-- | useful for a backend to implement tableName by adding escaping
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

-- | Execute a raw SQL statement
rawExecute :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m ()

-- | Execute a raw SQL statement and return the number of rows it has
--   modified.
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 ()))

-- | Execute a raw SQL statement and return its results as a list. If you
--   do not expect a return value, use of rawExecute is recommended.
--   
--   If you're using Entitys (which is quite likely), then
--   you must use entity selection placeholders (double question
--   mark, ??). These ?? placeholders are then replaced
--   for the names of the columns that we need for your entities. You'll
--   receive an error if you don't use the placeholders. Please see the
--   Entitys documentation for more details.
--   
--   You may put value placeholders (question marks, ?) in your
--   SQL query. These placeholders are then replaced by the values you pass
--   on the second parameter, already correctly escaped. You may want to
--   use toPersistValue to help you constructing the placeholder
--   values.
--   
--   Since you're giving a raw SQL statement, you don't get any guarantees
--   regarding safety. If rawSql is not able to parse the results of
--   your query back, then an exception is raised. However, most common
--   problems are mitigated by using the entity selection placeholder
--   ??, and you shouldn't see any error at all if you're not
--   using Single.
--   
--   Some example of rawSql based on this schema:
--   
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
--   Person
--       name String
--       age Int Maybe
--       deriving Show
--   BlogPost
--       title String
--       authorId PersonId
--       deriving Show
--   |]
--   
--   
--   Examples based on the above schema:
--   
--   
--   getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person]
--   getPerson = rawSql "select ?? from person where name=?" [PersistText "john"]
--   
--   getAge :: MonadIO m => ReaderT SqlBackend m [Single Int]
--   getAge = rawSql "select person.age from person where name=?" [PersistText "john"]
--   
--   getAgeName :: MonadIO m => ReaderT SqlBackend m [(Single Int, Single Text)]
--   getAgeName = rawSql "select person.age, person.name from person where name=?" [PersistText "john"]
--   
--   getPersonBlog :: MonadIO m => ReaderT SqlBackend m [(Entity Person, Entity BlogPost)]
--   getPersonBlog = rawSql "select ??,?? from person,blog_post where person.id = blog_post.author_id" []
--   
--   
--   Minimal working program for PostgreSQL backend based on the above
--   concepts:
--   
--   
--   {-# LANGUAGE EmptyDataDecls             #-}
--   {-# LANGUAGE FlexibleContexts           #-}
--   {-# LANGUAGE GADTs                      #-}
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   {-# LANGUAGE MultiParamTypeClasses      #-}
--   {-# LANGUAGE OverloadedStrings          #-}
--   {-# LANGUAGE QuasiQuotes                #-}
--   {-# LANGUAGE TemplateHaskell            #-}
--   {-# LANGUAGE TypeFamilies               #-}
--   
--   import           Control.Monad.IO.Class  (liftIO)
--   import           Control.Monad.Logger    (runStderrLoggingT)
--   import           Database.Persist
--   import           Control.Monad.Reader
--   import           Data.Text
--   import           Database.Persist.Sql
--   import           Database.Persist.Postgresql
--   import           Database.Persist.TH
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
--   Person
--       name String
--       age Int Maybe
--       deriving Show
--   |]
--   
--   conn = "host=localhost dbname=new_db user=postgres password=postgres port=5432"
--   
--   getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person]
--   getPerson = rawSql "select ?? from person where name=?" [PersistText "sibi"]
--   
--   liftSqlPersistMPool y x = liftIO (runSqlPersistMPool y x)
--   
--   main :: IO ()
--   main = runStderrLoggingT $ withPostgresqlPool conn 10 $ liftSqlPersistMPool $ do
--            runMigration migrateAll
--            xs <- getPerson
--            liftIO (print xs)
--   
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

-- | Get a connection from the pool, run the given action, and then return
--   the connection to the pool.
--   
--   Note: This function previously timed out after 2 seconds, but this
--   behavior was buggy and caused more problems than it solved. Since
--   version 2.1.2, it performs no timeout checks.
runSqlPool :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a

-- | Create a connection and run sql queries within it. This function
--   automatically closes the connection on it's completion.
--   
--   
Example usage
--   
--   
--   {-# LANGUAGE GADTs #-}
--   {-# LANGUAGE ScopedTypeVariables #-}
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE MultiParamTypeClasses #-}
--   {-# LANGUAGE TypeFamilies#-}
--   {-# LANGUAGE TemplateHaskell#-}
--   {-# LANGUAGE QuasiQuotes#-}
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   
--   import Control.Monad.IO.Class  (liftIO)
--   import Control.Monad.Logger
--   import Conduit
--   import Database.Persist
--   import Database.Sqlite
--   import Database.Persist.Sqlite
--   import Database.Persist.TH
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
--   Person
--     name String
--     age Int Maybe
--     deriving Show
--   |]
--   
--   openConnection :: LogFunc -> IO SqlBackend
--   openConnection logfn = do
--    conn <- open "/home/sibi/test.db"
--    wrapConnection conn logfn
--   
--   main :: IO ()
--   main = do
--     runNoLoggingT $ runResourceT $ withSqlConn openConnection (\backend ->
--                                         flip runSqlConn backend $ do
--                                           runMigration migrateAll
--                                           insert_ $ Person "John doe" $ Just 35
--                                           insert_ $ Person "Divya" $ Just 36
--                                           (pers :: [Entity Person]) <- selectList [] []
--                                           liftIO $ print pers
--                                           return ()
--                                        )
--   
--   
--   On executing it, you get this output:
--   
--   
--   Migrating: CREATE TABLE "person"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"age" INTEGER NULL)
--   [Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 1}}, entityVal = Person {personName = "John doe", personAge = Just 35}},Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 2}}, entityVal = Person {personName = "Hema", personAge = Just 36}}]
--   
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

-- | Useful for running a read query against a backend with unknown
--   capabilities.
readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a

-- | Useful for running a read query against a backend with read and write
--   capabilities.
readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a

-- | Useful for running a write query against an untagged backend with
--   unknown capabilities.
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

-- | A backwards-compatible alias for those that don't care about
--   distinguishing between read and write queries. It signifies the
--   assumption that, by default, a backend can write as well as read.
type PersistStore a = PersistStoreWrite a

-- | A backwards-compatible alias for those that don't care about
--   distinguishing between read and write queries. It signifies the
--   assumption that, by default, a backend can write as well as read.
type PersistUnique a = PersistUniqueWrite a

-- | For combinations of backends and entities that support
--   cascade-deletion. “Cascade-deletion” means that entries that depend on
--   other entries to be deleted will be deleted as well.
class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend

-- | Perform cascade-deletion of single database entry.
deleteCascade :: forall (m :: Type -> Type). (DeleteCascade record backend, MonadIO m) => Key record -> ReaderT backend m ()

-- | Represents a value containing all the configuration options for a
--   specific backend. This abstraction makes it easier to write code that
--   can easily swap backends.
class PersistConfig c where {
    type family PersistConfigBackend c :: Type -> Type -> Type -> Type;
    type family PersistConfigPool c;
}

-- | Load the config settings from a Value, most likely taken from a
--   YAML config file.
loadConfig :: PersistConfig c => Value -> Parser c

-- | Modify the config settings based on environment variables.
applyEnv :: PersistConfig c => c -> IO c

-- | Create a new connection pool based on the given config settings.
createPoolConfig :: PersistConfig c => c -> IO (PersistConfigPool c)

-- | Run a database action by taking a connection from the pool.
runPool :: (PersistConfig c, MonadUnliftIO m) => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a
type family BackendSpecificUpdate backend record

-- | Datatype that represents an entity, with both its Key and its
--   Haskell record representation.
--   
--   When using a SQL-based backend (such as SQLite or PostgreSQL), an
--   Entity may take any number of columns depending on how many
--   fields it has. In order to reconstruct your entity on the Haskell
--   side, persistent needs all of your entity columns and in the
--   right order. Note that you don't need to worry about this when using
--   persistent's API since everything is handled correctly behind
--   the scenes.
--   
--   However, if you want to issue a raw SQL command that returns an
--   Entity, then you have to be careful with the column order.
--   While you could use SELECT Entity.* WHERE ... and that would
--   work most of the time, there are times when the order of the columns
--   on your database is different from the order that persistent
--   expects (for example, if you add a new field in the middle of you
--   entity definition and then use the migration code --
--   persistent will expect the column to be in the middle, but
--   your DBMS will put it as the last column). So, instead of using a
--   query like the one above, you may use rawSql (from the
--   Database.Persist.GenericSql module) with its /entity selection
--   placeholder/ (a double question mark ??). Using
--   rawSql the query above must be written as SELECT ?? WHERE
--   ... Then rawSql will replace ?? with the list
--   of all columns that we need from your entity in the right order. If
--   your query returns two entities (i.e. (Entity backend a, Entity
--   backend b)), then you must you use SELECT ??, ?? WHERE
--   ..., and so on.
data Entity record
Entity :: Key record -> record -> Entity record
[entityKey] :: Entity record -> Key record
[entityVal] :: Entity record -> record

-- | Persistent serialized Haskell records to the database. A Database
--   Entity (A row in SQL, a document in MongoDB, etc) corresponds
--   to a Key plus a Haskell record.
--   
--   For every Haskell record type stored in the database there is a
--   corresponding PersistEntity instance. An instance of
--   PersistEntity contains meta-data for the record. PersistEntity also
--   helps abstract over different record types. That way the same query
--   interface can return a PersistEntity, with each query returning
--   different types of Haskell records.
--   
--   Some advanced type system capabilities are used to make this process
--   type-safe. Persistent users usually don't need to understand the class
--   associated data and functions.
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 {
    
    -- | Persistent allows multiple different backends (databases).
    type family PersistEntityBackend record;
    
    -- | By default, a backend will automatically generate the key Instead you
    --   can specify a Primary key made up of unique values.
    data family Key record;
    
    -- | An <a>EntityField</a> is parameterised by the Haskell record it
    --   belongs to and the additional type of that field.
    data family EntityField record :: Type -> Type;
    
    -- | Unique keys besides the <a>Key</a>.
    data family Unique record;
}

-- | A lower-level key operation.
keyToValues :: PersistEntity record => Key record -> [PersistValue]

-- | A lower-level key operation.
keyFromValues :: PersistEntity record => [PersistValue] -> Either Text (Key record)

-- | A meta-operation to retrieve the Key EntityField.
persistIdField :: PersistEntity record => EntityField record (Key record)

-- | Retrieve the EntityDef meta-data for the record.
entityDef :: (PersistEntity record, Monad m) => m record -> EntityDef

-- | Return meta-data for a given EntityField.
persistFieldDef :: PersistEntity record => EntityField record typ -> FieldDef

-- | A meta-operation to get the database fields of a record.
toPersistFields :: PersistEntity record => record -> [SomePersistField]

-- | A lower-level operation to convert from database values to a Haskell
--   record.
fromPersistValues :: PersistEntity record => [PersistValue] -> Either Text record

-- | A meta operation to retrieve all the Unique keys.
persistUniqueKeys :: PersistEntity record => record -> [Unique record]

-- | A lower level operation.
persistUniqueToFieldNames :: PersistEntity record => Unique record -> [(HaskellName, DBName)]

-- | A lower level operation.
persistUniqueToValues :: PersistEntity record => Unique record -> [PersistValue]

-- | Use a PersistField as a lens.
fieldLens :: PersistEntity record => EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record)

-- | This class teaches Persistent how to take a custom type and marshal it
--   to and from a PersistValue, allowing it to be stored in a
--   database.
--   
--   
Examples
--   
--   
Simple Newtype
--   
--   You can use newtype to add more type safety/readability to a
--   basis type like ByteString. In these cases, just derive
--   PersistField and PersistFieldSql:
--   
--   
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   
--   newtype HashedPassword = HashedPassword ByteString
--     deriving (Eq, Show, PersistField, PersistFieldSql)
--   
--   
--   
Smart Constructor Newtype
--   
--   In this example, we create a PersistField instance for a
--   newtype following the "Smart Constructor" pattern.
--   
--   
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   import qualified Data.Text as T
--   import qualified Data.Char as C
--   
--   -- | An American Social Security Number
--   newtype SSN = SSN Text
--    deriving (Eq, Show, PersistFieldSql)
--   
--   mkSSN :: Text -> Either Text SSN
--   mkSSN t = if (T.length t == 9) && (T.all C.isDigit t)
--    then Right $ SSN t
--    else Left $ "Invalid SSN: " <> t
--   
--   instance PersistField SSN where
--     toPersistValue (SSN t) = PersistText t
--     fromPersistValue (PersistText t) = mkSSN t
--     -- Handle cases where the database does not give us PersistText
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize an SSN: expected PersistText, received: " <> T.pack (show x)
--   
--   
--   Tips:
--   
--   
--   
- This file contain dozens of PersistField instances you can
--   look at for examples.
--   
- Typically custom PersistField instances will only accept a
--   single PersistValue constructor in
--   fromPersistValue.
--   
- Internal PersistField instances accept a wide variety of
--   PersistValues to accomodate e.g. storing booleans as integers,
--   booleans or strings.
--   
- If you're making a custom instance and using a SQL database,
--   you'll also need PersistFieldSql to specify the type of the
--   database column.
--   
class PersistField a
toPersistValue :: PersistField a => a -> PersistValue
fromPersistValue :: PersistField a => PersistValue -> Either Text a
data SomePersistField
SomePersistField :: a -> SomePersistField

-- | Backends supporting conditional read operations.
class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend

-- | Get all records matching the given criterion in the specified order.
--   Returns also the identifiers.
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 ()))

-- | Get just the first record for the criterion.
selectFirst :: forall (m :: Type -> Type) record. (PersistQueryRead backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))

-- | Get the Keys of all records matching the given criterion.
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 ()))

-- | Backends supporting conditional write operations
class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend

-- | Update individual fields on any record matching the given criterion.
updateWhere :: forall (m :: Type -> Type) record. (PersistQueryWrite backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m ()

-- | Delete all records matching the given criterion.
deleteWhere :: forall (m :: Type -> Type) record. (PersistQueryWrite backend, MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m ()

-- | This class witnesses that two backend are compatible, and that you can
--   convert from the sub backend into the sup backend.
--   This is similar to the HasPersistBackend and
--   IsPersistBackend classes, but where you don't want to fix the
--   type associated with the PersistEntityBackend of a record.
--   
--   Generally speaking, where you might have:
--   
--   
--   foo ::
--     ( PersistEntity record
--     , PeristEntityBackend record ~ BaseBackend backend
--     , IsSqlBackend backend
--     )
--   
--   
--   this can be replaced with:
--   
--   
--   foo ::
--     ( PersistEntity record,
--     , PersistEntityBackend record ~ backend
--     , BackendCompatible SqlBackend backend
--     )
--   
--   
--   This works for SqlReadBackend because of the instance
--   BackendCompatible SqlBackend
--   SqlReadBackend, without needing to go through the
--   BaseBackend type family.
--   
--   Likewise, functions that are currently hardcoded to use
--   SqlBackend can be generalized:
--   
--   
--   -- before:
--   asdf :: ReaderT SqlBackend m ()
--   asdf = pure ()
--   
--   -- after:
--   asdf' :: BackendCompatible SqlBackend backend => ReaderT backend m ()
--   asdf' = withReaderT projectBackend asdf
--   
class BackendCompatible sup sub
projectBackend :: BackendCompatible sup sub => sub -> sup
data family BackendKey backend

-- | Class which allows the plucking of a BaseBackend backend from
--   some larger type. For example,  instance HasPersistBackend
--   (SqlReadBackend, Int) where type BaseBackend (SqlReadBackend, Int) =
--   SqlBackend persistBackend = unSqlReadBackend . fst 
class HasPersistBackend backend where {
    type family BaseBackend backend;
}
persistBackend :: HasPersistBackend backend => backend -> BaseBackend backend

-- | Class which witnesses that backend is essentially the same as
--   BaseBackend backend. That is, they're isomorphic and
--   backend is just some wrapper over BaseBackend
--   backend.
class HasPersistBackend backend => IsPersistBackend backend
class PersistCore backend where {
    data family BackendKey backend;
}

-- | A convenient alias for common type signatures
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 a record by identifier, if available.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   getSpj :: MonadIO m => ReaderT SqlBackend m (Maybe User)
--   getSpj = get spjId
--   
--   
--   
--   mspj <- getSpj
--   
--   
--   The above query when applied on dataset-1, will get this:
--   
--   
--   +------+-----+
--   | name | age |
--   +------+-----+
--   | SPJ  |  40 |
--   +------+-----+
--   
get :: forall (m :: Type -> Type) record. (PersistStoreRead backend, MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record)

-- | Get many records by their respective identifiers, if available.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1:
--   
--   
--   getUsers :: MonadIO m => ReaderT SqlBackend m (Map (Key User) User)
--   getUsers = getMany allkeys
--   
--   
--   
--   musers <- getUsers
--   
--   
--   The above query when applied on dataset-1, will get these
--   records:
--   
--   
--   +----+-------+-----+
--   | id | name  | age |
--   +----+-------+-----+
--   |  1 | SPJ   |  40 |
--   +----+-------+-----+
--   |  2 | Simon |  41 |
--   +----+-------+-----+
--   
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

-- | Create a new record in the database, returning an automatically
--   created key (in SQL an auto-increment id).
--   
--   
Example usage
--   
--   Using schema-1 and dataset-1, let's insert a new user
--   John.
--   
--   
--   insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User)
--   insertJohn = insert $ User "John" 30
--   
--   
--   
--   johnId <- insertJohn
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |John  |30   |
--   +-----+------+-----+
--   
insert :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Key record)

-- | Same as insert, but doesn't return a Key.
--   
--   
Example usage
--   
--   with schema-1 and dataset-1,
--   
--   
--   insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User)
--   insertJohn = insert_ $ User "John" 30
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |John  |30   |
--   +-----+------+-----+
--   
insert_ :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m ()

-- | Create multiple records in the database and return their Keys.
--   
--   If you don't need the inserted Keys, use insertMany_.
--   
--   The MongoDB and PostgreSQL backends insert all records and retrieve
--   their keys in one database query.
--   
--   The SQLite and MySQL backends use the slow, default implementation of
--   mapM insert.
--   
--   
Example usage
--   
--   with schema-1 and dataset-1,
--   
--   
--   insertUsers :: MonadIO m => ReaderT SqlBackend m [Key User]
--   insertUsers = insertMany [User "John" 30, User "Nick" 32, User "Jane" 20]
--   
--   
--   
--   userIds <- insertUsers
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |John  |30   |
--   +-----+------+-----+
--   |4    |Nick  |32   |
--   +-----+------+-----+
--   |5    |Jane  |20   |
--   +-----+------+-----+
--   
insertMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m [Key record]

-- | Same as insertMany, but doesn't return any Keys.
--   
--   The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records
--   in one database query.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   insertUsers_ :: MonadIO m => ReaderT SqlBackend m ()
--   insertUsers_ = insertMany_ [User "John" 30, User "Nick" 32, User "Jane" 20]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |John  |30   |
--   +-----+------+-----+
--   |4    |Nick  |32   |
--   +-----+------+-----+
--   |5    |Jane  |20   |
--   +-----+------+-----+
--   
insertMany_ :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()

-- | Same as insertMany_, but takes an Entity instead of just
--   a record.
--   
--   Useful when migrating data from one entity to another and want to
--   preserve ids.
--   
--   The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records
--   in one database query.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   insertUserEntityMany :: MonadIO m => ReaderT SqlBackend m ()
--   insertUserEntityMany = insertEntityMany [SnakeEntity, EvaEntity]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Snake |38   |
--   +-----+------+-----+
--   |4    |Eva   |38   |
--   +-----+------+-----+
--   
insertEntityMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m ()

-- | Create a new record in the database using the given key.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   insertAliceKey :: MonadIO m => Key User -> ReaderT SqlBackend m ()
--   insertAliceKey key = insertKey key $ User "Alice" 20
--   
--   
--   
--   insertAliceKey $ UserKey {unUserKey = SqlBackendKey {unSqlBackendKey = 3}}
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Alice |20   |
--   +-----+------+-----+
--   
insertKey :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()

-- | Put the record in the database with the given key. Unlike
--   replace, if a record with the given key does not exist then a
--   new record will be inserted.
--   
--   
Example usage
--   
--   We try to explain upsertBy using schema-1 and
--   dataset-1.
--   
--   First, we insert Philip to dataset-1.
--   
--   
--   insertPhilip :: MonadIO m => ReaderT SqlBackend m (Key User)
--   insertPhilip = insert $ User "Philip" 42
--   
--   
--   
--   philipId <- insertPhilip
--   
--   
--   This query will produce:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Philip|42   |
--   +-----+------+-----+
--   
--   
--   
--   repsertHaskell :: MonadIO m => Key record -> ReaderT SqlBackend m ()
--   repsertHaskell id = repsert id $ User "Haskell" 81
--   
--   
--   
--   repsertHaskell philipId
--   
--   
--   This query will replace Philip's record with Haskell's one:
--   
--   
--   +-----+-----------------+--------+
--   |id   |name             |age     |
--   +-----+-----------------+--------+
--   |1    |SPJ              |40      |
--   +-----+-----------------+--------+
--   |2    |Simon            |41      |
--   +-----+-----------------+--------+
--   |3    |Philip -> Haskell|42 -> 81|
--   +-----+-----------------+--------+
--   
--   
--   repsert inserts the given record if the key doesn't exist.
--   
--   
--   repsertXToUnknown :: MonadIO m => ReaderT SqlBackend m ()
--   repsertXToUnknown = repsert unknownId $ User "X" 999
--   
--   
--   For example, applying the above query to dataset-1 will produce
--   this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |X     |999  |
--   +-----+------+-----+
--   
repsert :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()

-- | Put many entities into the database.
--   
--   Batch version of repsert for SQL backends.
--   
--   Useful when migrating data from one entity to another and want to
--   preserve ids.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   repsertManyUsers :: MonadIO m =>ReaderT SqlBackend m ()
--   repsertManyusers = repsertMany [(simonId, User "Philip" 20), (unknownId999, User "Mr. X" 999)]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+----------------+---------+
--   |id   |name            |age      |
--   +-----+----------------+---------+
--   |1    |SPJ             |40       |
--   +-----+----------------+---------+
--   |2    |Simon -> Philip |41 -> 20 |
--   +-----+----------------+---------+
--   |999  |Mr. X           |999      |
--   +-----+----------------+---------+
--   
repsertMany :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m ()

-- | Replace the record in the database with the given key. Note that the
--   result is undefined if such record does not exist, so you must use
--   insertKey or repsert in these cases.
--   
--   
Example usage
--   
--   With schema-1 schama-1 and dataset-1,
--   
--   
--   replaceSpj :: MonadIO m => User -> ReaderT SqlBackend m ()
--   replaceSpj record = replace spjId record
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |Mike  |45   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   
replace :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()

-- | Update individual fields on a specific record, and retrieve the
--   updated value from the database.
--   
--   Note that this function will throw an exception if the given key is
--   not found in the database.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   updateGetSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m User
--   updateGetSpj updates = updateGet spjId updates
--   
--   
--   
--   spj <- updateGetSpj [UserAge +=. 100]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |140  |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   
updateGet :: forall (m :: Type -> Type) record. (PersistStoreWrite backend, MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record

-- | ToBackendKey converts a PersistEntity Key into a
--   BackendKey This can be used by each backend to convert between
--   a Key and a plain Haskell type. For Sql, that is done with
--   toSqlKey and fromSqlKey.
--   
--   By default, a PersistEntity uses the default BackendKey
--   for its Key and is an instance of ToBackendKey
--   
--   A Key that instead uses a custom type will not be an instance
--   of ToBackendKey.
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

-- | Queries against Unique keys (other than the id Key).
--   
--   Please read the general Persistent documentation to learn how to
--   create Unique keys.
--   
--   Using this with an Entity without a Unique key leads to undefined
--   behavior. A few of these functions require a single
--   Unique, so using an Entity with multiple Uniques is also
--   undefined. In these cases persistent's goal is to throw an exception
--   as soon as possible, but persistent is still transitioning to that.
--   
--   SQL backends automatically create uniqueness constraints, but for
--   MongoDB you must manually place a unique index on a field to have a
--   uniqueness constraint.
class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend

-- | Get a record by unique key, if available. Returns also the identifier.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1:
--   
--   
--   getBySpjName :: MonadIO m  => ReaderT SqlBackend m (Maybe (Entity User))
--   getBySpjName = getBy $ UniqueUserName "SPJ"
--   
--   
--   
--   mSpjEnt <- getBySpjName
--   
--   
--   The above query when applied on dataset-1, will get this
--   entity:
--   
--   
--   +----+------+-----+
--   | id | name | age |
--   +----+------+-----+
--   |  1 | SPJ  |  40 |
--   +----+------+-----+
--   
getBy :: forall (m :: Type -> Type) record. (PersistUniqueRead backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record))

-- | Some functions in this module (insertUnique, insertBy,
--   and replaceUnique) first query the unique indexes to check for
--   conflicts. You could instead optimistically attempt to perform the
--   operation (e.g. replace instead of replaceUnique).
--   However,
--   
--   
--   
- there is some fragility to trying to catch the correct exception
--   and determing the column of failure;
--   
- an exception will automatically abort the current SQL
--   transaction.
--   
class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend

-- | Delete a specific record by unique key. Does nothing if no record
--   matches.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1,
--   
--   
--   deleteBySpjName :: MonadIO m => ReaderT SqlBackend m ()
--   deleteBySpjName = deleteBy UniqueUserName "SPJ"
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   
deleteBy :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m ()

-- | Like insert, but returns Nothing when the record
--   couldn't be inserted because of a uniqueness constraint.
--   
--   
Example usage
--   
--   With schema-1 and dataset-1, we try to insert the
--   following two records:
--   
--   
--   linusId <- insertUnique $ User "Linus" 48
--   spjId   <- insertUnique $ User "SPJ" 90
--   
--   
--   
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Linus |48   |
--   +-----+------+-----+
--   
--   
--   Linus's record was inserted to dataset-1, while SPJ wasn't
--   because SPJ already exists in dataset-1.
insertUnique :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Maybe (Key record))

-- | Update based on a uniqueness constraint or insert:
--   
--   
--   
- insert the new record if it does not exist;
--   
- If the record exists (matched via it's uniqueness constraint),
--   then update the existing record with the parameters which is passed on
--   as list to the function.
--   
--   
--   
Example usage
--   
--   First, we try to explain upsert using schema-1 and
--   dataset-1.
--   
--   
--   upsertSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User))
--   upsertSpj updates = upsert (User "SPJ" 999) upadtes
--   
--   
--   
--   mSpjEnt <- upsertSpj [UserAge +=. 15]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+-----+--------+
--   |id   |name |age     |
--   +-----+-----+--------+
--   |1    |SPJ  |40 -> 55|
--   +-----+-----+--------+
--   |2    |Simon|41      |
--   +-----+-----+--------+
--   
--   
--   
--   upsertX :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User))
--   upsertX updates = upsert (User "X" 999) updates
--   
--   
--   
--   mXEnt <- upsertX [UserAge +=. 15]
--   
--   
--   The above query when applied on dataset-1, will produce this:
--   
--   
--   +-----+-----+--------+
--   |id   |name |age     |
--   +-----+-----+--------+
--   |1    |SPJ  |40      |
--   +-----+-----+--------+
--   |2    |Simon|41      |
--   +-----+-----+--------+
--   |3    |X    |999     |
--   +-----+-----+--------+
--   
--   
--   Next, what if the schema has two uniqueness constraints? Let's check
--   it out using schema-2:
--   
--   
--   mSpjEnt <- upsertSpj [UserAge +=. 15]
--   
--   
--   This fails with a compile-time type error alerting us to the fact that
--   this record has multiple unique keys, and suggests that we look for
--   upsertBy to select the unique key we want.
upsert :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> [Update record] -> ReaderT backend m (Entity record)

-- | Update based on a given uniqueness constraint or insert:
--   
--   
--   
- insert the new record if it does not exist;
--   
- update the existing record that matches the given uniqueness
--   constraint.
--   
--   
--   
Example usage
--   
--   We try to explain upsertBy using schema-2 and
--   dataset-1.
--   
--   
--   upsertBySpjName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
--   upsertBySpjName record updates = upsertBy (UniqueUserName "SPJ") record updates
--   
--   
--   
--   mSpjEnt <- upsertBySpjName (Person "X" 999) [PersonAge += .15]
--   
--   
--   The above query will alter dataset-1 to:
--   
--   
--   +-----+-----+--------+
--   |id   |name |age     |
--   +-----+-----+--------+
--   |1    |SPJ  |40 -> 55|
--   +-----+-----+--------+
--   |2    |Simon|41      |
--   +-----+-----+--------+
--   
--   
--   
--   upsertBySimonAge :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
--   upsertBySimonAge record updates = upsertBy (UniqueUserName "SPJ") record updates
--   
--   
--   
--   mPhilipEnt <- upsertBySimonAge (User "X" 999) [UserName =. "Philip"]
--   
--   
--   The above query will alter dataset-1 to:
--   
--   
--   +----+-----------------+-----+
--   | id |      name       | age |
--   +----+-----------------+-----+
--   |  1 | SPJ             |  40 |
--   +----+-----------------+-----+
--   |  2 | Simon -> Philip |  41 |
--   +----+-----------------+-----+
--   
--   
--   
--   upsertByUnknownName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
--   upsertByUnknownName record updates = upsertBy (UniqueUserName "Unknown") record updates
--   
--   
--   
--   mXEnt <- upsertByUnknownName (User "X" 999) [UserAge +=. 15]
--   
--   
--   This query will alter dataset-1 to:
--   
--   
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   |3    |X    |999  |
--   +-----+-----+-----+
--   
upsertBy :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> ReaderT backend m (Entity record)

-- | Put many records into db
--   
--   
--   
- insert new records that do not exist (or violate any unique
--   constraints)
--   
- replace existing records (matching any unique constraint)
--   
putMany :: forall (m :: Type -> Type) record. (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()

-- | Tells Persistent what database column type should be used to store a
--   Haskell type.
--   
--   
Examples
--   
--   
Simple Boolean Alternative
--   
--   
--   data Switch = On | Off
--     deriving (Show, Eq)
--   
--   instance PersistField Switch where
--     toPersistValue s = case s of
--       On -> PersistBool True
--       Off -> PersistBool False
--     fromPersistValue (PersistBool b) = if b then Right On else Right Off
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize a Switch: expected PersistBool, received: " <> T.pack (show x)
--   
--   instance PersistFieldSql Switch where
--     sqlType _ = SqlBool
--   
--   
--   
Non-Standard Database Types
--   
--   If your database supports non-standard types, such as Postgres'
--   uuid, you can use SqlOther to use them:
--   
--   
--   import qualified Data.UUID as UUID
--   instance PersistField UUID where
--     toPersistValue = PersistDbSpecific . toASCIIBytes
--     fromPersistValue (PersistDbSpecific uuid) =
--       case fromASCIIBytes uuid of
--         Nothing -> Left $ "Model/CustomTypes.hs: Failed to deserialize a UUID; received: " <> T.pack (show uuid)
--         Just uuid' -> Right uuid'
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize a UUID: expected PersistDbSpecific, received: "-- >  <> T.pack (show x)
--   
--   instance PersistFieldSql UUID where
--     sqlType _ = SqlOther "uuid"
--   
--   
--   
User Created Database Types
--   
--   Similarly, some databases support creating custom types, e.g.
--   Postgres' DOMAIN and ENUM features. You can use
--   SqlOther to specify a custom type:
--   
--   
--   CREATE DOMAIN ssn AS text
--         CHECK ( value ~ '^[0-9]{9}$');
--   
--   
--   
--   instance PersistFieldSQL SSN where
--     sqlType _ = SqlOther "ssn"
--   
--   
--   
--   CREATE TYPE rainbow_color AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet');
--   
--   
--   
--   instance PersistFieldSQL RainbowColor where
--     sqlType _ = SqlOther "rainbow_color"
--   
class PersistField a => PersistFieldSql a
sqlType :: PersistFieldSql a => Proxy a -> SqlType

-- | Class for data types that may be retrived from a rawSql
--   query.
class RawSql a

-- | Number of columns that this data type needs and the list of
--   substitutions for SELECT placeholders ??.
rawSqlCols :: RawSql a => (DBName -> Text) -> a -> (Int, [Text])

-- | A string telling the user why the column count is what it is.
rawSqlColCountReason :: RawSql a => a -> String

-- | Transform a row of the result into the data type.
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

-- | A Migration is a four level monad stack consisting of:
--   
--   
--   
- WriterT [Text] representing a log of errors
--   in the migrations.
--   
- WriterT CautiousMigration representing a
--   list of migrations to run, along with whether or not they are
--   safe.
--   
- ReaderT SqlBackend, aka the
--   SqlPersistT transformer for database interop.
--   
- IO for arbitrary IO.
--   
type Migration = WriterT [Text] WriterT CautiousMigration ReaderT SqlBackend IO ()
data PersistentSqlException
StatementAlreadyFinalized :: Text -> PersistentSqlException
Couldn'tGetSQLConnection :: PersistentSqlException

-- | A single column (see rawSql). Any PersistField may
--   be used here, including PersistValue (which does not do any
--   processing).
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

-- | A backend which is a wrapper around SqlBackend.
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

-- | table name, column names, id name, either 1 or 2 statements to run
[connInsertSql] :: SqlBackend -> EntityDef -> [PersistValue] -> InsertSqlResult

-- | SQL for inserting many rows and returning their primary keys, for
--   backends that support this functioanlity. If Nothing, rows will
--   be inserted one-at-a-time using connInsertSql.
[connInsertManySql] :: SqlBackend -> Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)

-- | Some databases support performing UPSERT _and_ RETURN entity in a
--   single call.
--   
--   This field when set will be used to generate the UPSERT+RETURN sql
--   given * an entity definition * updates to be run on unique key(s)
--   collision
--   
--   When left as Nothing, we find the unique key from entity def
--   before * trying to fetch an entity by said key * perform an update
--   when result found, else issue an insert * return new entity from db
[connUpsertSql] :: SqlBackend -> Maybe (EntityDef -> NonEmpty UniqueDef -> Text -> Text)

-- | Some databases support performing bulk UPSERT, specifically "insert or
--   replace many records" in a single call.
--   
--   This field when set, given * an entity definition * number of records
--   to be inserted should produce a PUT MANY sql with placeholders for
--   records
--   
--   When left as Nothing, we default to using
--   defaultPutMany.
[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

-- | Some databases (probably only Sqlite) have a limit on how many
--   question-mark parameters may be used in a statement
[connMaxParams] :: SqlBackend -> Maybe Int

-- | Some databases support performing bulk an atomic+bulk INSERT where
--   constraint conflicting entities can replace existing entities.
--   
--   This field when set, given * an entity definition * number of records
--   to be inserted should produce a INSERT sql with placeholders for
--   primary+record fields
--   
--   When left as Nothing, we default to using
--   defaultRepsertMany.
[connRepsertManySql] :: SqlBackend -> Maybe (EntityDef -> Int -> Text)

-- | A constraint synonym which witnesses that a backend is SQL and can run
--   read queries.
type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend)

-- | A constraint synonym which witnesses that a backend is SQL and can run
--   read and write queries.
type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend)

-- | An SQL backend which can only handle read queries
--   
--   The constructor was exposed in 2.10.0.
newtype SqlReadBackend
SqlReadBackend :: SqlBackend -> SqlReadBackend
[unSqlReadBackend] :: SqlReadBackend -> SqlBackend

-- | Like SqlPersistT but compatible with any SQL backend which
--   can handle read queries.
type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a

-- | An SQL backend which can handle read or write queries
--   
--   The constructor was exposed in 2.10.0
newtype SqlWriteBackend
SqlWriteBackend :: SqlBackend -> SqlWriteBackend
[unSqlWriteBackend] :: SqlWriteBackend -> SqlBackend

-- | Like SqlPersistT but compatible with any SQL backend which
--   can handle read and write queries.
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

-- | A Checkmark should be used as a field type whenever a
--   uniqueness constraint should guarantee that a certain kind of record
--   may appear at most once, but other kinds of records may appear any
--   number of times.
--   
--   NOTE: You need to mark any Checkmark fields as
--   nullable (see the following example).
--   
--   For example, suppose there's a Location entity that
--   represents where a user has lived:
--   
--   
--   Location
--       user    UserId
--       name    Text
--       current Checkmark nullable
--   
--       UniqueLocation user current
--   
--   
--   The UniqueLocation constraint allows any number of
--   Inactive Locations to be current. However,
--   there may be at most one current Location per user
--   (i.e., either zero or one per user).
--   
--   This data type works because of the way that SQL treats
--   NULLable fields within uniqueness constraints. The SQL
--   standard says that NULL values should be considered
--   different, so we represent Inactive as SQL NULL, thus
--   allowing any number of Inactive records. On the other hand, we
--   represent Active as TRUE, so the uniqueness constraint
--   will disallow more than one Active record.
--   
--   Note: There may be DBMSs that do not respect the SQL standard's
--   treatment of NULL values on uniqueness constraints, please
--   check if this data type works before relying on it.
--   
--   The SQL BOOLEAN type is used because it's the smallest data
--   type available. Note that we never use FALSE, just
--   TRUE and NULL. Provides the same behavior Maybe
--   () would if () was a valid PersistField.
data Checkmark

-- | When used on a uniqueness constraint, there may be at most one
--   Active record.
Active :: Checkmark

-- | When used on a uniqueness constraint, there may be any number of
--   Inactive records.
Inactive :: Checkmark
data CompositeDef
CompositeDef :: ![FieldDef] -> ![Attr] -> CompositeDef
[compositeFields] :: CompositeDef -> ![FieldDef]
[compositeAttrs] :: CompositeDef -> ![Attr]
newtype DBName
DBName :: Text -> DBName
[unDBName] :: DBName -> Text

-- | An EmbedEntityDef is the same as an EntityDef But it is only used for
--   fieldReference so it only has data needed for embedding
data EmbedEntityDef
EmbedEntityDef :: !HaskellName -> ![EmbedFieldDef] -> EmbedEntityDef
[embeddedHaskell] :: EmbedEntityDef -> !HaskellName
[embeddedFields] :: EmbedEntityDef -> ![EmbedFieldDef]

-- | An EmbedFieldDef is the same as a FieldDef But it is only used for
--   embeddedFields so it only has data needed for embedding
data EmbedFieldDef
EmbedFieldDef :: !DBName -> Maybe EmbedEntityDef -> Maybe HaskellName -> EmbedFieldDef
[emFieldDB] :: EmbedFieldDef -> !DBName
[emFieldEmbed] :: EmbedFieldDef -> Maybe EmbedEntityDef

-- | emFieldEmbed can create a cycle (issue #311) when a cycle is
--   detected, emFieldEmbed will be Nothing and emFieldCycle
--   will be Just
[emFieldCycle] :: EmbedFieldDef -> Maybe HaskellName

-- | An EntityDef represents the information that
--   persistent knows about an Entity. It uses this information to
--   generate the Haskell datatype, the SQL migrations, and other relevant
--   conversions.
data EntityDef
EntityDef :: !HaskellName -> !DBName -> !FieldDef -> ![Attr] -> ![FieldDef] -> ![UniqueDef] -> ![ForeignDef] -> ![Text] -> !Map Text [ExtraLine] -> !Bool -> !Maybe Text -> EntityDef

-- | The name of the entity as Haskell understands it.
[entityHaskell] :: EntityDef -> !HaskellName

-- | The name of the database table corresponding to the entity.
[entityDB] :: EntityDef -> !DBName

-- | The entity's primary key or identifier.
[entityId] :: EntityDef -> !FieldDef

-- | The persistent entity syntax allows you to add arbitrary
--   Attrs to an entity using the ! operator. Those
--   attributes are stored in this list.
[entityAttrs] :: EntityDef -> ![Attr]

-- | The fields for this entity. Note that the ID field will not be present
--   in this list. To get all of the fields for an entity, use
--   keyAndEntityFields.
[entityFields] :: EntityDef -> ![FieldDef]

-- | The Uniqueness constraints for this entity.
[entityUniques] :: EntityDef -> ![UniqueDef]

-- | The foreign key relationships that this entity has to other entities.
[entityForeigns] :: EntityDef -> ![ForeignDef]

-- | A list of type classes that have been derived for this entity.
[entityDerives] :: EntityDef -> ![Text]
[entityExtra] :: EntityDef -> !Map Text [ExtraLine]

-- | Whether or not this entity represents a sum type in the database.
[entitySum] :: EntityDef -> !Bool

-- | Optional comments on the entity.
[entityComments] :: EntityDef -> !Maybe Text
type ExtraLine = [Text]

-- | A FieldDef represents the inormation that persistent
--   knows about a field of a datatype. This includes information used to
--   parse the field out of the database and what the field corresponds to.
data FieldDef
FieldDef :: !HaskellName -> !DBName -> !FieldType -> !SqlType -> ![Attr] -> !Bool -> !ReferenceDef -> !Maybe Text -> FieldDef

-- | The name of the field. Note that this does not corresponds to the
--   record labels generated for the particular entity - record labels are
--   generated with the type name prefixed to the field, so a
--   FieldDef that contains a HaskellName "name" for
--   a type User will have a record field userName.
[fieldHaskell] :: FieldDef -> !HaskellName

-- | The name of the field in the database. For SQL databases, this
--   corresponds to the column name.
[fieldDB] :: FieldDef -> !DBName

-- | The type of the field in Haskell.
[fieldType] :: FieldDef -> !FieldType

-- | The type of the field in a SQL database.
[fieldSqlType] :: FieldDef -> !SqlType

-- | User annotations for a field. These are provided with the !
--   operator.
[fieldAttrs] :: FieldDef -> ![Attr]

-- | If this is True, then the Haskell datatype will have a strict
--   record field. The default value for this is True.
[fieldStrict] :: FieldDef -> !Bool
[fieldReference] :: FieldDef -> !ReferenceDef

-- | Optional comments for a Field. There is not currently a way
--   to attach comments to a field in the quasiquoter.
[fieldComments] :: FieldDef -> !Maybe Text
data FieldType

-- | Optional module and name.
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

-- | Used instead of FieldDef to generate a smaller amount of code
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

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

-- | A raw value which can be stored in any backend and can be marshalled
--   to and from a PersistField.
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

-- | Intended especially for MongoDB backend
PersistObjectId :: ByteString -> PersistValue

-- | Intended especially for PostgreSQL backend for text arrays
PersistArray :: [PersistValue] -> PersistValue

-- | Using PersistDbSpecific allows you to use types specific to a
--   particular backend For example, below is a simple example of the
--   PostGIS geography type:
--   
--   
--   data Geo = Geo ByteString
--   
--   instance PersistField Geo where
--     toPersistValue (Geo t) = PersistDbSpecific t
--   
--     fromPersistValue (PersistDbSpecific t) = Right $ Geo $ Data.ByteString.concat ["'", t, "'"]
--     fromPersistValue _ = Left "Geo values must be converted from PersistDbSpecific"
--   
--   instance PersistFieldSql Geo where
--     sqlType _ = SqlOther "GEOGRAPHY(POINT,4326)"
--   
--   toPoint :: Double -> Double -> Geo
--   toPoint lat lon = Geo $ Data.ByteString.concat ["'POINT(", ps $ lon, " ", ps $ lat, ")'"]
--     where ps = Data.Text.pack . show
--   
--   
--   If Foo has a geography field, we can then perform insertions like the
--   following:
--   
--   
--   insert $ Foo (toPoint 44 44)
--   
PersistDbSpecific :: ByteString -> PersistValue

-- | There are 3 kinds of references 1) composite (to fields that exist in
--   the record) 2) single field 3) embedded
data ReferenceDef
NoReference :: ReferenceDef

-- | A ForeignRef has a late binding to the EntityDef it references via
--   HaskellName and has the Haskell type of the foreign key in the form of
--   FieldType
ForeignRef :: !HaskellName -> !FieldType -> ReferenceDef
EmbedRef :: EmbedEntityDef -> ReferenceDef
CompositeRef :: CompositeDef -> ReferenceDef

-- | A SelfReference stops an immediate cycle which causes non-termination
--   at compile-time (issue #311).
SelfReference :: ReferenceDef

-- | A SQL data type. Naming attempts to reflect the underlying Haskell
--   datatypes, eg SqlString instead of SqlVarchar. Different SQL databases
--   may have different translations for these types.
data SqlType
SqlString :: SqlType
SqlInt32 :: SqlType
SqlInt64 :: SqlType
SqlReal :: SqlType
SqlNumeric :: Word32 -> Word32 -> SqlType
SqlBool :: SqlType
SqlDay :: SqlType
SqlTime :: SqlType

-- | Always uses UTC timezone
SqlDayTime :: SqlType
SqlBlob :: SqlType

-- | a backend-specific name
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

-- | The reason why a field is nullable is very important. A field
--   that is nullable because of a Maybe tag will have its type
--   changed from A to Maybe A. OTOH, a field that is
--   nullable because of a nullable tag will remain with the same
--   type.
data WhyNullable
ByMaybeAttr :: WhyNullable
ByNullableAttr :: WhyNullable

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

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

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

-- | Aggregate mode
data AggMode

-- | ALL
AggModeAll :: AggMode

-- | DISTINCT
AggModeDistinct :: AggMode

-- | (array_agg) Concatenate distinct input values, including
--   NULLs, into an array.
--   
--   Since: 2.5.3
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]))

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

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

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

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

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

-- | (random()) Split out into database specific modules because
--   MySQL uses `rand()`.
--   
--   Since: 2.6.0
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
--   insertSelect but allows to update values that violate a
--   constraint during insertions.
--   
--   Example of usage:
--   
--   
--   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 ->
--       return $ Foo <# (b ^. BarNum)
--     )
--     (current excluded ->
--       [FooNum =. (current ^. FooNum) +. (excluded ^. FooNum)]
--     )
--   
--   
--   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 insertSelectWithConflict 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
--   
--   Do not use this function directly, instead define a new
--   function and give it a type (see unsafeSqlBinOp)
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:
--   
--   
--   
- The Type column in the PostgreSQL documentation tables
--   are the types of the right operand, the left is always
--   jsonb.
--   
- Since these operators can all take NULL values as their
--   input, and most can also output NULL values (even when the
--   inputs are guaranteed to not be NULL), all JSONB values are
--   wrapped in Maybe. This also makes it easier to chain them. (cf.
--   JSONBExpr) Just use the just function to lift any
--   non-Maybe JSONB values in case it doesn't type check.
--   
- As long as the previous operator's resulting value is a
--   JSONBExpr, any other JSON operator can be used to transform the
--   JSON further. (e.g. [1,2,3] -> 1 @> 2)
--   
--   
--   The PostgreSQL version the functions work with are included
--   in their description.
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

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

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

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

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

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

-- | Requires PostgreSQL version >= 9.3
--   
--   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
--   NULL (Nothing) when encountering any other JSON type.
--   
--   The Texts 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:
--   
--   
--   x ^. TestBody #>. ["0","1"]
--   
--   
--   The following JSON values in the test table's body
--   column will be affected:
--   
--   
--    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
--   
--   
--   
PostgreSQL Documentation
--   
--   
--        | Type   | Description                       |  Example                                   | Example Result
--   -----+--------+-----------------------------------+--------------------------------------------+----------------
--    #>  | text[] | Get JSON object at specified path | '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}' | {"c": "foo"}
--   
(#>.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 #>.

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

-- | Requires PostgreSQL version >= 9.4
--   
--   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:
--   https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)
--   
--   
PostgreSQL Documentation
--   
--   
--       | Type  | Description                                                 |  Example
--   ----+-------+-------------------------------------------------------------+---------------------------------------------
--    @> | jsonb | Does the left JSON value contain within it the right value? | '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb
--   
(@>.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)
infixl 6 @>.

-- | Requires PostgreSQL version >= 9.4
--   
--   This operator works the same as @>., 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:
--   https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)
--   
--   
PostgreSQL Documentation
--   
--   
--       | Type  | Description                                              |  Example
--   ----+-------+----------------------------------------------------------+---------------------------------------------
--    <@ | jsonb | Is the left JSON value contained within the right value? | '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb
--   
(<@.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)
infixl 6 <@.

-- | Requires PostgreSQL version >= 9.4
--   
--   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:
--   https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)
--   
--   
PostgreSQL Documentation
--   
--   
--      | Type | Description                                                     |  Example
--   ---+------+-----------------------------------------------------------------+-------------------------------
--    ? | text | Does the string exist as a top-level key within the JSON value? | '{"a":1, "b":2}'::jsonb ? b
--   
(?.) :: JSONBExpr a -> Text -> SqlExpr (Value Bool)
infixl 6 ?.

-- | Requires PostgreSQL version >= 9.4
--   
--   This operator checks if ANY 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:
--   https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)
--   
--   
PostgreSQL Documentation
--   
--   
--       | Type   | Description                                            |  Example
--   ----+--------+--------------------------------------------------------+---------------------------------------------------
--    ?| | text[] | Do any of these array strings exist as top-level keys? | '{"a":1, "b":2, "c":3}'::jsonb ?| array[b, c]
--   
(?|.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)
infixl 6 ?|.

-- | Requires PostgreSQL version >= 9.4
--   
--   This operator checks if ALL 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:
--   https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)
--   
--   
PostgreSQL Documentation
--   
--   
--       | Type   | Description                                            |  Example
--   ----+--------+--------------------------------------------------------+----------------------------------------
--    ?& | text[] | Do all of these array strings exist as top-level keys? | '["a", "b"]'::jsonb ?& array[a, b]
--   
(?&.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)
infixl 6 ?&.

-- | Requires PostgreSQL version >= 9.5
--   
--   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.
--   -1 being the last element, -2 being the second to
--   last, etc.)
--   
--   CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN USED ON ANYTHING
--   OTHER THAN OBJECTS OR ARRAYS WHEN USING TEXT, AND ANYTHING
--   OTHER THAN ARRAYS WHEN USING INTEGERS!
--   
--   
Objects and arrays
--   
--   
--   {"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                      - <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
--   
--   
--   
PostgreSQL Documentation
--   
--   
--      | Type    | Description                                                            |  Example
--   ---+---------+------------------------------------------------------------------------+-------------------------------------------------
--    - | text    | Delete key/value pair or string element from left operand.             | '{"a": "b"}'::jsonb - a
--      |         | 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. |
--   
(-.) :: JSONBExpr a -> JSONAccessor -> JSONBExpr b
infixl 6 -.

-- | Requires PostgreSQL version >= 10
--   
--   Removes a set of keys from an object, or string elements from an
--   array.
--   
--   This is the same operator internally as -., but the option to
--   use a text array, instead of text or
--   integer was only added in version 10. That's why this
--   function is seperate from -.
--   
--   NOTE: The following is equivalent:
--   
--   
--   {some JSON expression} -. "a" -. "b"
--   
--   
--   is equivalent to
--   
--   
--   {some JSON expression} --. ["a","b"]
--   
--   
--   
PostgreSQL Documentation
--   
--   
--      | 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.                  |
--   
(--.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 --.

-- | Requires PostgreSQL version >= 9.5
--   
--   This operator can remove elements nested in an object.
--   
--   If a Text 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.
--   -1 being the last element, -2 being the second to
--   last, etc.)
--   
--   CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN USED ON
--   ANYTHING OTHER THAN OBJECTS OR ARRAYS, AND WILL ALSO THROW WHEN
--   TRYING TO SELECT AN ARRAY ELEMENT WITH A NON-INTEGER TEXT
--   
--   
Objects
--   
--   
--   {"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}
--   
--   
--   
Arrays
--   
--   
--   [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"
--   
--   
--   
Other values
--   
--   
--   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
--   
--   
--   
PostgreSQL Documentation
--   
--   
--       | 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) |
--   
(#-.) :: JSONBExpr a -> [Text] -> JSONBExpr b
infixl 6 #-.

-- | Requires PostgreSQL version >= 9.5
--   
--   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.
--   
--   CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN CONCATENATING
--   A JSON OBJECT WITH A JSON SCALAR VALUE!
--   
--   
Arrays
--   
--   This operator is a standard concatenation function when used on
--   arrays:
--   
--   
--   [1,2]   || [2,3]   == [1,2,2,3]
--   []      || [1,2,3] == [1,2,3]
--   [1,2,3] || []      == [1,2,3]
--   
--   
--   
Objects
--   
--   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.
--   
--   
--   {"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
--   
--   
--   
Scalar values
--   
--   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.
--   
--   
--   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}]
--   
--   
--   
PostgreSQL Documentation
--   
--   
--       | Type  | Description                                         |  Example
--   ----+-------+-----------------------------------------------------+--------------------------------------------
--    || | jsonb | Concatenate two jsonb values into a new jsonb value | '["a", "b"]'::jsonb || '["c", "d"]'::jsonb
--   
--   
--   Note: The || operator concatenates the elements at the top
--   level of each of its operands. It does not operate
--   recursively.
--   
--   For example, if both operands are objects with a common key field
--   name, the value of the field in the result will just be the
--   value from the right hand operand.
(||.) :: JSONBExpr a -> JSONBExpr b -> JSONBExpr c
infixl 6 ||.

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

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