3 ms·
Honestly none of the statically typed sql generators (Opaleye included) really tick all the boxes; all are lacking in one way or another. Here's a breakdown of
by virtualwhys 11y ago
Honestly none of the statically typed sql generators (Opaleye included) really tick all the boxes; all are lacking in one way or another.
Here's a breakdown of the leaders of the pack on this front[0]
Haskell
1) Opaleye[1]: composable and prevents invalid sql, but no join support (simulated via sub selects), Postgres only, and tough syntax to parse.
2) Esqueleto[2]: composable, readable, supports joins, but Postgres only, and the DSL can't/doesn't prevent invalid sql (which is, IIRC, one of the reasons why Opaleye came into being).
Scala
1) Slick[3] myriad databases supported (Oracle and SQL Server require non-free license), join support, fully composable (really, king of monad hill), and elegant syntax (until you `groupBy`/`sortBy` and then enter unreadble tuple_.1, tuple._N soup). Also, grouping requires flattening result set via min, max, sum, etc. aggregate function so not possible to return tuple representing say, a User, when grouping. Suggested workaround is to group on the client (and send a million rows over the wire to app server, ok o_O).
2) Squeryl[4] myriad databases supported (all free), join support, sql-like syntax, but lacks compositionality of aforementioned and relies on runtime reflection to make the DSL go.
Microsoft
LINQ to SQL/Objects myriad databases supported (not sure of driver licensing), excellent sql-like syntax, and type providers straight other worldly, but lacks compositionality and is tied to Windows (until *nix support lands).
[0] There are likely (many) others but these are the statically typed ones I'm aware of. Feel free to add others, curious to see what's out there (e.g. OCaml must have something)
[1] https://github.com/tomjaguarpaw/haskell-opaleye https://github.com/tomjaguarpaw/haskell-opaleye
[2] https://github.com/prowdsponsor/esqueleto https://github.com/prowdsponsor/esqueleto
[3] https://github.com/slick/slick https://github.com/slick/slick
[4] https://github.com/squeryl/squeryl https://github.com/squeryl/squeryl
- tome 11y agoSome corrections/comments/questions: > Opaleye ... no join support (simulated via sub selects) This is true for exactly one reason: despite being raised frequently, nobody has ever been able to demonstrate any performance difference between subselects and joins (in Postgres)! As soon as someone does, they should file an issue (https://github.com/tomjaguarpaw/haskell-opaleye/issues/ https://github.com/tomjaguarpaw/haskell-opaleye/issues/) and I'll add joins forthwith. > Opaleye ... tough syntax to parse What do you mean by this? The Haskell syntax of Opaleye, or the generated SQL? > Esqueleto ... Postgres only You're incorrect about this. From your Esqueleto link: "It has many kinds of backends, such as SQL backends (persistent-mysql, persistent-postgresql, persistent-sqlite) and NoSQL backends (persistent-mongoDB)." > Esqueleto ... can't/doesn't prevent invalid sql But you're right about this.
- merb 11y agoI use slick, however I never used the elegant syntax. I always drop to the sql/sqlu and there you have a really really cool sql syntax and rowparsers