Skip to content

Instantly share code, notes, and snippets.

@jim-collins
Created May 23, 2015 15:13
Show Gist options
  • Save jim-collins/2dff73681125e3034451 to your computer and use it in GitHub Desktop.
Save jim-collins/2dff73681125e3034451 to your computer and use it in GitHub Desktop.
package dojo
import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
object HelloSlick {
val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver="org.h2.Driver")
val emps = TableQuery[Emp]
val setup = DBIO.seq(
// Create the tables, including primary and foreign keys
(emps.schema).create,
// Insert some employees
emps ++= Seq(
("Jim"),
("Ed"),
("Michael"),
("Miguelf"),
("Ian")
)
)
def main (args: Array[String]) {
try {
val setupFuture = db.run(setup)
db.run(emps.result).map(_.foreach {
println(_)
})
} finally db.close()
}
}
class Emp(tag: Tag) extends Table[(String)](tag, "Employees") {
def name = column[String]("Emp_NAME", O.PrimaryKey)
def * = (name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment