Got curious and did some digging, the DBAction
class extends the CurrentDBAction
trait which has an apply method:
def apply[A](dbName: String, bodyParser: BodyParser[A] = anyContent)(requestHandler: DBSessionRequest[A] => SimpleResult)(implicit app: Application = null) = {
val current = db(dbName, Option(app))
applyForDB(current)(requestHandler)(bodyParser)(current.withSession)(errorPage)
}
Basically what it's doing is create a DB
object and passing it to the applyForDB
function together with withSession
which should (should because I'm not an expert and the source code is not that easy to read) be exactly the same as doing this
DB.withSession {
implicit session: Session => {
/* some computation */
}
}
The code can be found here.