on master help sign in
Document whereExists and whereNotExists
commit2d8335d480453e1683af7081e0cfbdf7bfb8bc03 authorOllie Charles <ollie@ocharles.org.uk> dateTue 23 Mar 2021, 16:22 (6 years ago) parentb31e84e
1 file changed+24
src/Rel8/Query/Exists.hs+24
src/Rel8/Query/Exists.hs+24
@@ -46,10 +46,34 @@ inQuery :: EqTable a => a -> Query a -> Query (Expr Bool)
4646inQuery a = exists . (>>= filter (a ==:))
4747
4848
49+-- | Produce the empty query if the given query returns no rows. @whereExists@
50+-- is equivalent to @WHERE EXISTS@ in SQL.
51+--
52+-- >>> :{
53+-- select c do
54+-- author <- each authorSchema
55+-- whereExists do
56+-- project <- each projectSchema
57+-- where_ $ projectAuthorId project ==. authorId author
58+-- return $ authorName author
59+-- :}
60+-- ["Ollie","Bryan O'Sullivan"]
4961whereExists :: Query a -> Query ()
5062whereExists = mapOpaleye Opaleye.restrictExists
5163
5264
65+-- | Produce the empty query if the given query returns rows. @whereNotExists@
66+-- is equivalent to @WHERE NOT EXISTS@ in SQL.
67+--
68+-- >>> :{
69+-- select c do
70+-- author <- each authorSchema
71+-- whereNotExists do
72+-- project <- each projectSchema
73+-- where_ $ projectAuthorId project ==. authorId author
74+-- return $ authorName author
75+-- :}
76+-- ["Emily Pillmore"]
5377whereNotExists :: Query a -> Query ()
5478whereNotExists = mapOpaleye Opaleye.restrictNotExists
5579