Function deleteBy

Summary

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

(1) size_t deleteBy(const Criteria &criteria) noexcept(false)

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

Function overload

Synopsis

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

size_t deleteBy(const Criteria &criteria) noexcept(false)

Description

Delete records that satisfy the given criteria.

Parameters

criteria - The criteria.

Returns
size_t The number of deleted records.

Source

Lines 1393-1421 in orm_lib/inc/drogon/orm/Mapper.h. Line 571 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline size_t Mapper<T>::deleteBy(const Criteria &criteria) noexcept(false)
{
    clear();
    static_assert(!std::is_same<typename T::PrimaryKeyType, void>::value,
                  "No primary key in the table!");
    std::string sql = "delete from ";
    sql += T::tableName;

    if (criteria)
    {
        sql += " where ";
        sql += criteria.criteriaString();
        sql = replaceSqlPlaceHolder(sql, "$?");
    }

    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();  // Maybe throw exception;
    }
    return r.affectedRows();
}

Synopsis

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

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

Description

Delete records that match the given criteria asynchronously.

Parameters

criteria - The criteria

rcb - is called with the number of deleted records.

ecb - is called when an error occurs.

Source

Lines 1422-1447 in orm_lib/inc/drogon/orm/Mapper.h. Line 580 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline void Mapper<T>::deleteBy(const Criteria &criteria,
                                const CountCallback &rcb,
                                const ExceptionCallback &ecb) noexcept
{
    clear();
    static_assert(!std::is_same<typename T::PrimaryKeyType, void>::value,
                  "No primary key in the table!");
    std::string sql = "delete from ";
    sql += T::tableName;

    if (criteria)
    {
        sql += " where ";
        sql += criteria.criteriaString();
        sql = replaceSqlPlaceHolder(sql, "$?");
    }

    auto binder = *client_ << std::move(sql);
    if (criteria)
    {
        criteria.outputArgs(binder);
    }
    binder >> [rcb](const Result &r) { rcb(r.affectedRows()); };
    binder >> ecb;
}





Add Discussion as Guest

Log in