ObjectBox C and C++ API  4.0.3
obx::QueryBuilder< EntityT > Class Template Reference

See QueryBuilderBase for general information on query builders; this templated class allows to work with generated entity types conveniently. To specify actual conditions, use obx_qb_*() methods with queryBuilder.cPtr() as the first argument. More...

#include <objectbox.hpp>

Inheritance diagram for obx::QueryBuilder< EntityT >:
Inheritance graph

Public Member Functions

 QueryBuilder (Store &store)
 
template<OBXPropertyType PropType>
QueryBuilderorder (Property< EntityT, PropType > property, uint32_t flags=0)
 Adds an order based on a given property. More...
 
QueryBuilderwith (const QueryCondition &condition)
 Appends given condition/combination of conditions. More...
 
template<typename RangePropertyEntityT , OBXPropertyType RangePropertyType, typename = EnableIfDate<RangePropertyType>>
QueryBuilder< RangePropertyEntityT > linkTime (Property< RangePropertyEntityT, RangePropertyType > property)
 Links the (time series) entity type to another entity space using a time point in a linked entity. More...
 
template<typename RangePropertyEntityT , OBXPropertyType RangePropertyType, typename = EnableIfDate<RangePropertyType>>
QueryBuilder< RangePropertyEntityT > linkTime (Property< RangePropertyEntityT, RangePropertyType > beginProperty, Property< RangePropertyEntityT, RangePropertyType > endProperty)
 Links the (time series) entity type to another entity space using a range defined in a given linked entity. More...
 
template<typename RelTargetEntityT >
QueryBuilder< RelTargetEntityT > link (RelationProperty< EntityT, RelTargetEntityT > rel)
 Create a link based on a property-relation (to-one). More...
 
template<typename RelSourceEntityT >
QueryBuilder< RelSourceEntityT > backlink (RelationProperty< RelSourceEntityT, EntityT > rel)
 Create a backlink based on a property-relation used in reverse (to-many). More...
 
template<typename RelTargetEntityT >
QueryBuilder< RelTargetEntityT > link (RelationStandalone< EntityT, RelTargetEntityT > rel)
 Create a link based on a standalone relation (many-to-many) More...
 
template<typename RelSourceEntityT >
QueryBuilder< RelSourceEntityT > backlink (RelationStandalone< RelSourceEntityT, EntityT > rel)
 Create a backlink based on a standalone relation (many-to-many, reverse direction) More...
 
QueryBuildernearestNeighborsFloat32 (Property< EntityT, OBXPropertyType_FloatVector > vectorProperty, const float *queryVector, size_t maxResultCount)
 Performs an approximate nearest neighbor (ANN) search to find objects near to the given query vector. This requires the vector property to have a HNSW index. More...
 
QueryBuildernearestNeighborsFloat32 (Property< EntityT, OBXPropertyType_FloatVector > vectorProperty, const std::vector< float > &queryVector, size_t maxResultCount)
 Overload for a std::vector; for details see the pointer-based nearestNeighborsFloat32(). More...
 
Query< EntityT > build ()
 Once all conditions have been applied, build the query using this method to actually run it. More...
 
 QueryBuilderBase (Store &store, obx_schema_id entityId)
 
 QueryBuilderBase (Store &store, const char *entityName)
 
 QueryBuilderBase (Store &store, OBX_query_builder *ptr, bool isRoot)
 Take ownership of an OBX_query_builder. More...
 
 QueryBuilderBase (const QueryBuilderBase &)=delete
 Can't be copied, single owner of C resources is required (e.g. avoid double-free during destruction) More...
 
 QueryBuilderBase (QueryBuilderBase &&source) noexcept
 
- Public Member Functions inherited from obx::QueryBuilderBase
 QueryBuilderBase (Store &store, obx_schema_id entityId)
 
 QueryBuilderBase (Store &store, const char *entityName)
 
 QueryBuilderBase (Store &store, OBX_query_builder *ptr, bool isRoot)
 Take ownership of an OBX_query_builder. More...
 
 QueryBuilderBase (const QueryBuilderBase &)=delete
 Can't be copied, single owner of C resources is required (e.g. avoid double-free during destruction) More...
 
 QueryBuilderBase (QueryBuilderBase &&source) noexcept
 
virtual ~QueryBuilderBase ()
 
OBX_query_buildercPtr () const
 
