qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead of delete it from database
A soft delete doesn't remove rows from database (this is not a physical delete) : a new column is added to the table definition to flag a row as deleted or not. This column can contain a boolean (1 means row deleted, 0 or NULL means row not deleted), or can contain deletion date-time (if empty or NULL, row is not deleted). So you can reactivate a deleted row by setting NULL or empty value into database.
To define a soft delete behavior with QxOrm library, you have to use the class qx::QxSoftDelete in function mapping by class qx::register_class<T>. Here is an example with the class Bar containing 2 properties m_id and m_desc :
{
t.
data(& Bar::m_desc,
"desc");
}}
void setSoftDelete(const qx::QxSoftDelete &o)
qx::QxClass<T> : concrete class of type T registered into QxOrm context (this class is a singleton an...
IxDataMember * id(type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion=0)
IxDataMember * data(const QString &sKey, long lVersion)
qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as...
void register_class(T &t)
qx::register_class<T>(T & t) : specialize this template to register a class of type T into QxOrm cont...
Root namespace for all QxOrm library features.
SQL queries builded by QxOrm library will take into account this soft delete parameter to add conditions (don't fetch deleted item, don't delete physically a row, etc.). For example, if you execute this code with the class Bar :
Bar_ptr pBar; pBar.reset(new Bar());
pBar->setId(5);
qx_bool : boolean type with code and description message when an error occured
QSqlError destroy_all(QSqlDatabase *pDatabase=NULL)
Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context),...
QSqlError delete_by_id(T &t, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Delete a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered i...
qx_bool exist(T &t, QSqlDatabase *pDatabase=NULL)
Search if an element (or list of elements) already exists into database.
QSqlError delete_all(QSqlDatabase *pDatabase=NULL)
Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context)
long count(const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm c...
You will obtain following output trace :
[QxOrm] sql query (93 ms) : UPDATE Bar SET deleted_at = '20110617115148615' WHERE id = :id
[QxOrm] sql query (0 ms) : SELECT Bar.id AS Bar_id_0, Bar.deleted_at FROM Bar WHERE Bar.id = :id AND (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
[QxOrm] sql query (78 ms) : UPDATE Bar SET deleted_at = '20110617115148724'
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM Bar WHERE (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
[QxOrm] sql query (110 ms) : DELETE FROM Bar
Note : To delete physically a row from database, you have to use followings functions : qx::dao::destroy_by_id() and qx::dao::destroy_all().
Other note : it is recommended to define into database an index on column deleted_at to optimize execution of SQL queries.
Definition at line 96 of file QxSoftDelete.h.