Cameleon2: DBForge

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
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 contains an example in the directory src/dbforge/example. You will find several files.
Makefile is the file used to compile with make.
base.xml is the file containing the schema. It can be edited with the graphical interface, launched by the following command:
dbforge2.gui.{x,byte} base.xmlThe OCaml code is generated from this file with the follownig command:
dbforge2.{x,byte} -o base.ml base.xmlThe file base.ml then contains the generated OCaml code. This code uses two modules installed with Cameleon2: Dbf_sql_driver and Dbf_sql_misc. You can get the module interface of the generated file with the following command:
ocamlc -I +cameleon2 -i base.ml > base.mli
The generated code is composed of functers, one per table and one more for the additional queries defined in the schema. These functers 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 Dbf_mysql whose source is installed with Cameleon2. Since it needs the OCaml-MySQL library to be installed, this module is not compiled when Cameleon2 is installed, but must be compiled by the application which uses it. This module has the type Dbf_sql_driver.SqlDriver and can therefore be passed in parameter to the functers of the generated code in file base.ml. The modules obtained then offer the functions to access the database.
To complete...
Cameleon2: DBForge
