12 ms·
Very cool, does it compose? Some statically typed languages allow you to build up composable query snippets along the lines of (from a Scala DSL): val acc
by virtualwhys 8y ago
Very cool, does it compose?
Some statically typed languages allow you to build up composable query snippets along the lines of (from a Scala DSL):
val accountQ = for {
(a, t) <- Account leftJoin Transaction (_.id is _.accountId)
if a.id is ... && t.userId ...
groupBy a.id
} yield (a, t.id, t.amount.sum, ...)
val invoiceQ = for {
(a, transId, total) <- accountQ
i <- Invoice join (_.transId is transId)
} yield (a, i, total)
Basically you can build up arbitrarily complex queries, all compile time checked -- it's really quite wonderful. Haskell has something similar with Esqueleto and C#/F# has LINQ to SQL.
I love query DSLs, the more we move away from string-y SQL the better :)
- elcritch 8y agoEcto is pretty composeable [1]. Having a compile time checked SQL DSL was always one of the biggest features I wanted back in my Java days. 1: https://elixirschool.com/blog/ecto-query-composition/ https://elixirschool.com/blog/ecto-query-composition/