0

Trying to understand the following syntax (the implicit session) in Scala:

def getDates(date: String): Option[String] = DB.readOnly { implicit session =>
 val date = "20201020"
}

Using the readOnly method from scalalikejdbc. Definition of method is:

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)
  }
} 
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
kgui
  • 4,015
  • 5
  • 41
  • 53

1 Answers1

2

It means session is in implicit scope for the entirety of the function body, for example

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 
}
Mario Galic
  • 47,285
  • 6
  • 56
  • 98