| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Database.Persist.Sql.Lifted.Expression.Maybe
Synopsis
- isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
- isNothing_ :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
- just :: NullableFieldProjection typ typ' => SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ'))
- nothing :: SqlExpr (Value (Maybe typ))
- joinV :: NullableFieldProjection typ typ' => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value (Maybe typ'))
- coalesce :: (PersistField a, NullableFieldProjection a a') => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a'))
- coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
Documentation
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool) #
IS NULL comparison.
For IS NOT NULL, you can negate this with not_, as in not_ (isNothing (person ^. PersonAge))
Warning: Persistent and Esqueleto have different behavior for != Nothing:
| Haskell | SQL | |
|---|---|---|
| Persistent | | IS NOT NULL |
| Esqueleto | | != NULL |
In SQL, = NULL and != NULL return NULL instead of true or false. For this reason, you very likely do not want to use in Esqueleto.
You may find these !=. Nothinghlint rules helpful to enforce this:
- error: {lhs: v Database.Esqueleto.==. Database.Esqueleto.nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing}
- error: {lhs: v Database.Esqueleto.==. Database.Esqueleto.val Nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing}
- error: {lhs: v Database.Esqueleto.!=. Database.Esqueleto.nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing}
- error: {lhs: v Database.Esqueleto.!=. Database.Esqueleto.val Nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing}isNothing_ :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool) #
An alias for isNothing that avoids clashing with the function from
Data.Maybe isNothing.
Since: esqueleto-3.5.10.0
just :: NullableFieldProjection typ typ' => SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ')) #
Analogous to Just, promotes a value of type typ into
one of type Maybe typ. It should hold that .val . Just
=== just . val
This function will try not to produce a nested Maybe. This is in accord
with how SQL represents NULL. That means that .
This behavior was changed in v3.6.0.0. If you want to produce nested just . just = justMaybe,
see just'.
joinV :: NullableFieldProjection typ typ' => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value (Maybe typ')) #
Join nested Maybes in a Value into one. This is useful when
calling aggregate functions on nullable fields.
As of v3.6.0.0, this function will attempt to work on both as well as SqlExpr
(Value (Maybe a))
inputs to make transitioning to SqlExpr (Value (Maybe (Maybe a)))NullableFieldProjection easier. This may
make type inference worse in some cases. If you want the monomorphic variant,
see joinV'
coalesce :: (PersistField a, NullableFieldProjection a a') => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a')) #
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: esqueleto-1.4.3
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a) #
Like coalesce, but takes a non-nullable SqlExpression
placed at the end of the SqlExpression list, which guarantees
a non-NULL result.
Since: esqueleto-1.4.3