Skip to content

Instantly share code, notes, and snippets.

@ghidalgo3
Created October 28, 2014 18:36
Show Gist options
  • Save ghidalgo3/25e0d88f5f495d47f73b to your computer and use it in GitHub Desktop.
Save ghidalgo3/25e0d88f5f495d47f73b to your computer and use it in GitHub Desktop.
Slick db implicits
val table : Table[Product] = Products.products //this is the DTO
private def database(f : => Unit) = {
Database.forURL("jdbc:mysql://127.0.0.1:3306/products", driver = "com.mysql.jdbc.Driver") withSession {
implicit session => f
}
}
def add(product : Product) = {
database {//the compiler complains that there is no implicit session to run this with
//but I thought that passing it to to database method would provide the session
//how do I get around this without just copy and pasting that Database.for....
//anywhere I want to make a db call?
table.insert(product)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment