meteficha/esqueleto — pull request #15 by himura (2013-05-20 11:43:16+00:00)
Title: Add HAVING support.

I've added the `having` method to support `HAVING` clause with some aggregate functions like this:

~~~~ {.haskell}
ret <- select $
from $ \(p `LeftOuterJoin` b) -> do
on (p ^. PersonId ==. b ^. BlogPostAuthorId)
let cnt = count (b ^. BlogPostId)
groupBy (p ^. PersonId)
having (cnt >. (val 0))
orderBy [ asc cnt ]
return (p, cnt)
~~~~

It generates

~~~~ {.sql}
SELECT "Person"."id", "Person"."name", "Person"."age", COUNT("BlogPost"."id")
FROM "Person" LEFT OUTER JOIN "BlogPost" ON "Person"."id" = "BlogPost"."authorId"
GROUP BY "Person"."id"
HAVING COUNT("BlogPost"."id") > ?
ORDER BY COUNT("BlogPost"."id") ASC
~~~~