Running transactions in caqti with Dream and Rapper?

The second argument of Dream.sql is Caqti_lwt.connection -> 'a promise, and Caqti_lwt.connection is defined as type connection = (module CONNECTION) wich means it’s actually the module you need to run your transaction.
So if you unpack the module in the signature of your function, you’ll have all you need:

let f ((module DB : Caqti_lwt.CONNECTION) as connection) =

So now you can use the DB module to access with_transaction, start, commit, rollback or use the connection variable if you need to pass the argument to another function.

1 Like