ConnectionPool.singleton("jdbc:...","user","password")
caseclass User(id: Int, name: String)
val users = DB.readOnly { session =>
SQL("select * from user").map { rs =>
User(rs.int("id"), rs.string("name"))
}.list.apply()
}
DB .autoCommit { session =>
SQL("insert into user values (?,?)").bind(123, "Alice").update.apply()
}
DB localTx { session =>
SQL("insert into user values (?,?)").bind(123, "Alice").update.apply()
}
using(DB(ConnectionPool.borrow())) { db =>
db.begin()
try {
DB withTx { session =>
SQL("update user set name = ? where id = ?").bind("Alice", 123).update.apply()
}
db.commit()
} catch { case e =>
db.rollbackIfActive()
throw e
}
}
SQL abstraction's companion object.