Slide 4
Slide 4 text
Basic usage of ScalikeJDBC
• Only 3 steps to issue a database query:
• 1) Build a SQL object
• 2) Define a function to extract values from ResultSet
• 3) Perform SQL execution with an implicitly passed
database session (which can be transaction-wired)
1)> val q: SQL[Nothing, NoExtractor] = sql"select id, name from members limit 2"
2)> val toTuple: (WrappedResultSet) => (Int, Option[String]) =
| (rs) => (rs.get[Int]("id"), rs.get[Option[String]]("name"))
3)> val rows: Seq[(Int, Option[String])] = q.map(toTuple).list.apply()
[SQL Execution] select id, name from members limit 2; (0 ms)
rows: Seq[(Int, Option[String])] = List((1,Some(Alice)), (2,Some(Bob)))