Boost logo

Boost :

Subject: [boost] quince: queries in C++ expressions
From: Michael Shepanski (mps_at_[hidden])
Date: 2014-07-15 02:04:21


Hello, boost!

I've released a library called "quince", which lets you use a relational
database in C++ rather than SQL. So it provides an EDSL to wrap the SQL
syntax, it converts between C++ types (including user-defined class
types) and SQL column types, and it enforces type safety at compile-time.

I wanted to ask whether there would be an interest in this for boost, so
I subscribed to this list today, and for the first time I discover
Roland Bock's sqlpp11, which does all of those things too.

First of all I'd like to say: nice work Roland! The truth is, if I had
seen sqlcpp11 earlier, I would not have had felt the need to write quince.

Nevertheless, I did write it, and so of course it has a different set of
features. The full doco is at http://quince-lib.com, but let me quickly
point out a few differences from sqlpp11.

1. If you want some class to be mapped into SQL data, quince lets you
write this sort of thing:

         struct point {
             float x;
             float y;
         };
         QUINCE_MAP_CLASS(point, (x)(y))

         extern database db;
         table<point> points(db, "points");

The macro QUINCE_MAP_CLASS uses a bit of Boost.Preprocessor magic and a
bit of template metaprogramming to produce all the statically typed
metadata that quince needs, regarding the user's type. There is no code
generation step.

2. Quince's EDSL looks somewhat different. This is my first day as a
student of sqlpp11, so I'm not really qualified to define the
distinctions, but I think part of it is that sqlpp11 exposes the concept
of column aliases, where quince does not, and quince is preoccupied with
the idea of compositionality, in a way that sqlpp11 is not (as far as I
know). Anyway you can see an example of the quince EDSL here:
http://quince-lib.com/getting_started.html .

3. Just as sqlpp11 uses /connectors/, quince uses /backend libraries/,
or /backends/. Currently I provide backends for PostgreSQL and sqlite.
Unlike sqlpp11, however, I have not yet published the interface between
quince and the backends. It's no secret --the whole lot is open source--
but I'm not yet ready to declare that I know all the customization
points I'm going to need.

4. Quince provides mappings for std::tuple<T, ...> and
boost::optional<T>, whenever it provides mappings for the Ts. E.g. a
boost::optional<int32_t> is mapped as an INTEGER column with its NOT
NULL constraint turned off. If you have a query q1 that produces results
of type T1, and a query q2 that produces results of type T2, then
q1.left_join(q2, some_predicate) produces results of type std::tuple<T1,
boost::optional<T2>>.

5. An application can customize the representation of data in a
particular database, or a particular table.

6. Quince does not currently provide bulk insert. (It's on my to-do list.)

I've barely scratched the surface, but right now I have the impression
that both products have their distinctive pluses.

Keen to know your thoughts.

Regards,
--- Michael


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk