Function deleteOne
Summary
#include <orm_lib/inc/drogon/orm/Mapper.h>
(1) size_t deleteOne(const T &obj) noexcept(false)
(2) void deleteOne(const T &obj, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept
Function overload
Synopsis
#include <orm_lib/inc/drogon/orm/Mapper.h>
size_t deleteOne(const T &obj) noexcept(false)
Description
Delete a record from the table.
- Parameters
obj
- The record.- Returns
- size_t The number of deleted records.
- Note
- The table must have a primary key.
Mentioned in
- Controller Introduction / Controller HttpController / Usage
Source
Lines 1325-1348 in orm_lib/inc/drogon/orm/Mapper.h. Line 541 in orm_lib/inc/drogon/orm/Mapper.h.
template <typename T>
inline size_t Mapper<T>::deleteOne(const T &obj) 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;
sql += " "; // Replace the last ','
makePrimaryKeyCriteria(sql);
sql = replaceSqlPlaceHolder(sql, "$?");
Result r(nullptr);
{
auto binder = *client_ << std::move(sql);
outputPrimeryKeyToBinder(obj.getPrimaryKey(), 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 deleteOne(const T &obj, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept
Description
Asynchronously delete a record from the table.
- Parameters
obj
- The record.rcb
- is called with the number of deleted records.ecb
- is called when an error occurs.- Note
- The table must have a primary key.
Mentioned in
- Controller Introduction / Controller HttpController / Usage
Source
Lines 1349-1368 in orm_lib/inc/drogon/orm/Mapper.h. Line 551 in orm_lib/inc/drogon/orm/Mapper.h.
template <typename T>
inline void Mapper<T>::deleteOne(const T &obj,
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;
sql += " ";
makePrimaryKeyCriteria(sql);
sql = replaceSqlPlaceHolder(sql, "$?");
auto binder = *client_ << std::move(sql);
outputPrimeryKeyToBinder(obj.getPrimaryKey(), binder);
binder >> [rcb](const Result &r) { rcb(r.affectedRows()); };
binder >> ecb;
}