Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.22 KB | None | 0 0
  1. package models.database
  2.  
  3. import play.api.db.slick.Config.driver.simple._
  4. import com.github.tototoshi.slick.H2JodaSupport._
  5. import models.{ClientTag, Client}
  6. import org.joda.time.DateTime
  7. import scala.slick.model.ForeignKeyAction
  8.  
  9. /**
  10.  * Created by ed on 4/15/14.
  11.  */
  12. class Clients(tag: Tag) extends Table[Client](tag, "clients") {
  13.   def id        = column[Long]      ("id",        O.PrimaryKey,   O.AutoInc)
  14.   def host      = column[String]    ("host")
  15.   def accessKey = column[String]    ("access_key")
  16.   def createdOn = column[DateTime]  ("created_on")
  17.   def expiresOn = column[DateTime]  ("expires_on")
  18.  
  19.   def * = (id.?, host, accessKey, createdOn, expiresOn) <> (Client.tupled, Client.unapply _)
  20.  
  21.   def hostIdx   = index("clients_idx_host", host)
  22. }
  23.  
  24. class ClientTags(tag: Tag) extends Table[ClientTag](tag, "client_tags") {
  25.   def clientId  = column[Long]      ("client_id")
  26.   def tagName   = column[String]    ("tag_name")
  27.  
  28.   def client    = foreignKey("fk_clients", clientId, DAO.clients)(_.id, onDelete = ForeignKeyAction.Cascade)
  29.  
  30.   def * = (clientId, tagName) <> (ClientTag.tupled, ClientTag.unapply _)
  31. }
  32.  
  33. object DAO {
  34.   lazy val clients = TableQuery[Clients]
  35.   lazy val clientTags = TableQuery[ClientTags]
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement