Database modelling

I have written a first draft of an Ocaml library, or utility, that generates–writes–modules and types based upon database tables and fields. The modules should be in a form ready to serve as part of the input to the ocaml compiler as part of any other project. The benefits are saved time when dealing with many tables or fields, and accuracy since types are generated at compile time programmatic-ally. Changes to the tables or fields would also not require time spent making matching changes to individual modules.

So far I only support mysql but would like to extend support to postgres. I also prefer to use Core, but some people I’m sure do not. The code is ugly, some of it intentionally so that the output is pretty. I threw in some additional functions I found useful and got tired of writing over and over and over again when dealing with many tables. Ideally this would fit into the build sequence of other projects that have lots of tables that need to be available. How exactly that would work still needs to be ironed out. See for example, the Jooq project in Java, and many other such projects I’m sure, for the kind of functionality I am ultimately striving.

If anyone finds it useful, has suggestions, or wants to contribute, please do so. Pull requests welcome.

3 Likes

And a version for postgresql:

3 Likes