Thanks for the idea Adam.
Personally I steer well clear of views for anything but read-only data.
Something I've learned from enterprise systems: When you look at
databases it's always good to make a split between operational and
statistical data, where operational data is typically data against
which you would do your normal CRUD operations. Statistical data is
usually processed to the point where the data is normalised
(flattened) and you know that the data is either valid, or invalid,
e.g. tables showing accounts that balance (everything's ok) and tables
that show accounts that does not balance (something went nutty).
Statistical data would be read-only from a user perspective.
For operational data you want the logic (as far as possible) to remain
under control of your software. You want to centralise your business
logic as far as possible. This also makes it possible to move between
databases more readily.
The way I see Slick queries, and I may be wrong here, is that the
whole idea behind Slick queries is that complex queries can be
composed out of simple queries. That way you will keep your logic
manageable, as shown in this example (from
http://slick.typesafe.com/talks/2012-10-17_Typesafe-Slick-presentation-at-BASE/2012-10-17_Typesafe-Slick-presentation-at-BASE.pdf).
def personByAge( from:Int, to:Int ) =
Persons.filter( p => p.age >= from && p.age <= to )
// Interests of people between 20 and 25
for( p <- personByAge(20, 25); i <- Interests; if i.personId ===
p.id) yield i.text
// Cars of people between 55 and 65
for( p <- personByAge(55, 65); c <- Cars; if c.personId ===
p.id) yield c.model
You will notice that personByAge is re-used in other queries. This
works because Slick makes a manageable distinction between query
creation and query execution. As a matter of fact, composable queries
the single feature of Slick that won me over - it gives you a way to
divide and conquer your database problems, and to re-use tried and
tested queries inside other queries (something that would otherwise be
done as stored procedures).
Kind regards,
Jacobus