Document isNothing (#203)

* Document isNothing

I have two goals with this documentation:

1. Surface how to do `IS NOT NULL`. This PR makes a search for that string turn up a result, and directs you to combine `isNothing` with `not_`.
2. Documents a major gotcha where behavior between Persistent and Esqueleto is different. I haven't tested this in awhile, but we run into this gotcha occassionally, so I'm pretty confident it's still an issue.

* ..

* ..

Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
This commit is contained in:
Maximilian Tagher 2020-08-26 14:36:41 -04:00 committed by GitHub
parent 1de1ee9e6e
commit dd16400d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,7 @@
3.3.3.3
========
- @maxgabriel
- [#203](https://github.com/bitemyapp/esqueleto/pull/203) Document `isNothing`
- @sestrella
- [#198](https://github.com/bitemyapp/esqueleto/pull/198) - Allow PostgreSQL aggregate functions to take a filter clause

View File

@ -579,6 +579,22 @@ val :: PersistField typ => typ -> SqlExpr (Value typ)
val v = ERaw Never $ const ("?", [toPersistValue v])
-- | @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__ | @'Database.Persist.!=.' Nothing@ | @IS NOT NULL@ |
-- +----------------+----------------------------------+---------------+
-- | __Esqueleto__ | @'!=.' Nothing@ | @!= NULL@ |
-- +----------------+----------------------------------+---------------+
--
-- In SQL, @= NULL@ and @!= NULL@ return NULL instead of true or false. For this reason, you very likely do not want to use @'!=.' Nothing@ in Esqueleto.
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing v =
case v of