-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autorollback functionality for database #1386
Comments
A transaction will rollback automatically on any query failure. |
Thank you for your answer. In drogon when the Transaction object is destructed, the commit statement is automatically executed to end the transaction. But i need the opposite. I meant this. |
We could add a There is also an easy solution without any changes on the library. class TransactionAutoRollback
{
public:
TransactionAutoRollback(std::shared_ptr<Transaction> &&trans)
: trans_(std::move(trans))
{
}
~TransactionAutoRollback()
{
if (trans_)
trans_->rollback();
}
const std::shared_ptr<Transaction> &get()
{
return trans_;
}
void commit(const std::function<void(bool)> &commitCallback)
{
if (trans_)
{
if (commitCallback)
{
trans_->setCommitCallback(commitCallback);
}
trans_.reset();
}
}
private:
std::shared_ptr<Transaction> trans_;
}; |
@an-tao Can we add setAutoCommit(bool) funtion for Transaction class? I really need it. |
if adding autorollback functionality is impossible, please uncomment commit() function in transaction class.
class Transaction : public DbClient
{
public:
virtual void rollback() = 0;
// virtual void commit() = 0;
virtual void setCommitCallback(
const std::function<void(bool)> &commit Callback) = 0;
void closeAll() override
{
}
};
The text was updated successfully, but these errors were encountered: