Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/.idea/
/.idea_modules/
/target/
/project/project/
/project/target/
target
/project/typesafe.properties
/project/activator-*
/logs/
/RUNNING_PID
*.iml
.DS_Store
.sbtserver*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Typesafe, Inc.
Copyright 2013-2015 Typesafe, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions activator.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name=hello-slick
title=Hello Slick!
name=hello-slick-3.1
title=Hello Slick! (Slick 3.1)
description=Slick is Typesafe's modern database query and access library for Scala. It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred. You can also use SQL directly. This tutorial will get you started with a simple standalone Scala application that uses Slick.
tags=Basics,slick,starter
tags=Basics,slick,starter,reactive
14 changes: 6 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name := "hello-slick"

version := "1.0"

scalaVersion := "2.10.3"

mainClass in Compile := Some("HelloSlick")

libraryDependencies ++= List(
"com.typesafe.slick" %% "slick" % "2.0.0",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.h2database" % "h2" % "1.3.170",
"org.scalatest" %% "scalatest" % "2.0" % "test"
"com.typesafe.slick" %% "slick" % "3.1.1",
"org.slf4j" % "slf4j-nop" % "1.7.10",
"com.h2database" % "h2" % "1.4.187",
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
)

fork in run := true
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.0
sbt.version=0.13.7
5 changes: 5 additions & 0 deletions project/play-fork-run.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This plugin adds forked run capabilities to Play projects which is needed for Activator.

resolvers += Resolver.typesafeRepo("releases")

addSbtPlugin("com.typesafe.play" % "sbt-fork-run-plugin" % "2.3.9")
3 changes: 3 additions & 0 deletions project/sbt-ui.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This plugin represents functionality that is to be added to sbt in the future

addSbtPlugin("org.scala-sbt" % "sbt-core-next" % "0.1.1")
6 changes: 6 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
h2mem1 = {
url = "jdbc:h2:mem:test1"
driver = org.h2.Driver
connectionPool = disabled
keepAliveConnection = true
}
35 changes: 19 additions & 16 deletions src/main/scala/CaseClassMapping.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import scala.slick.driver.H2Driver.simple._
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import slick.driver.H2Driver.api._

object CaseClassMapping extends App {

// the base query for the Users table
val users = TableQuery[Users]

val db = Database.forURL("jdbc:h2:mem:hello", driver = "org.h2.Driver")
db.withSession { implicit session =>

// create the schema
users.ddl.create
// insert two User instances
users += User("John Doe")
users += User("Fred Smith")
// print the users (select * from USERS)
println(users.list)
}

val db = Database.forConfig("h2mem1")
try {
Await.result(db.run(DBIO.seq(
// create the schema
users.schema.create,

// insert two User instances
users += User("John Doe"),
users += User("Fred Smith"),

// print the users (select * from USERS)
users.result.map(println)
)), Duration.Inf)
} finally db.close
}

case class User(name: String, id: Option[Int] = None)
Expand All @@ -27,7 +30,7 @@ class Users(tag: Tag) extends Table[User](tag, "USERS") {
// Auto Increment the id primary key column
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
// The name can't be null
def name = column[String]("NAME", O.NotNull)
def name = column[String]("NAME")
// the * projection (e.g. select * ...) auto-transforms the tupled
// column values to / from a User
def * = (name, id.?) <> (User.tupled, User.unapply)
Expand Down
Loading