Database library for writing queries 2021

The last topic I found was from 2017 Databases and OCaml

What DB library do you use for writing queries?

I really liked GitHub - roddyyaga/ppx_rapper: Syntax extension for writing SQL in OCaml because

  • it uses SQL and is not a query builder. I don’t get query builders - SQL is portable across programming languages, why bother with some new API?
  • it is simple to use and covered my initial cases

but I reached a point where either it’s not possible, or I don’t see how to handle all of my new use cases (Issues · roddyyaga/ppx_rapper · GitHub):

  • insert multiple rows
  • create a table with a dynamic name
  • represent some postgres queries

I noticed that some of these are documented in GitHub - issuu/ppx_mysql: ppx_mysql , but the caveat is that it’s mysql, which while an option would be a second choice

Is there any simple query library (preferably postgres), that is used in prod and is documented?

3 Likes

If you want to write raw SQL, you can use Postgresql-ocaml. It also supports cursors, listen / notify etc. and is definitively ready for production. If you need a Lwt-wrapper, there is Ezpostgresql.

1 Like

I often use ocaml-caqti and ppx_rapper for PostgreSQL, have you checked that combination?