ScalaQuery (see the note about "slick" at the bottom) can do the simple:
for{
a <- Article
if a.dateCreated between(start, end)
_ <- Query groupBy a.reporterID orderBy a.dateCreated.desc
} yield(a)
or the arbitrarily complex via composition:
val team = for{
t <- Team
s <- School if t.schoolID is s.id
} yield (t,s)
val player = for{
r <- Roster
p <- Player if r.playerID is p.id
} yield (r, p)
val playerDetail = for{
(r, p) <- player
} yield (p.id, p.firstName, p.lastName, r.jerseyID, r.position, r.gamesPlayed)
val scoring = for{
(r, p) <- player
s <- Scoring if p.id is s.playerID
detail <- playerDetail
} yield (r, p, s, detail)
val scoringDetail = for{
(r, p, s, detail) <- scoring
val (total, goals, assists) =
(s.playerID.count, s.goal.sum, (s.assist1.sum + s.assist2.sum))
val ppg = (s.playerID.count / r.gamesPlayed)
} yield (goals, assists, total, ppg)
Here's how to get team stats (could modify for league or single player view):
val forScoring = for{
start ~ end ~ teamID <- Parameters[JodaTime,JodaTime,Int]
(r,p,s,player) <- scoring if r.teamID is teamID
comp <- bindDate(start, end) if s.gameID is comp.id
(goals, assists, total, ppg) <- scoringDetail
_ <- Query groupBy p.id orderBy ( ppg.desc, total.asc, goals.desc )
} yield (player, goals, assists, total, ppg)
def getScoring(start: JodaTime, end: JodaTime, id: Int): List[TeamScoring] = {
forScoring(start, end, id).list
}
I did not think it would be possible to generate strongly typed complex queries in Scala, and had resigned myself to just porting around tried & true hand written SQL; that is, until I came across ScalaQuery, which has been a revelation, much like the Scala language itself.
Anyway, you have options, Squeryl may be more in-line with SQL Alchemy, don't know, explore a bit, you'll likely not be disappointed, there is so much Scala goodness on offer, it's hard not to feel giddy in the here, now, and after ;-)
p.s. a great talk by Zeiger and Vogt at Scala Days Skills Matters on SLICK, the next evolution of ScalaQuery