diff --git a/src/main/scala/model/BaseTable.scala b/src/main/scala/model/BaseTable.scala deleted file mode 100644 index ebe986d..0000000 --- a/src/main/scala/model/BaseTable.scala +++ /dev/null @@ -1,15 +0,0 @@ -package model - -import scala.slick.driver.H2Driver.simple._ - -protected[model] abstract class BaseTable[T](_tableName: String) extends Table[T](_tableName) { - def userName = column[String]("USER_NAME") - def repositoryName = column[String]("REPOSITORY_NAME") - def base = userName ~ repositoryName - - def repository(owner: String, repository: String) = - (userName is owner.bind) && (repositoryName is repository.bind) - - def repository(other: BaseTable[T]) = - (userName is other.userName) && (repositoryName is other.repositoryName) -} diff --git a/src/main/scala/model/BasicTemplate.scala b/src/main/scala/model/BasicTemplate.scala new file mode 100644 index 0000000..971a5db --- /dev/null +++ b/src/main/scala/model/BasicTemplate.scala @@ -0,0 +1,34 @@ +package model + +import scala.slick.driver.H2Driver.simple._ + +protected[model] trait BasicTemplate { self: Table[_] => + def userName = column[String]("USER_NAME") + def repositoryName = column[String]("REPOSITORY_NAME") + + def byRepository(owner: String, repository: String) = + (userName is owner.bind) && (repositoryName is repository.bind) + + def byRepository(userName: Column[String], repositoryName: Column[String]) = + (this.userName is userName) && (this.repositoryName is repositoryName) +} + +protected[model] trait IssueTemplate extends BasicTemplate { self: Table[_] => + def issueId = column[Int]("ISSUE_ID") + + def byIssue(owner: String, repository: String, issueId: Int) = + byRepository(owner, repository) && (this.issueId is issueId.bind) + + def byIssue(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = + byRepository(userName, repositoryName) && (this.issueId is issueId) +} + +protected[model] trait LabelTemplate extends BasicTemplate { self: Table[_] => + def labelId = column[Int]("LABEL_ID") + + def byLabel(owner: String, repository: String, labelId: Int) = + byRepository(owner, repository) && (this.labelId is labelId.bind) + + def byLabel(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = + byRepository(userName, repositoryName) && (this.labelId is labelId) +} \ No newline at end of file diff --git a/src/main/scala/model/Collaborator.scala b/src/main/scala/model/Collaborator.scala index 644e775..0232365 100644 --- a/src/main/scala/model/Collaborator.scala +++ b/src/main/scala/model/Collaborator.scala @@ -1,11 +1,10 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object Collaborators extends Table[Collaborator]("COLLABORATOR") { +object Collaborators extends Table[Collaborator]("COLLABORATOR") with BasicTemplate { def collaboratorName = column[String]("COLLABORATOR_NAME") - def * = base ~ collaboratorName <> (Collaborator, Collaborator.unapply _) + def * = userName ~ repositoryName ~ collaboratorName <> (Collaborator, Collaborator.unapply _) } case class Collaborator( diff --git a/src/main/scala/model/Issue.scala b/src/main/scala/model/Issue.scala index 5de5312..402fce7 100644 --- a/src/main/scala/model/Issue.scala +++ b/src/main/scala/model/Issue.scala @@ -1,15 +1,12 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object IssueId extends Table[(String, String, Int)]("ISSUE_ID") { - def issueId = column[Int]("ISSUE_ID") - def * = base ~ issueId +object IssueId extends Table[(String, String, Int)]("ISSUE_ID") with IssueTemplate { + def * = userName ~ repositoryName ~ issueId } -object Issues extends Table[Issue]("ISSUE") with Functions { - def issueId = column[Int]("ISSUE_ID") +object Issues extends Table[Issue]("ISSUE") with IssueTemplate with Functions { def openedUserName = column[String]("OPENED_USER_NAME") def milestoneId = column[Int]("MILESTONE_ID") def assignedUserName = column[String]("ASSIGNED_USER_NAME") @@ -18,7 +15,7 @@ def closed = column[Boolean]("CLOSED") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = base ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _) + def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _) } case class Issue( diff --git a/src/main/scala/model/IssueComment.scala b/src/main/scala/model/IssueComment.scala index a3c5c50..38beae6 100644 --- a/src/main/scala/model/IssueComment.scala +++ b/src/main/scala/model/IssueComment.scala @@ -1,18 +1,16 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with Functions { - def issueId = column[Int]("ISSUE_ID") +object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with IssueTemplate with Functions { def commentId = column[Int]("COMMENT_ID", O AutoInc) def commentedUserName = column[String]("COMMENTED_USER_NAME") def content = column[String]("CONTENT") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = base ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _) + def * = userName ~ repositoryName ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _) - def autoInc = base ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId + def autoInc = userName ~ repositoryName ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId } case class IssueComment( diff --git a/src/main/scala/model/IssueLabels.scala b/src/main/scala/model/IssueLabels.scala index db27dda..16a7469 100644 --- a/src/main/scala/model/IssueLabels.scala +++ b/src/main/scala/model/IssueLabels.scala @@ -1,12 +1,9 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") { - def issueId = column[Int]("ISSUE_ID") - def labelId = column[Int]("LABEL_ID") - def * = base ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _) +object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") with IssueTemplate with LabelTemplate { + def * = userName ~ repositoryName ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _) } case class IssueLabel( diff --git a/src/main/scala/model/Labels.scala b/src/main/scala/model/Labels.scala index e5b66f2..188af73 100644 --- a/src/main/scala/model/Labels.scala +++ b/src/main/scala/model/Labels.scala @@ -1,14 +1,13 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object Labels extends Table[Label]("LABEL") { - def labelId = column[Int]("LABEL_ID", O AutoInc) +object Labels extends Table[Label]("LABEL") with LabelTemplate { def labelName = column[String]("LABEL_NAME") def color = column[String]("COLOR") - def * = base ~ labelId ~ labelName ~ color <> (Label, Label.unapply _) - def ins = base ~ labelName ~ color + def * = userName ~ repositoryName ~ labelId ~ labelName ~ color <> (Label, Label.unapply _) + + def ins = userName ~ repositoryName ~ labelName ~ color } case class Label( diff --git a/src/main/scala/model/Milestone.scala b/src/main/scala/model/Milestone.scala index 048dbba..334b014 100644 --- a/src/main/scala/model/Milestone.scala +++ b/src/main/scala/model/Milestone.scala @@ -1,17 +1,16 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object Milestones extends Table[Milestone]("MILESTONE") with Functions { +object Milestones extends Table[Milestone]("MILESTONE") with BasicTemplate with Functions { def milestoneId = column[Int]("MILESTONE_ID", O AutoInc) def title = column[String]("TITLE") def description = column[String]("DESCRIPTION") def dueDate = column[java.util.Date]("DUE_DATE") def closedDate = column[java.util.Date]("CLOSED_DATE") - def * = base ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _) + def * = userName ~ repositoryName ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _) - def autoInc = base ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId + def autoInc = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId } case class Milestone( diff --git a/src/main/scala/model/Repository.scala b/src/main/scala/model/Repository.scala index 3408ca8..0ef8a0a 100644 --- a/src/main/scala/model/Repository.scala +++ b/src/main/scala/model/Repository.scala @@ -1,16 +1,15 @@ package model import scala.slick.driver.H2Driver.simple._ -import model.{BaseTable => Table} -object Repositories extends Table[Repository]("REPOSITORY") with Functions { +object Repositories extends Table[Repository]("REPOSITORY") with BasicTemplate with Functions { def isPrivate = column[Boolean]("PRIVATE") def description = column[String]("DESCRIPTION") def defaultBranch = column[String]("DEFAULT_BRANCH") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") def lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE") - def * = base ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) + def * = userName ~ repositoryName ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) } case class Repository(