I'm trying to figure out how to write the following query using Esqueleto
SELECT COUNT("person"."id")
FROM "person"
WHERE (("person"."admin" = 't' OR "person"."vip" = 't') // 't' as in True
OR "person"."karma" >= 5000 AND "person"."hellbanned" = 'f')
Here's how my model is defined
Person
admin Bool
vip Bool
karma Int
hellbanned Bool
I've managed to get almost everything, except for the COUNT
part
select $
from $ \p -> do
where_
((p ^. PersonAdmin ==. val True) ||. (p ^. PersonVip ==. val True)
&&. (p ^. PersonKarma >=. val 5000) &&. (p ^. PersonHellbanned ==. val False))
return $ p ^. PersonId
I managed to find a countRows
function, however I haven't managed to find a way to combine these two in a way that typechecks.
I'm also not sure if I need all those p ^.
in each branch of the where clause, or if those can be collapsed together somehow?