[odb-users] query a container

Boris Kolpackov boris at codesynthesis.com
Fri Apr 17 10:12:34 EDT 2020


sam.degheldere at bricsys.com <sam.degheldere at bricsys.com> writes:

> #pragma db object
> class Commit
> {
>     std::map<OdString, std::shared_ptr<FileData>> m_files;
> }
>   
> I was wondering if I can somehow query on this map?
> 
> Specifically I'd like to query all my commits that contain a certain path
> (string/odstring).

Currently, the only way to query on containers is using native views (i.e.,
raw SQL). With one exception: if the container established a relationship
(like in your example), then you could query on the pointed-to object using
an object view.

So, in your example, a native view is the only way to query based on
the map key (OdString). But for FileData you can do:

#pragma db view object(Commit) object(FileData)
struct CommitFileView
{
  std::shared_ptr<Commit> commit;
};

And then:

using Query = odb::query<CommitFileView>;

db.query<CommitFileView> (Query::FileData::path == mypath)



More information about the odb-users mailing list