QueryBuilderBaserelationCount (obx_schema_id relationEntityId, obx_schema_id relationPropertyId, uint32_t relationCount)
 An object matches, if it has a given number of related objects pointing to it. At this point, there are a couple of limitations (later version may improve on that): 1) 1:N relations only, 2) the complexity is O(n * (relationCount + 1)) and cannot be improved via indexes, 3) The relation count cannot be set as an parameter. More...
 
QueryBuilderBaseequals (obx_schema_id propertyId, int64_t value)
 
QueryBuilderBasenotEquals (obx_schema_id propertyId, int64_t value)
 
QueryBuilderBasegreaterThan (obx_schema_id propertyId, int64_t value)
 
QueryBuilderBaselessThan (obx_schema_id propertyId, int64_t value)
 
QueryBuilderBaseequalsString (obx_schema_id propertyId, const char *value, bool caseSensitive=true)
 
QueryBuilderBasenotEqualsString (obx_schema_id propertyId, const char *value, bool caseSensitive=true)
 
QueryBuilderBaseorder (obx_schema_id propertyId, uint32_t flags=0)
 Adds an order based on a given property. More...
 
QueryBuilderBasewith (const QueryCondition &condition)
 Appends given condition/combination of conditions. More...
 
QueryBuilderBasenearestNeighborsFloat32 (obx_schema_id vectorPropertyId, const float *queryVector, size_t maxResultCount)
 Performs an approximate nearest neighbor (ANN) search to find objects near to the given query_vector. This requires the vector property to have a HNSW index. More...
 
QueryBase buildBase ()
 Once all conditions have been applied, build the query using this method to actually run it. More...
 

Protected Member Functions

template<typename LinkedEntityT >
QueryBuilder< LinkedEntityT > linkedQB (OBX_query_builder *qb)
 

Additional Inherited Members

- Protected Attributes inherited from obx::QueryBuilderBase
Storestore_
 
OBX_query_buildercQueryBuilder_
 
const obx_schema_id entityId_
 
const bool isRoot_
 

Detailed Description

template<typename EntityT>
class obx::QueryBuilder< EntityT >

See QueryBuilderBase for general information on query builders; this templated class allows to work with generated entity types conveniently. To specify actual conditions, use obx_qb_*() methods with queryBuilder.cPtr() as the first argument.

Constructor & Destructor Documentation

◆ QueryBuilder()

template<typename EntityT >
obx::QueryBuilder< EntityT >::QueryBuilder ( Store store)
inlineexplicit

Member Function Documentation

◆ backlink() [1/2]

template<typename EntityT >
template<typename RelSourceEntityT >
QueryBuilder<RelSourceEntityT> obx::QueryBuilder< EntityT >::backlink ( RelationProperty< RelSourceEntityT, EntityT >  rel)
inline

Create a backlink based on a property-relation used in reverse (to-many).

Note
Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Parameters
relthe relation property, with target EntityT represented by this QueryBuilder.
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ backlink() [2/2]

template<typename EntityT >
template<typename RelSourceEntityT >
QueryBuilder<RelSourceEntityT> obx::QueryBuilder< EntityT >::backlink ( RelationStandalone< RelSourceEntityT, EntityT >  rel)
inline

Create a backlink based on a standalone relation (many-to-many, reverse direction)

Note
Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ link() [1/2]

template<typename EntityT >
template<typename RelTargetEntityT >
QueryBuilder<RelTargetEntityT> obx::QueryBuilder< EntityT >::link ( RelationProperty< EntityT, RelTargetEntityT >  rel)
inline

Create a link based on a property-relation (to-one).

Note
Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Parameters
relthe relation property, with source EntityT represented by this QueryBuilder.
conditiona condition or a group of conditions to apply on the linked entity
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ link() [2/2]

template<typename EntityT >
template<typename RelTargetEntityT >
QueryBuilder<RelTargetEntityT> obx::QueryBuilder< EntityT >::link ( RelationStandalone< EntityT, RelTargetEntityT >  rel)
inline

Create a link based on a standalone relation (many-to-many)

Note
Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ linkedQB()

template<typename EntityT >
template<typename LinkedEntityT >
QueryBuilder<LinkedEntityT> obx::QueryBuilder< EntityT >::linkedQB ( OBX_query_builder qb)
inlineprotected

◆ linkTime() [1/2]

