Skip to content

Instantly share code, notes, and snippets.

@dozed
Created May 5, 2015 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dozed/0fe4a3e8139f2fa547c4 to your computer and use it in GitHub Desktop.
Save dozed/0fe4a3e8139f2fa547c4 to your computer and use it in GitHub Desktop.
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