3 ms·
> First class queries is another thing that I've never seen out in the wild. It's not that complicated to add a composable layer on top of SQL to generate arbit
by karmakaze 3y ago
> First class queries is another thing that I've never seen out in the wild. It's not that complicated to add a composable layer on top of SQL to generate arbitrary queries.
I'm interpreting the post as wanting to do just that with static typing and calling it an ORM.
From TFA
> I want a query language that’s better than SQL. Specifically, it has to be 1) composable, 2) statically typed and with 3) a sane syntax.
I want sum types.
I want a statically-typed way of constructing composable queries that follow SQL rather than reinvent a different thing. It doesn't have to be the same syntax but it has to be the same structuring.
I started writing one[0] and stopped before doing all the boilerplate code generation, having moved on from the JVM ecosystem for the time being. One thing it does is treat most things like sets so we don't end up with N+1 queries. Another trick it uses is collapsing constant expressions via an expression evaluation library[1].
[0] https://github.com/karmakaze/safeql https://github.com/karmakaze/safeql
[1] https://github.com/karmakaze/moja https://github.com/karmakaze/moja
- ndriscoll 3y agoThe Scala ecosystem has a few ways to do composable type-safe query building, e.g. Slick[0] or more recently Quill[1]. I believe both also have ways to do compile-time string interpolation (e.g. sql"""select * from users where id = ${user.id}""".as[User]) which generate prepared statements (I know Slick does prepared statements. Quill appears to have a similar interpolator). [0] https://scala-slick.org/ https://scala-slick.org/ [1] https://zio.dev/zio-quill/ https://zio.dev/zio-quill/