Created
August 19, 2015 14:34
-
-
Save cheptsov/9a8ab33de5d6d6de09d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package models | |
import java.sql.Timestamp | |
import javax.inject.{Inject, Singleton} | |
import play.api.db.slick.{HasDatabaseConfigProvider, DatabaseConfigProvider} | |
import slick.driver.JdbcProfile | |
case class Topic(id: Long = 0, groupId: Long, userId: Long, date: Timestamp, text: String) extends AbstractGroupMessage | |
@Singleton() | |
class TopicsDAO @Inject()(val dbConfigProvider: DatabaseConfigProvider, val groupsDAO: GroupsDAO, val usersDAO: UsersDAO) | |
extends HasDatabaseConfigProvider[JdbcProfile] { | |
import driver.api._ | |
val groups = TableQuery[groupsDAO.GroupsTable] | |
val users = TableQuery[usersDAO.UsersTable] | |
class TopicsTable(tag: Tag) extends Table[Topic](tag, "topics") { | |
def id = column[Long]("id", O.PrimaryKey, O.AutoInc) | |
def groupId = column[Long]("group_id") | |
def userId = column[Long]("user_id") | |
def date = column[Timestamp]("date") | |
def text = column[String]("text", O.SqlType("text")) | |
def group = foreignKey("topic_group_fk", groupId, groups)(_.id) | |
def user = foreignKey("topic_user_fk", userId, users)(_.id) | |
def * = (id, groupId, userId, date, text) <>(Topic.tupled, Topic.unapply) | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment