paurkedal / ocaml-caqti

Cooperative-threaded access to relational data
https://paurkedal.github.io/ocaml-caqti/index.html
GNU Lesser General Public License v3.0
309 stars 36 forks source link

Use the postgresql driver when postgres is specified as the URI schema #25

Closed leamingrad closed 5 years ago

leamingrad commented 5 years ago

This is a small PR to fix an issue that has been causing us a bit of trouble when trying to use caqti.

In the postgres documentation here it states that valid postgres URIs can use either the postgresql or postgres scheme. It seems like the postgres scheme is quite common, for example when deploying to heroku.

The fix here is to handle the special case when resolving the driver name at connect time, and for the caqti-driver-postgresql library to register itself for both schemes.

I would be interested in your thoughts/feedback on this, including whether registering the driver twice is indeed the right approach - it is definitely the simplest, but there might be a nicer way.

paurkedal commented 5 years ago

Looks good. (Registering twice is okay, since it's just a Hashtbl entry. One could add an ?aliases argument to the registration function, but it would do the same thing. The scheme translation breaks the idea that drivers should be fully definable from external packages, but I don't see a simple solution, so let's stick with it.)

Can you tweak your PR a bit before I merge?:

leamingrad commented 5 years ago

Made the changes above - I didn't raise an issue for this so I don't have a number, but I'm happy to raise one and reference it if you would like.

paurkedal commented 5 years ago

Looks good, thanks!