ObjectBox C and C++ API  4.0.3
obx::QueryBuilderBase Class Reference

A QueryBuilderBase is used to create database queries using an API (no string based query language). Building the queries involves calling functions to add conditions for the query. In the end a Query object is build, which then can be used to actually run the query (potentially multiple times). For generated code, you can also use the templated subclass QueryBuilder instead to have type safety at compile time. More...

#include <objectbox.hpp>

Inheritance diagram for obx::QueryBuilderBase:
Inheritance graph

Public Member Functions

 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 Attributes

Storestore_
 
OBX_query_buildercQueryBuilder_
 
const obx_schema_id entityId_
 
const bool isRoot_
 

Detailed Description

A QueryBuilderBase is used to create database queries using an API (no string based query language). Building the queries involves calling functions to add conditions for the query. In the end a Query object is build, which then can be used to actually run the query (potentially multiple times). For generated code, you can also use the templated subclass QueryBuilder instead to have type safety at compile time.

Constructor & Destructor Documentation

◆ QueryBuilderBase() [1/5]

obx::QueryBuilderBase::QueryBuilderBase ( Store store,
obx_schema_id  entityId 
)
inline

◆ QueryBuilderBase() [2/5]

obx::QueryBuilderBase::QueryBuilderBase ( Store store,
const char *  entityName 
)
inline

◆ QueryBuilderBase() [3/5]

obx::QueryBuilderBase::QueryBuilderBase ( Store store,
OBX_query_builder ptr,
bool  isRoot 
)
inlineexplicit

Take ownership of an OBX_query_builder.

*Example:**

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

◆ QueryBuilderBase() [4/5]

obx::QueryBuilderBase::QueryBuilderBase ( const QueryBuilderBase )
delete

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

◆ QueryBuilderBase() [5/5]

obx::QueryBuilderBase::QueryBuilderBase ( QueryBuilderBase &&  source)
inlinenoexcept

◆ ~QueryBuilderBase()

virtual obx::QueryBuilderBase::~QueryBuilderBase ( )
inlinevirtual

Member Function Documentation

◆ buildBase()

QueryBase obx::QueryBuilderBase::buildBase ( )

Once all conditions have been applied, build the query using this method to actually run it.

◆ cPtr()

OBX_query_builder* obx::QueryBuilderBase::cPtr ( ) const
inline

◆ equals()

QueryBuilderBase& obx::QueryBuilderBase::equals ( obx_schema_id  propertyId,
int64_t  value 
)
inline

◆ equalsString()

QueryBuilderBase& obx::QueryBuilderBase::equalsString ( obx_schema_id  propertyId,
const char *  value,
bool  caseSensitive = true 
)
inline

◆ greaterThan()

QueryBuilderBase& obx::QueryBuilderBase::greaterThan ( obx_schema_id  propertyId,
int64_t  value 
)
inline

◆ lessThan()

QueryBuilderBase& obx::QueryBuilderBase::lessThan ( obx_schema_id  propertyId,
int64_t  value 
)
inline

◆ nearestNeighborsFloat32()

QueryBuilderBase& obx::QueryBuilderBase::nearestNeighborsFloat32 ( obx_schema_id  vectorPropertyId,
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
vectorPropertyIdthe 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).

◆ notEquals()

QueryBuilderBase& obx::QueryBuilderBase::notEquals ( obx_schema_id  propertyId,
int64_t  value 
)
inline

◆ notEqualsString()

QueryBuilderBase& obx::QueryBuilderBase::notEqualsString ( obx_schema_id  propertyId,
const char *  value,
bool  caseSensitive = true 
)
inline

◆ order()

QueryBuilderBase& obx::QueryBuilderBase::order ( obx_schema_id  propertyId,
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.

◆ relationCount()

QueryBuilderBase& obx::QueryBuilderBase::relationCount ( obx_schema_id  relationEntityId,
obx_schema_id  relationPropertyId,
uint32_t  relationCount 
)
inline

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.

Parameters
relationEntityIdID of the entity type the relation comes from.
relationPropertyIdID of the property in the related entity type representing the relation.
relationCountNumber of related object an object must have to match. May be 0 if objects shall be matched that do not have related objects. (Typically low numbers are used for the count.)

◆ with()

QueryBuilderBase& obx::QueryBuilderBase::with ( const QueryCondition &  condition)
inline

Appends given condition/combination of conditions.

Returns
the reference to the same QueryBuilder for fluent interface.

Member Data Documentation

◆ cQueryBuilder_

OBX_query_builder* obx::QueryBuilderBase::cQueryBuilder_
protected

◆ entityId_

const obx_schema_id obx::QueryBuilderBase::entityId_
protected

◆ isRoot_

const bool obx::QueryBuilderBase::isRoot_
protected

◆ store_

Store& obx::QueryBuilderBase::store_
protected