Export Wrapper for slick.session.Database
I have many queries in the format
db withSession{ implicit session : Session =>
Q.update[String](query).execute(id)} and I want to write it in a much
easier way: db.execute(query, id). So, I defined the wrapper in the same
file/package where I initialized the db. How can I export the wrapper such
that I can use it in this way? Now, I have the Problem value execute is
not a member of scala.slick.session.Database
Note: query and id are Strings. I use plain sql
db is an already initialized Database:
object SQLUtilities{
lazy val db = init()
private def init() = {Database.forURL("jdbc:postgresql://localhost",
driver = "org.postgresql.Driver")}
def execute(query: String, id: String){
db withSession{ //implicit session : Session =>
Q.update[String](query).execute(id)
}
}
}
Standard packages like import scala.slick.jdbc.{GetResult, StaticQuery =>
Q}; import scala.slick.session.{Session, Database} are imported
No comments:
Post a Comment