Skip to content

Commit

Permalink
More migration work
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurz committed Feb 24, 2024
1 parent 132232b commit 3d48198
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 36 deletions.
25 changes: 1 addition & 24 deletions play-scala-slick-example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lazy val root = (project in file("."))
.aggregate(
basicSample,
computerDatabaseSample,
personSample,
personSample
)

def sampleProject(name: String) =
Expand All @@ -25,36 +25,13 @@ def sampleProject(name: String) =
"-feature",
"-Werror"
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) =>
Seq(
"-Xsource:3",
)
case Some((3, _)) =>
Seq(
"-explain",
)
case _ => Nil
}
},
libraryDependencies ++= Seq(
guice,
"com.typesafe.play" %% "play-slick" % "5.3.0-RC1",
"com.typesafe.play" %% "play-slick-evolutions" % "5.3.0-RC1",
"com.h2database" % "h2" % "2.2.224",
specs2 % Test,
),
excludeDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
ExclusionRule("com.typesafe.play", "ssl-config-core_2.13"),
ExclusionRule("com.typesafe.play", "play_2.13"),
)
case _ => Nil
}
},
(Global / concurrentRestrictions) += Tags.limit(Tags.Test, 1)
)
.settings((Test / javaOptions) += "-Dslick.dbs.default.connectionTimeout=30 seconds")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Application @Inject() (
mapping(
"name" -> text(),
"color" -> text()
)(Cat.apply)(c => Some(c.name, c.color))
)(Cat.apply)(Cat.unapply)
)

val dogForm: Form[Dog] = Form(
mapping(
"name" -> text(),
"color" -> text()
)(Dog.apply)(d => Some(d.name, d.color))
)(Dog.apply)(Dog.unapply)
)

def index = Action.async { implicit request =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class CatDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider)(
def name = column[String]("NAME", O.PrimaryKey)
def color = column[String]("COLOR")

def * = (name, color) <> ((Cat.apply _).tupled, Cat.unapply)
def * = (name, color) <> (Cat.tupled, Cat.unapply)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class DogDAO @Inject() (@NamedDatabase("mydb") protected val dbConfigProvider: D
def name = column[String]("NAME", O.PrimaryKey)
def color = column[String]("COLOR")

def * = (name, color) <> ((Dog.apply _).tupled, Dog.unapply)
def * = (name, color) <> (Dog.tupled, Dog.unapply)
}
}
10 changes: 9 additions & 1 deletion play-scala-slick-example/samples/basic/app/models/Models.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package models

case class Cat(name: String, color: String)
object Cat {
def unapply(cat: Cat): Option[(String, String)] = Some((cat.name, cat.color))
def tupled = (this.apply _).tupled
}

case class Dog(name: String, color: String)
case class Dog(name: String, color: String)
object Dog {
def unapply(dog: Dog): Option[(String, String)] = Some((dog.name, dog.color))
def tupled = (this.apply _).tupled
}
4 changes: 2 additions & 2 deletions play-scala-slick-example/samples/basic/test/CatDaoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CatDAOSpec extends Specification {
Cat("creme puff", "grey")
)

Await.result(Future.sequence(testKitties.map(dao.insert)), 1 seconds)
val storedCats = Await.result(dao.all(), 1 seconds)
Await.result(Future.sequence(testKitties.map(dao.insert)), 1.seconds)
val storedCats = Await.result(dao.all(), 1.seconds)

storedCats.toSet must equalTo(testKitties)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Application @Inject() (
"introduced" -> optional(date("yyyy-MM-dd")),
"discontinued" -> optional(date("yyyy-MM-dd")),
"company" -> optional(longNumber)
)(Computer.apply)(c => Some(c.id, c.name, c.introduced, c.discontinued, c.companyId))
)(Computer.apply)(Computer.unapply)
)

// -- Actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait CompaniesComponent { self: HasDatabaseConfigProvider[JdbcProfile] =>
class Companies(tag: Tag) extends Table[Company](tag, "COMPANY") {
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def name = column[String]("NAME")
def * = (id.?, name) <> ((Company.apply _).tupled, Company.unapply _)
def * = (id.?, name) <> (Company.tupled, Company.unapply _)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ComputersDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProv
def discontinued = column[Option[Date]]("DISCONTINUED")
def companyId = column[Option[Long]]("COMPANY_ID")

def * = (id.?, name, introduced, discontinued, companyId) <> ((Computer.apply).tupled, Computer.unapply _)
def * = (id.?, name, introduced, discontinued, companyId) <> (Computer.tupled, Computer.unapply _)
}

private val computers = TableQuery[Computers]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ case class Page[A](items: Seq[A], page: Int, offset: Long, total: Long) {
}

case class Company(id: Option[Long], name: String)
object Company {
def unapply(c: Company): Option[(Option[Long], String)] = Some((c.id, c.name))
def tupled = (this.apply _).tupled
}

case class Computer(id: Option[Long] = None, name: String, introduced: Option[Date] = None, discontinued: Option[Date] = None, companyId: Option[Long] = None)
case class Computer(id: Option[Long] = None, name: String, introduced: Option[Date] = None, discontinued: Option[Date] = None, companyId: Option[Long] = None)
object Computer {
def unapply(c: Computer): Option[(Option[Long], String, Option[Date], Option[Date], Option[Long])] = Some((c.id, c.name, c.introduced, c.discontinued, c.companyId))
def tupled = (this.apply _).tupled
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@import helper._

@implicitFieldConstructor: FieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) }

@main {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@import helper._

@implicitFieldConstructor: FieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) }

@main {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PersonController @Inject()(repo: PersonRepository,
mapping(
"name" -> nonEmptyText,
"age" -> number.verifying(min(0), max(140))
)(CreatePersonForm.apply)(cpf => Some(cpf.name, cpf.age))
)(CreatePersonForm.apply)(CreatePersonForm.unapply)
}

/**
Expand Down Expand Up @@ -76,3 +76,7 @@ class PersonController @Inject()(repo: PersonRepository,
* that is generated once it's created.
*/
case class CreatePersonForm(name: String, age: Int)
object CreatePersonForm {
def unapply(cpf: CreatePersonForm): Option[(String, Int)] = Some((cpf.name, cpf.age))
def tupled = (this.apply _).tupled
}

0 comments on commit 3d48198

Please sign in to comment.