Commits

Joachim Hofer committed 8f75bf2

based tables on case classes instead of tuples

  • Participants
  • Parent commits 5e9d8b1

Comments (0)

Files changed (3)

File app/models/Bots.scala

   def asJson = Seq(toJson(id), toJson(name), toJson(author), toJson(version))
 }
 
+case class RawBot(id: Long, name: String, authorId: Long, version: String)
+
 object Bots {
   import util.database
   import util.extendedProfile.Implicit._
 
-  object Table extends Table[(Long, String, Long, String)]("bots") {
+  object Table extends Table[RawBot]("bots") {
     def id = column[Long]("id", O PrimaryKey, O AutoInc)
     def name = column[String]("name", O NotNull)
     def authorId = column[Long]("authorId", O NotNull)
 
     def author = foreignKey("authorFK", authorId, Users.Table)(_.id)
     
-    def * = id ~ name ~ authorId ~ version
+    def * = id ~ name ~ authorId ~ version <> (RawBot, RawBot unapply _)
   }
   
   def findAll : List[Bot] = database withSession { implicit db: Session =>

File app/models/Groups.scala

   import util.database
   import util.extendedProfile.Implicit._
 
-  object Table extends Table[(Long, String)]("groups") {
+  object Table extends Table[Group]("groups") {
     def id = column[Long]("id", O PrimaryKey, O AutoInc)
     def name = column[String]("name", O NotNull)
-    def * = id ~ name
+    def * = id ~ name <> (Group, Group unapply _)
   }
   
   def findAll : List[Group] = database withSession { implicit db: Session =>
-    (for (group <- Table) yield group.*).list map Group.tupled
+    (for (group <- Table) yield group.*).list
   }
 }

File app/models/Users.scala

 import org.scalaquery.ql.extended.ExtendedProfile
 import org.scalaquery.session._
 
+case class RawUser(id: Long, nick: String, password: String, groupId: Long)
+
 case class User(id: Long, nick: String, password: String, group: String) {
   import play.api.libs.json.Json._
 
   def asJson = Seq(toJson(id), toJson(nick), toJson(password), toJson(group))
 }
 
+case class AuthenticatedUser(nick: String, group: Option[String])
+
 object Users {
   import util.database
   import util.extendedProfile.Implicit._
 
-  object Table extends Table[(Long, String, String, Long)]("users") {
+  object Table extends Table[RawUser]("users") {
     def id = column[Long]("id", O PrimaryKey, O AutoInc)
     def nick = column[String]("nick", O NotNull)
     def password = column[String]("password", O NotNull)
 
     def group = foreignKey("groupFK", groupId, Groups.Table)(_.id)
 
-    def * = id ~ nick ~ password ~ groupId
+    def * = id ~ nick ~ password ~ groupId <> (RawUser, RawUser.unapply _)
   }
 
   def findAll : List[User] = database withSession { implicit db: Session =>