我有一個GitHub項目,是由大量小巧玲瓏的啓發,被稱爲dbmapper
優勢,較油滑的是:
- 沒有DSL - 你已經知道了良好的數據DSL,它被稱爲SQL
- 完全異步
- 很少的樣板代碼
下面是一個例子:
// Scala class that maps to the book table, with columns to match the class members
case class Book(
bookId: Int,
title: String,
retailPrice: BigDecimal,
publishDate: LocalDate)
// mapping function from table row to Book class,
// auto generated at compile time by Scala Macro
implicit def rowToBook: RowData => Book = (r) => DbCodeGenerator.rowToClass[Book](r)
// query returning future list of books,
// safe query interpolation, the maxPrice is converted to a query argument
val maxPrice = 11.99
val allBooksFuture = DbAsync.exec[Book](q"select * from book where retail_price < $maxPrice")
val oneBook: Future[Book] = DbAsync.execOne[Book](q"select * from book where book_id = 2")
// returns Future[Option[]]
val maybeOneBook: Future[Option[Book]] = DbAsync.execOneOrNone[Book](q"select * from book where book_id = -123")
如果你知道從DOTNET世界短小精悍然後dbmapper會感到奇怪的熟悉!
我可能應該更清楚地關注浮油,因爲它應該是在Play 2.1中執行SQL的首選方式。他們關於普通SQL類型的文檔顯示他們更喜歡其他兩種API。 –