试图理解 Scala 中的以下语法(隐式会话):
def getDates(date: String): Option[String] = DB.readOnly { implicit session =>
val date = "20201020"
}
使用来自 scalalikejdbc 的 readOnly 方法。方法的定义是:
def readOnly[A](execution: DBSession => A)(implicit context: CPContext = NoCPContext, settings: SettingsProvider = SettingsProvider.default): A = {
val cp = connectionPool(context)
using(cp.borrow()) { conn =>
DB(conn, cp.connectionAttributes, settings).autoClose(false).readOnly(execution)
}
}