DBForge is a tool to describe database schemas and generate OCaml code to access these databases.
The idea of the tool is based on the following problem: The creation of functions executing SQL queries
selectqueries) into the correct OCaml type,
To solve these problems, we want to
To do so, we must have the following information about each colum of each table:
The list of tables with the above information for each column is what we call the database schema.
The DBForge tool allows to edit such a schema in a graphical user interface, and generates the corresponding OCaml code. The user can also define SQL queries to be embedded in OCaml functions in the generared code. For now, only "select" and "union" queries are accepted.
The distribution archive contains an example in the directory
You will find several files.
Makefile is the file used to compile with
base.xml is the file containing the schema. It can be edited with the graphical
interface, launched by the following command:
The OCaml code is generated from this file with the follownig command:
dbforge[.byte] -o base.ml base.xml
base.ml then contains the generated OCaml code. This code uses two modules
installed with DBForge: Dbf_sql_driver and Dbf_sql_misc.
You can get the module interface of the generated file with the following command:
ocamlfind ocamlc -package dbforge.mysql -i base.ml > base.mli
The generated code is composed of functors, one per table and one more
for the additional queries defined in the schema. These functors take in
parameter a module of type
Dbf_sql_driver.SqlDriver, which allows to abstract
the underlying database system, by providing a common interface.
example.ml is the main file of the example. It uses the module
compiled and installed with DBForge. This module has the type
can therefore be passed in parameter to the functors of the generated code in
The modules obtained then offer the functions to access the database.
DBForge is hosted on Github.
DBForge requires the following libraries to be installed:
To compile and install:
This will install the following findlib packages:
dbforge, dbforge.gtk, dbforge.sql, dbforge.mysql and sqml
dbforge-gtk[.byte]) will be installed in
ocaml bin directory.
<Maxence 'DOT' Guesdon 'AT' inria 'DOT' fr>with Pierre-Yves Strub and Nadji Gauthier.