Function deleteFutureBy

Synopsis

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

std::future< size_t > deleteFutureBy(const Criteria &criteria) noexcept

Description

Delete records that match the given criteria asynchronously.

Parameters:

criteria - The criteria

Return
std::future<size_t> The future object with which user can get the number of deleted records

Source

Lines 1470-1497 in orm_lib/inc/drogon/orm/Mapper.h. Line 602 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline std::future<size_t> Mapper<T>::deleteFutureBy(
    const Criteria &criteria) 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);
    }

    std::shared_ptr<std::promise<size_t>> prom =
        std::make_shared<std::promise<size_t>>();
    binder >> [=](const Result &r) { prom->set_value(r.affectedRows()); };
    binder >> [=](const std::exception_ptr &e) { prom->set_exception(e); };
    binder.exec();
    return prom->get_future();
}





Add Discussion as Guest

Log in to DocsForge