Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d0f868d3c7d74efe9ad1c0ce245304f2 to your computer and use it in GitHub Desktop.
Save anonymous/d0f868d3c7d74efe9ad1c0ce245304f2 to your computer and use it in GitHub Desktop.
the description for this gist
val slickInterpreter = new Language[Future] {
/// I've skipped the Slick related part, you probably seen it 100 times already
private val slickPersonQuery = TableQuery[SlickPersonTable]
override type QueryObj = Query[SlickPersonTable, Person, Seq]
override def people(): Future[Raw] = {
Future.successful(Raw(slickPersonQuery))
}
override def filterByIds(query: Future[Raw], ids: Seq[Int]): Future[WithFilter] = {
query.map(_.q.filter(_.id inSet ids)).map(WithFilter)
}
override def paginate(query: Future[WithFilter], skip: Int, limit: Int): Future[WithPagination] = {
query.map(_.q.drop(skip).take(limit)).map(WithPagination)
}
override def run(query: Future[WithPagination]): Future[Seq[Person]] = {
query.flatMap { case finalQuery =>
db.run(finalQuery.q.result)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment