I'm using lifted embedding, and have tried to reduce this example to its essence (although I've removed the db creds). Troubleshooting performance for this basic setup I was surprised to see from the logs that slick appears to be preparing an identical statement for every execution. Am I using the session and queries correctly here? Dependencies, code, and log output below.
"com.typesafe.slick" %% "slick" % "1.0.1-RC1",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
-----
import scala.slick.driver.PostgresDriver.simple._
trait MbNameDAL {
case class MbName(id: Int, name: String)
object MbName {
val byIdQ = for {
id <- Parameters[(Int)]
x <- MbNameTable if
x.id is id
} yield x
def byId(id: Int)(implicit session: Session): MbName = byIdQ.first(id)
}
object MbNameTable extends Table[MbName]("artist_name") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def * = id ~ name <> (MbName.apply _, MbName.unapply _)
}
}
import Database.threadLocalSession
object StandaloneExample extends App with MbNameDAL {
val db = Database.forURL("jdbc:postgresql:_", "_", "_", driver = "org.postgresql.Driver")
db withSession {
println(MbName.byId(1))
println(MbName.byId(1))
println(MbName.byId(2))
}
}
------
11:26:47.102 [main] DEBUG s.s.compiler.FixRowNumberOrdering - No row numbers to fix
11:26:47.102 [main] DEBUG scala.slick.compiler.QueryCompiler - After phase fixRowNumberOrdering: (no change)
11:26:47.119 [main] DEBUG scala.slick.session.BaseSession - Preparing statement: select s6."id", s6."name" from "artist_name" s6 where s6."id" = ?
MbName(1,Barsotti, Marcel)
11:26:47.399 [main] DEBUG scala.slick.session.BaseSession - Preparing statement: select s6."id", s6."name" from "artist_name" s6 where s6."id" = ?
MbName(1,Barsotti, Marcel)
11:26:47.446 [main] DEBUG scala.slick.session.BaseSession - Preparing statement: select s6."id", s6."name" from "artist_name" s6 where s6."id" = ?
MbName(2,Isamar Compania)