Created
October 28, 2014 18:36
-
-
Save ghidalgo3/25e0d88f5f495d47f73b to your computer and use it in GitHub Desktop.
Slick db implicits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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