drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::orm::Criteria Class Reference

this class represents a comparison condition. More...

#include <drogon/orm/Criteria.h>

Public Member Functions

 operator bool () const
 Check if the condition is empty.
std::string criteriaString () const
 return the condition string in SQL.
template<typename... Arguments>
 Criteria (const CustomSql &sql, Arguments &&...args)
 Construct a new custom Criteria object.
template<typename... Arguments>
 Criteria (CustomSql &&sql, Arguments &&...args)
template<typename T>
 Criteria (const std::string &colName, const CompareOperator &opera, T &&arg)
 Construct a new Criteria object.
template<typename T>
 Criteria (const std::string &colName, const CompareOperator &opera, const std::vector< T > &args)
template<typename T>
 Criteria (const std::string &colName, const CompareOperator &opera, std::vector< T > &&args)
template<typename T>
 Criteria (const std::string &colName, const CompareOperator &opera, std::vector< T > &args)
template<typename T>
 Criteria (const std::string &colName, T &&arg)
 Construct a new Criteria object presenting a equal expression.
 Criteria (const std::string &colName, const CompareOperator &opera)
 Construct a new Criteria object presenting a expression without parameters.
 Criteria (const std::string &colName, CompareOperator &opera)
 Criteria (const std::string &colName, CompareOperator &&opera)
 Criteria (const Json::Value &json) noexcept(false)
 Construct a new Criteria object.
void outputArgs (internal::SqlBinder &binder) const
 Output arguments to the SQL binder object.

Friends

DROGON_EXPORT const Criteria operator&& (Criteria cond1, Criteria cond2)
DROGON_EXPORT const Criteria operator|| (Criteria cond1, Criteria cond2)

Detailed Description

this class represents a comparison condition.

Constructor & Destructor Documentation

◆ Criteria() [1/5]

template<typename... Arguments>
drogon::orm::Criteria::Criteria ( const CustomSql & sql,
Arguments &&... args )
inlineexplicit

Construct a new custom Criteria object.

Parameters
sqlThe SQL statement to be executed.
argsThe parameters to be passed to the placeholders.
Note

Use $? as placeholders in the SQL statement.

Be careful that the placeholders are not the same as the ones in functions such as drogon::orm::DbClient::execSqlAsync. Which means you couldn't use numeric placeholders such as $1, $2 to represent the order of the arguments.

The arguments should be in the same order as the placeholders.

◆ Criteria() [2/5]

template<typename T>
drogon::orm::Criteria::Criteria ( const std::string & colName,
const CompareOperator & opera,
T && arg )
inline

Construct a new Criteria object.

Template Parameters
Tthe type of the object to be compared with.
Parameters
colNameThe name of the column.
operaThe type of the comparison.
argThe object to be compared with.

◆ Criteria() [3/5]

template<typename T>
drogon::orm::Criteria::Criteria ( const std::string & colName,
T && arg )
inline

Construct a new Criteria object presenting a equal expression.

Template Parameters
TThe type of the object to be equal to.
Parameters
colNameThe name of the column.
argThe object to be equal to.

◆ Criteria() [4/5]

drogon::orm::Criteria::Criteria ( const std::string & colName,
const CompareOperator & opera )
inline

Construct a new Criteria object presenting a expression without parameters.

Parameters
colNameThe name of the column.
operaThe type of the comparison. it must be one of the following:
CompareOperator::IsNotNull
CompareOperator::IsNull

◆ Criteria() [5/5]

drogon::orm::Criteria::Criteria ( const Json::Value & json)
explicit

Construct a new Criteria object.

Parameters
jsonA json object representing the criteria
Note
the json object must be a array of three items, the first is the name of the field, the second is the comparison operator and the third is the value to be compared. The valid operators are "=","<",">","<=",">=","!=","in" for example: ["id","=",1] means 'id = 1' ["id","!=",null] means 'id is not null' ["user_name","in",["Tom","Bob"]] means 'user_name in ('Tom', 'Bob')' ["price","<",1000] means 'price < 1000'

Member Function Documentation

◆ criteriaString()

std::string drogon::orm::Criteria::criteriaString ( ) const
inline

return the condition string in SQL.

Returns
std::string

◆ operator bool()

drogon::orm::Criteria::operator bool ( ) const
inlineexplicit

Check if the condition is empty.

Returns
true means the condition is not empty.
false means the condition is empty.

◆ outputArgs()

void drogon::orm::Criteria::outputArgs ( internal::SqlBinder & binder) const
inline

Output arguments to the SQL binder object.

Parameters
binderThe SQL binder object.
Note
This method must be called by drogon.

The documentation for this class was generated from the following file: