Created
August 10, 2017 06:32
-
-
Save anonymous/d0f868d3c7d74efe9ad1c0ce245304f2 to your computer and use it in GitHub Desktop.
the description for this gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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