on master help sign in
Rename where{,Not}Exists to present and absent respectively
commit4cb7797d9e41765f08a1f7477f45eeb63b89ce8b authorShane O'Brien <shane.obrien@circuithub.com> dateSat 19 Jun 2021, 11:46 (5 years ago) parentbac704c
4 files changed+28−20
Changelog.md+8 docs/concepts/queries.rst+6−6 src/Rel8.hs+2−2 src/Rel8/Query/Exists.hs+12−12
Changelog.md+8
@@ -1,3 +1,11 @@
1+# 1.1.0.0 (??)
2+
3+* Fixes a bug where cartesian products of queries using `catListTable`, `catNonEmptyTable`, `catList` and `catNonEmpty` would incorrectly be zipped instead.
4+
5+* Simplify `evaluate` to run directly inside the `Query` monad, rendering the `Evaluate` monad unnecessary.
6+
7+* Rename `whereExists` and `whereNotExists` to `present` and `absent` respectively.
8+
19# 1.0.0.1 (2021-06-21)
210
311This release contains various fixes for documentation.
docs/concepts/queries.rst+6−6
@@ -138,20 +138,20 @@ a query. The above query could thus be written as::
138138
139139``where_`` and ``filter`` allow you to filter rows based on an expression, but
140140sometimes we want to filter based on another query. For this, Rel8 offers
141−``whereExists`` and ``whereNotExists``. For example, if all blog posts have a
142−list of tags, we could use ``whereExists`` to find all blog posts that have been
141+``present`` and ``absent``. For example, if all blog posts have a
142+list of tags, we could use ``present`` to find all blog posts that have been
143143tagged as "Haskell"::
144144
145145 blogPost <- each blogPostSchema
146− whereExists do
146+ present do
147147 filter (("Haskell" ==.) . tagName) =<< tagFromBlogPost blogPost
148148
149−Notice that this example uses ``whereExists`` with a query that itself uses
150−``filter``. For each blog post, ``whereExists`` causes that row to be selected
149+Notice that this example uses ``present`` with a query that itself uses
150+``filter``. For each blog post, ``present`` causes that row to be selected
151151only if the associated query finds a tag for that blog post with the ``tagName``
152152"Haskell".
153153
154−Like ``filter`` there is also a chaining variant of ``whereExists`` - ``with``.
154+Like ``filter`` there is also a chaining variant of ``present`` - ``with``.
155155We could rewrite the above query using ``with`` as::
156156
157157 haskellBlogPost <-
src/Rel8.hs+2−2
@@ -178,8 +178,8 @@ module Rel8
178178 -- ** Filtering
179179 , filter
180180 , where_
181− , whereExists
182− , whereNotExists
181+ , present
182+ , absent
183183 , distinct
184184 , distinctOn
185185 , distinctOnBy
src/Rel8/Query/Exists.hs+12−12
@@ -2,8 +2,8 @@
22
33module Rel8.Query.Exists
44 ( exists, inQuery
5− , whereExists, with, withBy
6− , whereNotExists, without, withoutBy
5+ , present, with, withBy
6+ , absent, without, withoutBy
77 )
88where
99
@@ -25,7 +25,7 @@ import Rel8.Table.Maybe ( isJustTable )
2525
2626-- | Checks if a query returns at least one row.
2727exists :: Query a -> Query (Expr Bool)
28−exists = fmap isJustTable . optional . whereExists
28+exists = fmap isJustTable . optional . present
2929-- FIXME: change this when b7aacc07c6392654cae439fc3b997620c3aa7a87 makes it
3030-- into a release of Opaleye
3131
@@ -34,23 +34,23 @@ inQuery :: EqTable a => a -> Query a -> Query (Expr Bool)
3434inQuery a = exists . (>>= filter (a ==:))
3535
3636
37−-- | Produce the empty query if the given query returns no rows. @whereExists@
37+-- | Produce the empty query if the given query returns no rows. @present@
3838-- is equivalent to @WHERE EXISTS@ in SQL.
39−whereExists :: Query a -> Query ()
40−whereExists = mapOpaleye Opaleye.restrictExists
39+present :: Query a -> Query ()
40+present = mapOpaleye Opaleye.restrictExists
4141
4242
43−-- | Produce the empty query if the given query returns rows. @whereNotExists@
43+-- | Produce the empty query if the given query returns rows. @absent@
4444-- is equivalent to @WHERE NOT EXISTS@ in SQL.
45−whereNotExists :: Query a -> Query ()
46−whereNotExists = mapOpaleye Opaleye.restrictNotExists
45+absent :: Query a -> Query ()
46+absent = mapOpaleye Opaleye.restrictNotExists
4747
4848
4949-- | @with@ is similar to 'filter', but allows the predicate to be a full query.
5050--
51−-- @with f a = a <$ whereExists (f a)@, but this form matches 'filter'.
51+-- @with f a = a <$ present (f a)@, but this form matches 'filter'.
5252with :: (a -> Query b) -> a -> Query a
53−with f a = a <$ whereExists (f a)
53+with f a = a <$ present (f a)
5454
5555
5656-- | Like @with@, but with a custom membership test.
@@ -60,7 +60,7 @@ withBy predicate bs = with $ \a -> bs >>= filter (predicate a)
6060
6161-- | Filter rows where @a -> Query b@ yields no rows.
6262without :: (a -> Query b) -> a -> Query a
63−without f a = a <$ whereNotExists (f a)
63+without f a = a <$ absent (f a)
6464
6565
6666-- | Like @without@, but with a custom membership test.