| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Database.Persist.Sql.Lifted.Query.Core
Synopsis
- data SqlQuery a
- where_ :: SqlExpr (Value Bool) -> SqlQuery ()
- limit :: Int64 -> SqlQuery ()
- offset :: Int64 -> SqlQuery ()
- distinct :: SqlQuery a -> SqlQuery a
- distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
- orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
- don :: SqlExpr (Value a) -> SqlExpr DistinctOn
- distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
- withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a
Type
SQL backend for esqueleto using SqlPersistT.
Instances
Where
Limit & offset
Distinct & order by
distinctOn :: [SqlExpr DistinctOn] -> 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: esqueleto-2.2.4
orderBy :: [SqlExpr OrderBy] -> SqlQuery () #
ORDER BY clause. See also asc and desc.
Multiple calls to orderBy get concatenated on the final
query, including distinctOnOrderBy.
don :: SqlExpr (Value a) -> SqlExpr DistinctOn #
Erase an SqlExpression's type so that it's suitable to
be used by distinctOn.
Since: esqueleto-2.2.4
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a #
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] $ doorderBy[asc foo, desc bar, desc quux] ...
Since: esqueleto-2.2.4
withNonNull
withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a #
Project an SqlExpression that may be null, guarding against null cases.