Skip to content

Instantly share code, notes, and snippets.

@sadache
Created April 18, 2011 17:00
Show Gist options
  • Save sadache/925698 to your computer and use it in GitHub Desktop.
Save sadache/925698 to your computer and use it in GitHub Desktop.
def prevNext = {
SQL(
"""
(
select *, 'next' as pos from post
where postedAt < {date} order by postedAt desc limit 1
)
union
(
select *, 'prev' as pos from post
where postedAt > {date} order by postedAt asc limit 1
)
order by postedAt desc
"""
).on("date" -> postedAt).as(
opt('pos.is("prev")~>Post.on("")) ~ opt('pos.is("next")~>Post.on(""))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment