Last active
August 29, 2015 14:06
-
-
Save lanceon/b2f921af19078448cb6b to your computer and use it in GitHub Desktop.
Slick projections/mappings
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
case class Emp(id: Long, | |
firstName: Option[String], | |
lastName: Option[String]) | |
case class EmpProj(id: Column[Long], | |
firstName: Column[Option[String]], | |
lastName: Column[Option[String]]) | |
implicit object EmpShape extends CaseClassShape(EmpProj.tupled, Emp.tupled) | |
class EmpTable(tag: Tag) extends Table[Emp](tag, "EMPLOYEE") { | |
val id = column[Long]("ID", O.AutoInc, O.PrimaryKey) | |
val firstName = column[Option[String]]("FIRSTNAME", O.Length(64,varying=true)) | |
val lastName = column[Option[String]]("LASTNAME", O.Length(32,varying=true))) | |
def projection = EmpProj(id, firstName, lastName) | |
override def * = projection | |
} | |
lazy val employees = TableQuery[EmpTable].map(_.projection) | |
employees.map{ case (id, first, last) => (first, last) }.list.map{ case (firstOption, lastOption) => ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment