Boost logo

Boost :

From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2024-03-27 01:02:12


On Tue, Mar 26, 2024 at 9:03 AM Peter Dimov via Boost
<boost_at_[hidden]> wrote:
>
> Klemens Morgenstern wrote:
> > > We have our own wrappers (plural), and even code based on Fusion (used
> > > in tests only) that I got here, which would probably be much nicer using
> > more modern C++ techniques. Integration with PFR or Describe would also be
> > pluses.
> >
> > I thought about doing that, but it's unclear to me how. Mapping a struct to a
> > table seems intuitive, but then how do I handle anything select other than `*` ?
>
> In the usual manner? The rows of `SELECT x, y FROM ...` can be retrieved as
>
> struct R
> {
> int x;
> std::string y;
> };
>
> BOOST_DESCRIBE_STRUCT(R, (), (x, y))
>

I added support for describe, tuples and pfr (on C++20) see here:
https://github.com/klemens-morgenstern/sqlite?tab=readme-ov-file#typed-queries

The implementation is currently done through tag_invoke in `detail`,
so it would be possible to open this up to more types if I can be
convinced of a use-case.

struct query_result { std::string first_name, lib_name;};
BOOST_DESCRIBE_STRUCT(query_result, (), (first_name, lib_name));

for (auto q : conn.query<query_result>(
    "select first_name, collect_libs(name) as lib_name"
       " from author inner join library l on author.id = l.author
group by last_name"))
  std::cout << q.first_name << " authored " << q.lib_name << std::endl;


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