@@ -23,6 +23,19 @@ import Rel8.Table.Eq ( EqTable, (==:) )
2323import Rel8.Table.Maybe ( isJustTable )
2424
2525
26+-- | Checks if a query returns at least one row.
27+--
28+-- >>> :{
29+-- mapM_ print =<< select c do
30+-- author <- each authorSchema
31+-- hasProjects <- exists do
32+-- project <- each projectSchema
33+-- where_ $ authorId author ==. projectAuthorId project
34+-- return (authorName author, hasProjects)
35+-- :}
36+-- ("Ollie",True)
37+-- ("Bryan O'Sullivan",True)
38+-- ("Emily Pillmore",False)
2639exists :: Query a -> Query (Expr Bool)
2740exists = fmap isJustTable . optional . whereExists
2841-- FIXME: change this when b7aacc07c6392654cae439fc3b997620c3aa7a87 makes it