I would probably make a named query
class Post { User user String subject String body Date dateCreated static namedQueries = { todaysPosts { def now = new Date().clearTime() between('dateCreated', now, now+1) } } }
Then you can use it like:
Post.todaysPosts.count()
or
Post.todaysPosts.list() Post.todaysPosts.list(max: 10, offset: 5)
you can even do
Post.todaysPosts.findAllByUser(user)
Here's more for named queries
source share