scala slick and sub-selects for max value
I am learning slick. A bit of tough road initially. The blogs and other posts out there really help. Thistutorial was especially helpful.
My domain was storing note objects in database and tracking revisions. Here's the table structure:
There are more enhancements needed for this table, but you get the gist.
So we can query the table for a specific document id and obtain the latest document:
But if we want to find it using just the timestamp, the first thing you can do is issue 2 queries:
But we would like to avoid issuing 2 queries because then we need a Session object. We want more of a query:
and that's what we wanted.
Of course, if we want to update a Note's latest flag, we do need to run 2 queries and hence need a session:
This is on gisthub: gisthub