Boost logo

Boost :

Subject: Re: [boost] quince: queries in C++ expressions
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-07-16 12:13:55


> Could you clarify what you mean by "do this"? QUINCE_MAP_CLASS builds a
> class with exactly the data members, function members, and bases that
> quince requires.

Boost.Fusion already provides the ability to map the classes to fusion
sequences. Here is a very simple example how to build an ORM using
Boost.Fusion in C++14:

https://gist.github.com/pfultz2/abbea635bdc8a4971424

Of course as a simple example, it doesn't map the types to the database
types(it just uses `typeid` for illustration purposes only).

Now this example just demonstrates mapping to the database with fusion. The
other half is building queries in C++. This can easily be done by taking
advantage that the structs are adapted as associative sequences. So we can
use
the keys to refer to the fields. So we could build queries something like
this:

    table<person> p("person");
    auto query = from(p)
                 .where(at_key<fields::age>(p) > 60)
                 .select(at_key<fields::name>(p));

Of course, some additional macros would be useful to reduce the boilerplate,
but an ORM in C++ should really start with Boost.Fusion.

> I'm not actually doing tuple manipulation here. That's not to say the
> task couldn't be solved by a detour through tuples, but it /would/ be a
> detour.

But it would be a 'detour' that would save you from writing mapping macros.

-Paul Fultz II

--
View this message in context: http://boost.2283326.n4.nabble.com/quince-queries-in-C-expressions-tp4665143p4665226.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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