QueryBuilder<T>/OBX_query_builder
class lets you build custom queries for your entities. Create an instance via box.query()
(C++) or obx_query_builder()
(C). enum
(C) or a struct
(C++). These provide a way to define query conditions safely, without literal entity and property IDs spread throughout the code. Let's have a look at a fragment of the generated code for a User
entity (its unique Entity ID is 6
and it has three properties: id
, name
surname
) and the examples below.build
the query and finally execute it using find
.obx_query_find()
needs to be executed inside an explicit read transaction to avoid data copy while preserving its validity (so that concurrent threads won't change the data while you read it). We're omitting this in the examples to keep them simple, see Transactions for more details.Query
you should cache the Query
object and re-use it. To make a Query
more reusable you can change the values, or query parameters, of each condition you added even after the Query
is built. Let's see how.User
with specific name
values. First, we build a regular Query
with an equal
condition for name
. Because we have to pass an initial parameter value to equal()
but plan to override it before running the Query
later, we just pass an empty string:Query
. To set a value for the name
parameter on the Query
and pass the name
property and the new parameter value:Alias()
right after specifying the condition:offset
and limit
methods to help you do that.obx_query_prop_*_find()
.objectbox.h
and objectbox.hpp
or API docs to discover more.