caseyjmorton/crakken — pull request #1 by bkyrlach (2014-03-15 00:01:18+00:00)
Title: First attempt at removing duplication...

Several undesirables here.

1) Table objects are instantiated by the TableQuery method every time. Because there's no way of enforcing a specific constructor to be available at compile time through generic constraints, this means that I have to have a ModelHelper implicit for each table. While this is still less coding burden than before, it's undesirable.

2) For "gets" and "deletes", the method arguments aren't enough for Scala's type inference to figure out what the entity and table types are. This yields some type noise for those two operations that should otherwise be perfectly avoidable.

3) Generlization "in general" for this use case is actually a little more limiting than one might expect up front. Specifically...

a) Objects in the domain don't specify any contract as to what kind of (or even if they have an)
ID. A lot of the "duplicate" code made use of the ID field, despite there being no common
access.

b) Case class copy methods are generated by the compiler. This means that expressions of the form
--> entity.copy(id = newId) <--
can never be compile time guaranteed under a generic setting. For this, I resorted to utilizing
scalaz lenses, but this adds another source of code "duplication".

c) Due to the fact that Table classes don't really clearly define their relationship to model
classes (remembering that the generic type parameter is not available at runtime), it makes
it more challenging to correctly associate the model with the related table object.

All in all, I believe that this still reduces the code duplication significantly, but I'm still
hunting for better solutions.