Hi, I am writing an orm-lib for OCaml based on Caqti as a coursework.
Using the preprocessor, I generate modules with methods for working with the db for the each marked first-class module. Like https://github.com/Tozarin/mrm/tree/dev (it is a little outdated) but with a state monad and subqueries like https://github.com/mirage/orm.
The lib allows write type-safe code if use the right entry point (connection function) and do not copy it. I support basic types, tuples, records, lists, one-to-many, many-to-many and user-defined types but with user’s decoder and encoder form/to string.
Maybe in your opinion there are features besides these that should be, or some thoughts on the concept.
I’ve been toying with the idea too of building on top of the prisma ecosystem from nodejs to generate an ocaml orm.
Others have done it for Go and Rust
Looking at the implementations for languages, does it turn out to be some kind of tool that generates code according to the scheme described by the user?
If this is the case, then on the one hand it would be cool to use a ready-made solution that just needs to be adapted, and on the other hand, the seamless experience for the user is lost.
It turns out a trade-off between performance (of course, prisma is better at this) and comfort for the user, who in my version just needs to add deriving.
Prisma’s from the user’s pov is just a cli tool and a specialized schema. It’s quite nice to reuse all the Prisma tooling.
Prisma also has an underlying Rust engine that parses some DSL into sql and adapts itself to a variety of databases. I would say it’d be a good familiar tool for those coming from the typescript world.
I actually think they only just figured out how to generate joins lol, so likely not the best performance for sql, but it offers a really nice API, assuming I can generate the correct ocaml code. Not all too easy to adapt though.
I would think deriving is easiest, as is the common pattern in other ocaml sql libs.