Created
May 23, 2015 15:13
-
-
Save jim-collins/2dff73681125e3034451 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
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