ObjectBox C and C++ API  0.12.0
obx::Query< EntityT > Class Template Reference

Provides a simple wrapper for OBX_query to simplify memory management - calls obx_query_close() on destruction. To execute the actual methods, use obx_query_*() methods with query.cPtr() as the first argument. Internal note: this is a template because it will provide EntityType-specific methods in the future. More...

#include <objectbox.hpp>

Public Member Functions

 Query (Store &store, OBX_query_builder *qb)
 Builds a query with the parameters specified by the builder. More...
 
 Query (const Query &query)
 Clones the query. More...
 
 Query (Query &&source) noexcept
 
virtual ~Query ()
 
OBX_querycPtr () const
 
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< std::unique_ptr< EntityT > > find ()
 Finds all objects matching the query. Note: returning a vector of pointers to avoid excessive allocation because we don't know the number of returned objects beforehand. More...
 
std::vector< obx_idfindIds ()
 Returns IDs of all matching objects. 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...
 
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[], int 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...
 

Detailed Description

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

Provides a simple wrapper for OBX_query to simplify memory management - calls obx_query_close() on destruction. To execute the actual methods, use obx_query_*() methods with query.cPtr() as the first argument. Internal note: this is a template because it will provide EntityType-specific methods in the future.

Constructor & Destructor Documentation

◆ Query() [1/3]

template<typename EntityT >
obx::Query< EntityT >::Query ( Store store,
OBX_query_builder qb 
)
inlineexplicit

Builds a query with the parameters specified by the builder.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ Query() [2/3]

template<typename EntityT >
obx::Query< EntityT >::Query ( const Query< EntityT > &  query)
inline

Clones the query.

◆ Query() [3/3]

template<typename EntityT >
obx::Query< EntityT >::Query ( Query< EntityT > &&  source)
inlinenoexcept

◆ ~Query()

template<typename EntityT >
virtual obx::Query< EntityT >::~Query ( )
inlinevirtual

Member Function Documentation

◆ count()

template<typename EntityT >
uint64_t obx::Query< EntityT >::count ( )
inline

Returns the number of matching objects.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ cPtr()

template<typename EntityT >
OBX_query* obx::Query< EntityT >::cPtr ( ) const
inline

◆ find()

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

Finds all objects matching the query. Note: returning a vector of pointers to avoid excessive allocation because we don't know the number of returned objects beforehand.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ findIds()

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

Returns IDs of all matching objects.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ 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.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ 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.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ remove()

template<typename EntityT >
size_t obx::Query< EntityT >::remove ( )
inline

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

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ setParameter() [1/12]

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/12]

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/12]

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/12]

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

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

◆ setParameter() [5/12]

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() [6/12]

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() [7/12]

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.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.

◆ setParameter() [8/12]

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() [9/12]

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() [10/12]

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() [11/12]

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() [12/12]

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.

◆ 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.

Examples
/home/markus/dev/objectbox/objectbox-c/include/objectbox.hpp.