ObjectBox C and C++ API  4.0.3
obx::Query< EntityT > Class Template 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::Query< EntityT >:
Inheritance graph

Public Member Functions

Queryoffset (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...
 
Querylimit (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< EntityT > find ()
 Finds all objects matching the query. More...
 
std::vector< std::unique_ptr< EntityT > > findUniquePtrs ()
 Finds all objects matching the query. More...
 
std::vector< std::pair< EntityT, double > > findWithScores ()
 Find objects 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 find()). More...
 
std::unique_ptr< EntityT > findFirst ()
 Find the first object matching the query or nullptr if none matches. More...
 
std::unique_ptr< EntityT > findUnique ()
 Find the only object matching the query. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_String || PropertyType == OBXPropertyType_StringVector>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, const char *value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_String || PropertyType == OBXPropertyType_StringVector>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, const std::string &value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_String > property, const char *const values[], size_t count)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_String > property, const std::vector< const char * > &values)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_String > property, const std::vector< std::string > &values)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_Bool > property, bool value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfIntegerOrRel<PropertyType>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, int64_t value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfIntegerOrRel<PropertyType>>
QuerysetParameters (Property< PropertyEntityT, PropertyType > property, int64_t valueA, int64_t valueB)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_Long || PropertyType == OBXPropertyType_Relation>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, const std::vector< int64_t > &values)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_Int>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, const std::vector< int32_t > &values)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfFloating<PropertyType>>
QuerysetParameter (Property< PropertyEntityT, PropertyType > property, double value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfFloating<PropertyType>>
QuerysetParameters (Property< PropertyEntityT, PropertyType > property, double valueA, double valueB)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_ByteVector > property, const void *value, size_t size)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_ByteVector > property, const std::vector< uint8_t > &value)
 Change previously set condition value in an existing query - this improves reusability of the query object. More...
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_FloatVector > property, const float *value, size_t element_count)
 
template<typename PropertyEntityT >
QuerysetParameter (Property< PropertyEntityT, OBXPropertyType_FloatVector > property, const std::vector< float > &vector)
 
template<typename PropertyEntityT >
QuerysetParameterMaxNeighbors (Property< PropertyEntityT, OBXPropertyType_FloatVector > property, int64_t maxNeighborCount)
 Only for HNSW-enabled properties that are used for a nearest neighbor search: sets the maximum of neighbors to search for. More...
 
 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
 
- Public Member Functions inherited from obx::QueryBase
 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)
 

Additional Inherited Members

- Protected Attributes inherited from obx::QueryBase
Storestore_
 
OBX_querycQuery_
 

Detailed Description

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

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

Member Function Documentation

◆ find()

template<typename EntityT >
std::vector<EntityT> obx::Query< EntityT >::find ( )
inline

Finds all objects matching the query.

Returns
a vector of objects

◆ findFirst()

template<typename EntityT >
std::unique_ptr<EntityT> obx::Query< EntityT >::findFirst ( )
inline

Find the first object matching the query or nullptr if none matches.

◆ findUnique()

template<typename EntityT >
std::unique_ptr<EntityT> obx::Query< EntityT >::findUnique ( )
inline

Find the only object matching the query.

Exceptions
ifthere are multiple objects matching the query

◆ findUniquePtrs()

template<typename EntityT >
std::vector<std::unique_ptr<EntityT> > obx::Query< EntityT >::findUniquePtrs ( )
inline

Finds all objects matching the query.

Returns
a vector of unique_ptr of the resulting objects

◆ findWithScores()

template<typename EntityT >
std::vector<std::pair<EntityT, double> > obx::Query< EntityT >::findWithScores ( )
inline

Find objects 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 find()).

◆ limit()

template<typename EntityT >
Query& obx::Query< EntityT >::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()

template<typename EntityT >
Query& obx::Query< EntityT >::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.

◆ QueryBase() [1/3]

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

Clones the query.

◆ QueryBase() [2/3]

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

◆ QueryBase() [3/3]

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

Builds a query with the parameters specified by the builder.

◆ setParameter() [1/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_Bool property,
bool  value 
)
inline

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

◆ setParameter() [2/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_ByteVector property,
const std::vector< uint8_t > &  value 
)
inline

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

◆ setParameter() [3/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_ByteVector property,
const void *  value,
size_t  size 
)
inline

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

◆ setParameter() [4/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_FloatVector property,
const float *  value,
size_t  element_count 
)
inline

◆ setParameter() [5/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_FloatVector property,
const std::vector< float > &  vector 
)
inline

◆ setParameter() [6/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_String property,
const char *const  values[],
size_t  count 
)
inline

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

◆ setParameter() [7/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_String property,
const std::vector< const char * > &  values 
)
inline

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

◆ setParameter() [8/14]

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, OBXPropertyType_String property,
const std::vector< std::string > &  values 
)
inline

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

◆ setParameter() [9/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_String || PropertyType == OBXPropertyType_StringVector>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
const char *  value 
)
inline

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

◆ setParameter() [10/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_String || PropertyType == OBXPropertyType_StringVector>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
const std::string &  value 
)
inline

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

◆ setParameter() [11/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_Int>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
const std::vector< int32_t > &  values 
)
inline

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

◆ setParameter() [12/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = enable_if_t<PropertyType == OBXPropertyType_Long || PropertyType == OBXPropertyType_Relation>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
const std::vector< int64_t > &  values 
)
inline

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

◆ setParameter() [13/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfFloating<PropertyType>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
double  value 
)
inline

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

◆ setParameter() [14/14]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfIntegerOrRel<PropertyType>>
Query& obx::Query< EntityT >::setParameter ( Property< PropertyEntityT, PropertyType >  property,
int64_t  value 
)
inline

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

◆ setParameterMaxNeighbors()

template<typename EntityT >
template<typename PropertyEntityT >
Query& obx::Query< EntityT >::setParameterMaxNeighbors ( Property< PropertyEntityT, OBXPropertyType_FloatVector property,
int64_t  maxNeighborCount 
)
inline

Only for HNSW-enabled properties that are used for a nearest neighbor search: sets the maximum of neighbors to search for.

◆ setParameters() [1/2]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfFloating<PropertyType>>
Query& obx::Query< EntityT >::setParameters ( Property< PropertyEntityT, PropertyType >  property,
double  valueA,
double  valueB 
)
inline

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

◆ setParameters() [2/2]

template<typename EntityT >
template<typename PropertyEntityT , OBXPropertyType PropertyType, typename = EnableIfIntegerOrRel<PropertyType>>
Query& obx::Query< EntityT >::setParameters ( Property< PropertyEntityT, PropertyType >  property,
int64_t  valueA,
int64_t  valueB 
)
inline

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