[odb-users] Using members that are sets in a odb::sqlite::database::query

Boris Kolpackov boris at codesynthesis.com
Wed Mar 16 07:56:52 EDT 2022


stefano dalbosco <stef.dalbosco at hotmail.com> writes:

> I have a db object with a member that is a set of strings and I like
> to create a odb::sqlite::database::query which given a string returns
> all objects that contains that string in there set.
>
> This is how my object looks like:
> 
> #pragma db object
> struct person
> {
>     #pragma db id auto
>     unsigned id_;
> 
>     std::string name_;
>     std::set<std::string> emails_;
> }
> 
> I can then easily query on name like this:
>     db.query<person>(odb::query<person>::name == "John");
> which return all the persons with name John. But is there a similar way
> to get all the persons with a specific email?

Using containers in query conditions is not yet supported except in a
few limited cases. Currently the only straightforward way to achieve this
is to "drop down" to SQL with a native view. (The not straightforward way
would be to try to map an object relationship to the container's table
and use that in the query condition).

You can find previous discussion of this topic by searching for
query+container in archives:

https://www.codesynthesis.com/pipermail/odb-users/



More information about the odb-users mailing list