Advertisement
Guest User

help with bidirectional mapping

a guest
Mar 20th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.82 KB | None | 0 0
  1. package models
  2.  
  3. import scala.slick.driver.PostgresDriver.simple._
  4. import play.api.Play.current
  5.  
  6. case class LastConfiguration(id: Option[Int] = None)
  7.  
  8. class LastConfigurationTable(tag: Tag) extends Table[LastConfiguration](tag, "last_configuration") {
  9.   // Auto Increment the id primary key column
  10.   def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
  11.   // the * projection (e.g. select * ...) auto-transforms the tupled
  12.   // column values to / from a Configuration
  13.   def * = (id.?) <> (LastConfiguration.tupled, LastConfiguration.unapply)
  14. }
  15.  
  16. object LastConfigurationTable {
  17.   val db = play.api.db.slick.DB
  18.   val last_configurations = TableQuery[LastConfigurationTable]
  19.   def findLastConfiguration: LastConfiguration = db.withSession { implicit session =>
  20.     last_configurations.sortBy(_.id.asc.nullsFirst).first
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement