Optional table projections or can/should we automate stuff?

60 views
Skip to first unread message

Pedro Furlanetto

unread,
Apr 8, 2014, 11:13:41 PM4/8/14
to scala...@googlegroups.com
Hello All,

I stumbled today with this little query:

val x4 = (for {
    (c,e) <- Company leftJoin Employee on (_.id === _.companyId)
  } yield (c,e.?))  


It's all cool since the auto-generated tables - in this case Employee - gives us the following (irrelevant parts removed):

def * = (id, name, phone, companyId) <> (EmployeeRow.tupled, EmployeeRow.unapply)
def ? = (id.?, name.?, phone.?, companyId.?).shaped.<>({r=>import r._; _1.map(_=> EmployeeRow.tupled((_1.get, _2.get, _3.get, _4.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))

But let's consider the case where I am hand writing my tables (personally, I do prefer that). And to make matters even worst let's say we had ten or more columns. And to make it even worst let's say we are in work-in-progress project where fields are changed, added, removed often. It's extremely tedious to keep fixing these projections on both places.

Can't we use the Shapes packing, unpacking, linearization etc facilities to abstract over that and use this abstraction create a Table.? for us?

If the Shapes transformations isn't easy or possible, I am pretty sure we can easily come out with a solution based on Shapeless (sounds like a pun, but I am Miles Sabin's Shapeless :)) Other approach are macros. 

Done these abstractions, wouldn't it also be feasible to end up with a `leftJoin_?` that already provides use with a Option[Projection] of the RHS of the join?

Well, consider this email a call for ideas and discussion around the subject.

And to don't lose the trip: best regards to Slick team and their great simplified API on Slick2, it's been a pleasure digging its guts and it's much easier to find my ways around in the sources now.

Cheers,
Pedro

    

 

Marc Siegel

unread,
Apr 16, 2014, 10:58:29 AM4/16/14
to scala...@googlegroups.com
+1
Reply all
Reply to author
Forward
0 new messages