-
-
Save dozed/0fe4a3e8139f2fa547c4 to your computer and use it in GitHub Desktop.
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
object slick1 extends App { | |
import scala.concurrent.Await | |
import scala.concurrent.duration.Duration | |
import slick.driver.H2Driver.api._ | |
import scala.concurrent.ExecutionContext.Implicits._ | |
import slick.jdbc.ResultSetAction | |
import slick.jdbc.GetResult._ | |
val jdbcUrl = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1" | |
val jdbcDriverClass = "org.h2.Driver" | |
val db = Database.forURL(jdbcUrl, driver = jdbcDriverClass) | |
val delay = Duration(5, "seconds") | |
// actions | |
def localTables: DBIO[Vector[String]] = | |
ResultSetAction[(String,String,String, String)](_.conn.getMetaData().getTables("", "", null, null)).map { ts => | |
ts.filter(_._4.toUpperCase == "TABLE").map(_._3).sorted | |
} | |
val createTable = sqlu"create table foo(id int)" | |
val dropTable = sqlu"drop table foo" | |
val printTables = localTables map { x => println(x) } | |
val actions = DBIO.seq( | |
printTables, | |
createTable, | |
printTables, | |
dropTable | |
) | |
// execution | |
val run1: Future[Unit] = db.run(actions) | |
Await.result(run1, delay) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment