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

Query allows to find data matching user defined criteria for a entity type. Created by QueryBuilder and typically used with supplying a Cursor. More...

#include <objectbox.hpp>

Inheritance diagram for obx::QueryBase:
Inheritance graph

Public Member Functions

 QueryBase (Store &store, OBX_query_builder *qb)
 Builds a query with the parameters specified by the builder. More...
 
 QueryBase (const QueryBase &query)
 Clones the query. More...
 
 QueryBase (QueryBase &&source) noexcept
 
virtual ~QueryBase ()
 
OBX_querycPtr () const
 
QueryBaseoffset (size_t offset)
 Sets an offset of what items to start at. This offset is stored for any further calls on the query until changed. Call with offset=0 to reset to the default behavior, i.e. starting from the first element. More...
 
QueryBaselimit (size_t limit)
 Sets a limit on the number of processed items. This limit is stored for any further calls on the query until changed. Call with limit=0 to reset to the default behavior - zero limit means no limit applied. More...
 
std::vector< obx_idfindIds ()
 Returns IDs of all matching objects. Note: if no order conditions is present, the order is arbitrary (sometimes ordered by ID, but never guaranteed to). More...
 
std::vector< std::pair< obx_id, double > > findIdsWithScores ()
 Find object IDs matching the query associated to their query score (e.g. distance in NN search). The resulting vector is sorted by score in ascending order (unlike findIds()). More...
 
std::vector< obx_idfindIdsByScore ()
 Find object IDs matching the query ordered by their query score (e.g. distance in NN search). The resulting array is sorted by score in ascending order (unlike findIds()). Unlike findIdsWithScores(), this method returns a simple vector of IDs without scores. More...
 
void visit (obx_data_visitor *visitor, void *userData)
 Walk over matching objects one-by-one using the given data visitor (C-style callback function with user data). Note: if no order conditions is present, the order is arbitrary (sometimes ordered by ID, but never guaranteed to). More...
 
void visitWithScore (obx_data_score_visitor *visitor, void *userData)
 Walk over matching objects one-by-one using the given data visitor (C-style callback function with user data). Note: the elements are ordered by the score. More...
 
uint64_t count ()
 Returns the number of matching objects. More...
 
size_t remove ()
 Removes all matching objects from the database & returns the number of deleted objects. More...
 
QueryBasesetParameter (obx_schema_id entityId, obx_schema_id propertyId, const char *value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
QueryBasesetParameter (obx_schema_id entityId, obx_schema_id propertyId, const std::string &value)
 
QueryBasesetParameter (obx_schema_id entityId, obx_schema_id propertyId, int64_t value)
 

Protected Attributes

Storestore_
 
OBX_querycQuery_
 

Detailed Description

Query allows to find data matching user defined criteria for a entity type. Created by QueryBuilder and typically used with supplying a Cursor.

Constructor & Destructor Documentation

◆ QueryBase() [1/3]

obx::QueryBase::QueryBase ( Store store,
OBX_query_builder qb 
)
inlineexplicit

Builds a query with the parameters specified by the builder.

◆ QueryBase() [2/3]

obx::QueryBase::QueryBase ( const QueryBase query)
inline

Clones the query.

◆ QueryBase() [3/3]

obx::QueryBase::QueryBase ( QueryBase &&  source)
inlinenoexcept

◆ ~QueryBase()

virtual obx::QueryBase::~QueryBase ( )
inlinevirtual

Member Function Documentation

◆ count()

uint64_t obx::QueryBase::count ( )
inline

Returns the number of matching objects.

◆ cPtr()

OBX_query* obx::QueryBase::cPtr ( ) const
inline

◆ findIds()

std::vector<obx_id> obx::QueryBase::findIds ( )
inline

Returns IDs of all matching objects. Note: if no order conditions is present, the order is arbitrary (sometimes ordered by ID, but never guaranteed to).

◆ findIdsByScore()

std::vector<obx_id> obx::QueryBase::findIdsByScore ( )
inline

Find object IDs matching the query ordered by their query score (e.g. distance in NN search). The resulting array is sorted by score in ascending order (unlike findIds()). Unlike findIdsWithScores(), this method returns a simple vector of IDs without scores.

◆ findIdsWithScores()

std::vector<std::pair<obx_id, double> > obx::QueryBase::findIdsWithScores ( )
inline

Find object IDs matching the query associated to their query score (e.g. distance in NN search). The resulting vector is sorted by score in ascending order (unlike findIds()).

◆ limit()

QueryBase& obx::QueryBase::limit ( size_t  limit)
inline

Sets a limit on the number of processed items. This limit is stored for any further calls on the query until changed. Call with limit=0 to reset to the default behavior - zero limit means no limit applied.

◆ offset()

QueryBase& obx::QueryBase::offset ( size_t  offset)
inline

Sets an offset of what items to start at. This offset is stored for any further calls on the query until changed. Call with offset=0 to reset to the default behavior, i.e. starting from the first element.

◆ remove()

size_t obx::QueryBase::remove ( )
inline

Removes all matching objects from the database & returns the number of deleted objects.

◆ setParameter() [1/3]

QueryBase& obx::QueryBase::setParameter ( obx_schema_id  entityId,
obx_schema_id  propertyId,
const char *  value 
)
inline

Change previously set condition value in an existing query - this improves reusability of the query object.

◆ setParameter() [2/3]

QueryBase& obx::QueryBase::setParameter ( obx_schema_id  entityId,
obx_schema_id  propertyId,
const std::string &  value 
)
inline

◆ setParameter() [3/3]

QueryBase& obx::QueryBase::setParameter ( obx_schema_id  entityId,
obx_schema_id  propertyId,
int64_t  value 
)
inline

◆ visit()

void obx::QueryBase::visit ( obx_data_visitor visitor,
void *  userData 
)
inline

Walk over matching objects one-by-one using the given data visitor (C-style callback function with user data). Note: if no order conditions is present, the order is arbitrary (sometimes ordered by ID, but never guaranteed to).

◆ visitWithScore()

void obx::QueryBase::visitWithScore ( obx_data_score_visitor visitor,
void *  userData 
)
inline

Walk over matching objects one-by-one using the given data visitor (C-style callback function with user data). Note: the elements are ordered by the score.

Member Data Documentation

◆ cQuery_

OBX_query* obx::QueryBase::cQuery_
protected

◆ store_

Store& obx::QueryBase::store_
protected