How to Join in ObjectBox C++

48 Views Asked by At

How do I make a relational query in ObjectBox C++

schema.fbs

table Slot {
    /// objectbox:id
    id                      : ulong;

    defaultlinkoffset               : int32;

    /// objectbox:relation=Device
    parentid                    : ulong;
}

table Device {
    /// objectbox:id
    id                      : ulong;
    hid                     : string;
}

I can insert and query a table no problem

Insert

tableDevice_.put({.id = 0, .hid = hid});

Query

std::string hid = "test";
obx::QueryBuilder<Device> qb = tableDevice_.query(Device_::hid.equals(hid, true));
obx::Query<Device> query = qb.build();
query.find();

There is a many to one relationship between Slot and Device, 1 Slot can have many devices. Slot parentuid cannot be set to an array/vector the docs on the C++ side are sparse but looking at the tests only vectors of string, byte and ubyte are supported.

C++ tests:

https://github.com/objectbox/objectbox-generator/blob/main/test/comparison/testdata/fbs/typeful/schema.fbs

The Java docs show you can use ToMany<Relation> data; is there a similar feature for the C++ version?

Java docs: https://docs.objectbox.io/relations

I also tried a relational query by looking at the Java docs but it does not build

obx::QueryBuilder<Slot> builder = tableSlot_.query(Slot_::defaultlinkoffset.equals(123));
builder.link(Slot_::parentid).equals(Slot_::parentid, "123");

Is this possible for the C++ version? Are there any examples?

0

There are 0 best solutions below