Function count

Summary

#include <orm_lib/inc/drogon/orm/Mapper.h>

(1) size_t count(const Criteria &criteria=Criteria()) noexcept(false)

(2) void count(const Criteria &criteria, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept

Function overload

Synopsis

#include <orm_lib/inc/drogon/orm/Mapper.h>

size_t count(const Criteria &criteria=Criteria()) noexcept(false)

Description

Get the count of rows that match the given criteria.

Parameters:

criteria - The criteria.

Return
size_t The number of rows.

Source

Lines 1062-1085 in orm_lib/inc/drogon/orm/Mapper.h. Line 399 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline size_t Mapper<T>::count(const Criteria &criteria) noexcept(false)
{
    std::string sql = "select count(*) from ";
    sql += T::tableName;
    if (criteria)
    {
        sql += " where ";
        sql += criteria.criteriaString();
        sql = replaceSqlPlaceHolder(sql, "$?");
    }
    clear();
    Result r(nullptr);
    {
        auto binder = *client_ << std::move(sql);
        if (criteria)
            criteria.outputArgs(binder);
        binder << Mode::Blocking;
        binder >> [&r](const Result &result) { r = result; };
        binder.exec();  // exec may be throw exception;
    }
    assert(r.size() == 1);
    return r[0][(Row::SizeType)0].as<size_t>();
}

Synopsis

#include <orm_lib/inc/drogon/orm/Mapper.h>

void count(const Criteria &criteria, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept

Description

Asynchronously get the number of rows that match the given criteria.

Parameters:

criteria - The criteria.

rcb - is clalled with the result.

ecb - is called when an error occurs.

Source

Lines 1086-1108 in orm_lib/inc/drogon/orm/Mapper.h. Line 409 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline void Mapper<T>::count(const Criteria &criteria,
                             const CountCallback &rcb,
                             const ExceptionCallback &ecb) noexcept
{
    std::string sql = "select count(*) from ";
    sql += T::tableName;
    if (criteria)
    {
        sql += " where ";
        sql += criteria.criteriaString();
        sql = replaceSqlPlaceHolder(sql, "$?");
    }
    clear();
    auto binder = *client_ << std::move(sql);
    if (criteria)
        criteria.outputArgs(binder);
    binder >> [=](const Result &r) {
        assert(r.size() == 1);
        rcb(r[0][(Row::SizeType)0].as<size_t>());
    };
    binder >> ecb;
}





Add Discussion as Guest

Log in to DocsForge