This is an important question, one that does not have an easy answer,
AFAIK.
You can compose any query prior to invoking list, foreach, etc.
trait SortedByName[Tuple <: Product] extends HasName[Tuple {
override def allQuery =
for {
res <- super.allQuery
_ < Query orderBy name desc
} yield res
}
isActive would look like (provided isActive is Boolean):
for { res <- super.allQuery if res.isActive } yield res
@Harshad's type alias suggestion seems a good one. I have been
muddling by with case class + companion object:
case class User(
id: Int,
firstName: String,
lastName: String,
email: String,
password: String
)
object Users extends _Mapper[User]("user") {
...
}
where _Mapper just defines the id PK
I'm not sure what you gain through your attempt, however. You can do
things like:
val byBar = FooObject.createFinderBy(_.bar)
val fiveBars = byBar(someBar) take 5 // or in a for {...} compose
query as you like
In other words, there may be no need to go beyond basic DAO findAll,
findOne, create, update, etc. since we can compose any base query into
something arbitrarily complex & wonderful via for {} comprehensions --
I cannot believe the transformation in 1 project, had serious doubts
about SQ being able to handle some of the string-based queries, but to
my surprise, verbatim replication, and type safe to boot, incredible!