docudb  1.0
Loading...
Searching...
No Matches
docudb::query::binary_op Struct Reference

Represents a binary operation for querying. More...

#include <docudb.hpp>

Inheritance diagram for docudb::query::binary_op:
docudb::query::eq docudb::query::gt docudb::query::gte docudb::query::like docudb::query::lt docudb::query::lte docudb::query::neq docudb::query::regexp

Public Member Functions

 binary_op (std::string const &json_query, std::string const &op, db_value &&value)
 
 binary_op (std::string const &json_query, std::string const &op, nullptr_t)
 
std::string to_query_string () const
 
binder const & get_binder () const
 
binderget_binder ()
 

Detailed Description

Represents a binary operation for querying.

Definition at line 243 of file docudb.hpp.

Constructor & Destructor Documentation

◆ binary_op() [1/2]

docudb::query::binary_op::binary_op ( std::string const & json_query,
std::string const & op,
db_value && value )
inlineexplicit

Definition at line 245 of file docudb.hpp.

248 : var_(json_query), op_(op), index_(1 + (++bind_counter % MAX_VAR_NUM))
249 {
250 binder_.add(index_, std::move(value));
251 }
const int MAX_VAR_NUM
Definition docudb.hpp:238
thread_local int bind_counter
void add(int index, db_value &&v)
Definition docudb.hpp:160

◆ binary_op() [2/2]

docudb::query::binary_op::binary_op ( std::string const & json_query,
std::string const & op,
nullptr_t  )
inlineexplicit

Definition at line 253 of file docudb.hpp.

256 : var_(json_query), op_(op), index_(-1)
257 {
258
259 }

Member Function Documentation

◆ get_binder() [1/2]

binder & docudb::query::binary_op::get_binder ( )
inline

Definition at line 285 of file docudb.hpp.

286 {
287 return binder_;
288 }

◆ get_binder() [2/2]

binder const & docudb::query::binary_op::get_binder ( ) const
inline

Definition at line 280 of file docudb.hpp.

281 {
282 return binder_;
283 }

◆ to_query_string()

std::string docudb::query::binary_op::to_query_string ( ) const
inline

Definition at line 261 of file docudb.hpp.

262 {
263 auto json_query = var_.size() > 0 && var_[0] == '$';
264 auto is_value_null = index_ == -1;
265
266 // special case for null value
267 if (is_value_null) {
268 if (json_query)
269 return std::format("json_type(body, '{0}') IS NOT NULL AND json_extract(body, '{0}') {1} NULL", var_, op_);
270 else
271 return std::format("[{}] {} NULL", var_, op_);
272 }
273
274 if (json_query)
275 return std::format("(json_extract(body, '{}') {} ?{})", var_, op_, index_);
276 else
277 return std::format("([{}] {} ?{})", var_, op_, index_);
278 }

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