Function deleteFutureOne

Synopsis

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

std::future< size_t > deleteFutureOne(const T &obj) noexcept

Description

Asynchronously delete a record from the table.

Parameters:

obj - The record.

Return
std::future<size_t> The future object with which user can get the number of deleted records.
Note
The table must have a primary key.

Source

Lines 1391-1413 in orm_lib/inc/drogon/orm/Mapper.h. Line 574 in orm_lib/inc/drogon/orm/Mapper.h.

template <typename T>
inline std::future<size_t> Mapper<T>::deleteFutureOne(const T &obj) 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;
    sql += " ";

    makePrimaryKeyCriteria(sql);

    sql = replaceSqlPlaceHolder(sql, "$?");
    auto binder = *client_ << std::move(sql);
    outputPrimeryKeyToBinder(obj.getPrimaryKey(), 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