template<typename EntityT >
template<typename RangePropertyEntityT , OBXPropertyType RangePropertyType, typename = EnableIfDate<RangePropertyType>>
QueryBuilder<RangePropertyEntityT> obx::QueryBuilder< EntityT >::linkTime ( Property< RangePropertyEntityT, RangePropertyType >  beginProperty,
Property< RangePropertyEntityT, RangePropertyType >  endProperty 
)
inline

Links the (time series) entity type to another entity space using a range defined in a given linked entity.

Note
1) Time series functionality (ObjectBox TS) must be available to use this.
2) Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Parameters
beginPropertyProperty of the linked entity defining the beginning of a time range. Must be a date type (e.g. PropertyType_Date or PropertyType_DateNano).
endPropertyProperty of the linked entity defining the end of a time range. Must be a date type (e.g. PropertyType_Date or PropertyType_DateNano).
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ linkTime() [2/2]

template<typename EntityT >
template<typename RangePropertyEntityT , OBXPropertyType RangePropertyType, typename = EnableIfDate<RangePropertyType>>
QueryBuilder<RangePropertyEntityT> obx::QueryBuilder< EntityT >::linkTime ( Property< RangePropertyEntityT, RangePropertyType >  property)
inline

Links the (time series) entity type to another entity space using a time point in a linked entity.

Note
1) Time series functionality (ObjectBox TS) must be available to use this.
2) Returned QueryBuilder switches context, make sure to call build() on the root QueryBuilder.
Parameters
propertyProperty of the linked entity defining a time point or the begin of a time range. Must be a date type (e.g. PropertyType_Date or PropertyType_DateNano).
Returns
the linked QueryBuilder; "switches context" to the linked entity.

◆ nearestNeighborsFloat32() [1/2]

template<typename EntityT >
QueryBuilder& obx::QueryBuilder< EntityT >::nearestNeighborsFloat32 ( Property< EntityT, OBXPropertyType_FloatVector vectorProperty,
const float *  queryVector,
size_t  maxResultCount 
)
inline

Performs an approximate nearest neighbor (ANN) search to find objects near to the given query vector. This requires the vector property to have a HNSW index.

Parameters
vectorPropertythe vector property ID of the entity
queryVectorthe query vector; its dimensions should be at least the dimensions of the vector property.
maxResultCountmaximum number of objects to return by the ANN condition. Hint: it can also be used as the "ef" HNSW parameter to increase the search quality in combination with a query limit. For example, use 100 here with a query limit of 10 to have 10 results that are of potentially better quality than just passing in 10 here (quality/performance tradeoff).

◆ nearestNeighborsFloat32() [2/2]

template<typename EntityT >
QueryBuilder& obx::QueryBuilder< EntityT >::nearestNeighborsFloat32 ( Property< EntityT, OBXPropertyType_FloatVector vectorProperty,
const std::vector< float > &  queryVector,
size_t  maxResultCount 
)
inline

Overload for a std::vector; for details see the pointer-based nearestNeighborsFloat32().

◆ order()

template<typename EntityT >
template<OBXPropertyType PropType>
QueryBuilder& obx::QueryBuilder< EntityT >::order ( Property< EntityT, PropType >  property,
uint32_t  flags = 0 
)
inline

Adds an order based on a given property.

Parameters
propertythe property used for the order
flagscombination of OBXOrderFlags
Returns
the reference to the same QueryBuilder for fluent interface.

◆ QueryBuilderBase() [1/5]

template<typename EntityT >
obx::QueryBuilderBase::QueryBuilderBase
delete

Can't be copied, single owner of C resources is required (e.g. avoid double-free during destruction)

◆ QueryBuilderBase() [2/5]

template<typename EntityT >
obx::QueryBuilderBase::QueryBuilderBase
inlinenoexcept

◆ QueryBuilderBase() [3/5]

template<typename EntityT >
obx::QueryBuilderBase::QueryBuilderBase
inline

◆ QueryBuilderBase() [4/5]

template<typename EntityT >
obx::QueryBuilderBase::QueryBuilderBase
inlineexplicit

Take ownership of an OBX_query_builder.

*Example:**

     QueryBuilder innerQb(obx_qb_link_property(outerQb.cPtr(), linkPropertyId), false)

◆ QueryBuilderBase() [5/5]

template<typename EntityT >
obx::QueryBuilderBase::QueryBuilderBase
inline

◆ with()

template<typename EntityT >
QueryBuilder& obx::QueryBuilder< EntityT >::with ( const QueryCondition &  condition)
inline

Appends given condition/combination of conditions.

Returns
the reference to the same QueryBuilder for fluent interface.