on master help sign in
Rename where{,Not}Exists to present and absent respectively
4cb7797Shane O'Brien
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+
1# 1.0.0.1 (2021-06-21)
9# 1.0.0.1 (2021-06-21)
2
10
3This release contains various fixes for documentation.
11This 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::
138
138
139``where_`` and ``filter`` allow you to filter rows based on an expression, but
139``where_`` and ``filter`` allow you to filter rows based on an expression, but
140sometimes we want to filter based on another query. For this, Rel8 offers
140sometimes we want to filter based on another query. For this, Rel8 offers
141−``whereExists`` and ``whereNotExists``. For example, if all blog posts have a
141+``present`` and ``absent``. For example, if all blog posts have a
142−list of tags, we could use ``whereExists`` to find all blog posts that have been
142+list of tags, we could use ``present`` to find all blog posts that have been
143tagged as "Haskell"::
143tagged as "Haskell"::
144
144
145 blogPost <- each blogPostSchema
145 blogPost <- each blogPostSchema
146− whereExists do
146+ present do
147 filter (("Haskell" ==.) . tagName) =<< tagFromBlogPost blogPost
147 filter (("Haskell" ==.) . tagName) =<< tagFromBlogPost blogPost
148
148
149−Notice that this example uses ``whereExists`` with a query that itself uses
149+Notice that this example uses ``present`` with a query that itself uses
150−``filter``. For each blog post, ``whereExists`` causes that row to be selected
150+``filter``. For each blog post, ``present`` causes that row to be selected
151only if the associated query finds a tag for that blog post with the ``tagName``
151only if the associated query finds a tag for that blog post with the ``tagName``
152"Haskell".
152"Haskell".
153
153
154−Like ``filter`` there is also a chaining variant of ``whereExists`` - ``with``.
154+Like ``filter`` there is also a chaining variant of ``present`` - ``with``.
155We could rewrite the above query using ``with`` as::
155We could rewrite the above query using ``with`` as::
156
156
157 haskellBlogPost <-
157 haskellBlogPost <-
src/Rel8.hs+2−2
@@ -178,8 +178,8 @@ module Rel8
178 -- ** Filtering
178 -- ** Filtering
179 , filter
179 , filter
180 , where_
180 , where_
181− , whereExists
181+ , present
182− , whereNotExists
182+ , absent
183 , distinct
183 , distinct
184 , distinctOn
184 , distinctOn
185 , distinctOnBy
185 , distinctOnBy
src/Rel8/Query/Exists.hs+12−12
@@ -2,8 +2,8 @@
2
2
3module Rel8.Query.Exists
3module Rel8.Query.Exists
4 ( exists, inQuery
4 ( exists, inQuery
5− , whereExists, with, withBy
5+ , present, with, withBy
6− , whereNotExists, without, withoutBy
6+ , absent, without, withoutBy
7 )
7 )
8where
8where
9
9
@@ -25,7 +25,7 @@ import Rel8.Table.Maybe ( isJustTable )
25
25
26-- | Checks if a query returns at least one row.
26-- | Checks if a query returns at least one row.
27exists :: Query a -> Query (Expr Bool)
27exists :: Query a -> Query (Expr Bool)
28−exists = fmap isJustTable . optional . whereExists
28+exists = fmap isJustTable . optional . present
29-- FIXME: change this when b7aacc07c6392654cae439fc3b997620c3aa7a87 makes it
29-- FIXME: change this when b7aacc07c6392654cae439fc3b997620c3aa7a87 makes it
30-- into a release of Opaleye
30-- into a release of Opaleye
31
31
@@ -34,23 +34,23 @@ inQuery :: EqTable a => a -> Query a -> Query (Expr Bool)
34inQuery a = exists . (>>= filter (a ==:))
34inQuery a = exists . (>>= filter (a ==:))
35
35
36
36
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@
38-- is equivalent to @WHERE EXISTS@ in SQL.
38-- is equivalent to @WHERE EXISTS@ in SQL.
39−whereExists :: Query a -> Query ()
39+present :: Query a -> Query ()
40−whereExists = mapOpaleye Opaleye.restrictExists
40+present = mapOpaleye Opaleye.restrictExists
41
41
42
42
43−-- | Produce the empty query if the given query returns rows. @whereNotExists@
43+-- | Produce the empty query if the given query returns rows. @absent@
44-- is equivalent to @WHERE NOT EXISTS@ in SQL.
44-- is equivalent to @WHERE NOT EXISTS@ in SQL.
45−whereNotExists :: Query a -> Query ()
45+absent :: Query a -> Query ()
46−whereNotExists = mapOpaleye Opaleye.restrictNotExists
46+absent = mapOpaleye Opaleye.restrictNotExists
47
47
48
48
49-- | @with@ is similar to 'filter', but allows the predicate to be a full query.
49-- | @with@ is similar to 'filter', but allows the predicate to be a full query.
50--
50--
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'.
52with :: (a -> Query b) -> a -> Query a
52with :: (a -> Query b) -> a -> Query a
53−with f a = a <$ whereExists (f a)
53+with f a = a <$ present (f a)
54
54
55
55
56-- | Like @with@, but with a custom membership test.
56-- | Like @with@, but with a custom membership test.
@@ -60,7 +60,7 @@ withBy predicate bs = with $ \a -> bs >>= filter (predicate a)
60
60
61-- | Filter rows where @a -> Query b@ yields no rows.
61-- | Filter rows where @a -> Query b@ yields no rows.
62without :: (a -> Query b) -> a -> Query a
62without :: (a -> Query b) -> a -> Query a
63−without f a = a <$ whereNotExists (f a)
63+without f a = a <$ absent (f a)
64
64
65
65
66-- | Like @without@, but with a custom membership test.
66-- | Like @without@, but with a custom membership test.