Last active
January 6, 2016 19:19
-
-
Save joprice/ddf61e83ee1031a25d8d to your computer and use it in GitHub Desktop.
Slick compile time query verification
This file contains hidden or 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
tsql { | |
driver = "slick.driver.MySQLDriver$" | |
db { | |
driver = "com.mysql.jdbc.Driver" | |
url = "jdbc:mysql://localhost:3306/test" | |
user = "root" | |
password = "pass" | |
} | |
} |
This file contains hidden or 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
scalaVersion := "2.11.7" | |
libraryDependencies ++= Seq( | |
"com.typesafe.slick" %% "slick" % "3.1.1", | |
"com.typesafe.slick" %% "slick-hikaricp" % "3.1.1", | |
"org.slf4j" % "slf4j-nop" % "1.6.4", | |
"mysql" % "mysql-connector-java" % "5.1.12" | |
) |
This file contains hidden or 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
import slick.backend.{DatabaseConfig, StaticDatabaseConfig} | |
import slick.dbio._ | |
import slick.driver.JdbcProfile | |
import slick.jdbc.GetResult | |
import scala.concurrent.{ExecutionContext, Await} | |
import scala.concurrent.duration._ | |
@StaticDatabaseConfig("file:src/main/resources/application.conf#tsql") | |
object Test extends App { | |
val dc = DatabaseConfig.forAnnotation[JdbcProfile] | |
import dc.driver.api._ | |
case class Supplier(id: Int, name: String) | |
def getSuppliers(id: Int)(implicit ec: ExecutionContext): DBIO[Seq[Supplier]] = { | |
tsql"select id, name from suppliers where id > $id".map(_.map(Supplier.tupled)) | |
} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val result = dc.db.run(getSuppliers(1).map { | |
println(_) | |
}) | |
Await.ready(result, 5.seconds) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment