on master help sign in
Document whereExists and whereNotExists
2d8335dOllie Charles
src/Rel8/Query/Exists.hs+24
@@ -46,10 +46,34 @@ inQuery :: EqTable a => a -> Query a -> Query (Expr Bool)
46inQuery a = exists . (>>= filter (a ==:))
46inQuery a = exists . (>>= filter (a ==:))
47
47
48
48
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"]
49whereExists :: Query a -> Query ()
61whereExists :: Query a -> Query ()
50whereExists = mapOpaleye Opaleye.restrictExists
62whereExists = mapOpaleye Opaleye.restrictExists
51
63
52
64
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"]
53whereNotExists :: Query a -> Query ()
77whereNotExists :: Query a -> Query ()
54whereNotExists = mapOpaleye Opaleye.restrictNotExists
78whereNotExists = mapOpaleye Opaleye.restrictNotExists
55
79