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
  • 291,719
  • 55
  • 540
  • 600
kgui
  • 3,879
  • 4
  • 39
  • 51

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
  • 45,265
  • 6
  • 51
  • 87