Typed Primary keys

21 views
Skip to first unread message

Brent Gracey

unread,
Jan 6, 2015, 8:38:30 AM1/6/15
to squ...@googlegroups.com

I would like to define my Primary Keys as specific types - not just Long or String

For example

case class Project(
                    var id: ProjectId = 0,

One advantage of this is if I accidently compare different keys - then the compiler will pick it up.

Obviously this gives the compile error

overriding method id in trait KeyedEntity of type => Long;
 variable id has incompatible type

Are there any example's where this type of approach is successfully implemented?

Appendix - a draft of what ProjectId could be

trait SelfType[T] {
  val self : T
}

class Content_typeId( val self: Int) extends SelfType[Int]
class ProjectId( val self: Long) extends SelfType[Long]
object ProjectId {
  implicit def baseToType(self: Long) = new ProjectId(self)
  implicit def typeToBase(higherSelf: ProjectId) : Long = higherSelf.self

}

Thanks Brent

David Whittaker

unread,
Jan 8, 2015, 11:59:14 AM1/8/15
to squ...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages