I'm looking for a library for interacting with a database (postgres,
in
particular). I've found several options but none seem to contain
functions
that would convert query results that are returned as lists of strings
to
the appropriate ocaml types.
For instance, if I have a module that looks vaguely like this:
-----Database.mli----------
(* the kinds of data supported by the database *)
type field_t =
SQL_INT
SQL_FLOAT
(* etc... *)
(* a single entry in a "table" of returned values in response
to a query, with a string representation of the value and
what type of data it is *)
type result_cell_t = string * field_t
(* pass in a string of sql, get a matrix of results *)
val: query_the_database: query:string -> result_cell_t list list
-----/Database.mli--------------
Now, what I'm hoping is that somewhere is a library that
also has the ugly unsafe conversion functions to ocaml types for
each field_t. For example the sig and struct entries for converting
an SQL_INT to an int:
val result_cell_to_int: result_cell_t -> int
let result_cell_to_int cell =
match cell with
|(str, SQL_INT) -> int_of_string str
|_ -> failwith "wrong type"
Unless I'm missing some obviously better way, everyone who uses a
database
with ocaml must be writing some form of these functions for
themselves.
I did see PGOcaml, which attempts to deal with this issue, but it's
requirement
of a live database at compile time wouldn't work well for the way I do
testing.
Any pointers or advice would be appreciated.
-Peter