Scalalikejdbc隐式参数

Scalalikejdbc隐式参数,scala,scalikejdbc,Scala,Scalikejdbc,尝试理解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 = NoCPCon

尝试理解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)
  }
} 

例如,这意味着
会话
在整个会话的隐式范围内

trait Foo
val foo = new Foo {}
def g(implicit foo: Foo) = ???
val f: Foo => String = implicit foo => {
  // foo is in implicit scope in the method body
  g // foo argument passed in to g implicitly 
}

例如,这意味着
会话
在整个会话的隐式范围内

trait Foo
val foo = new Foo {}
def g(implicit foo: Foo) = ???
val f: Foo => String = implicit foo => {
  // foo is in implicit scope in the method body
  g // foo argument passed in to g implicitly 
}