KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having some trouble composing different query components into a single Query. My goal is to create a set of traits (e.g. SoftDeletable, HasName, SortedByName, WithTimestamps) that I can simply mix-in to Table objects to add that behavior. The ideal would look like: abstract class BaseModel[Tuple <: Product,CaseClass](tableName: String) extends Table[Tuple](tableName) { def id = column[Int]("id", O.AutoInc, O.PrimaryKey) def mapped: MappedProjection[CaseClass, TupleClass] def allQuery = this.map(_.mapped) final def all = database.withSession { implicit session: Session => allQuery.list() } ... } trait SoftDeletable[Tuple <: Product, CaseClass] extends BaseModel[Tuple,CaseClass] { def isActive = column[String]("is_active") def * = super.* ~ isActive def allQuery = /* here, I'd like to compose super.allQuery with a filter that returns rows where isActive is true */ } trait HasName[Tuple <: Product] extends Table[Tuple] { def name = column[String]("name") def * = super.* ~ name } trait SortedByName[Tuple <: Product] extends HasName[Tuple { override def allQuery = super.allQuery /* compose somehow with (_ <- Query orderBy name */ } Can I do these kinds of things with ScalaQuery? The main sticking points are: How do I cleanly compose the filters in SoftDeletable.allQuery and the sort in SortedByName.allQuery with BaseModel.allQuery ? By adding columns in subclass implementations of the * method, the tuple type parameter to Table no latter matches - is there a way for these traits to incrementally add new types to the columns tuple in the ultimate concrete class? (I don't expect there to be, but it would be nice if there was something I'm missing). I need to repeat the long tuple de
Tags (comma-separated)
Save Edits
Cancel