hhtokpinar / sqfEntity

SqfEntity ORM for Flutter/Dart lets you build and execute SQL commands on SQLite database easily and quickly with the help of fluent methods similar to .Net Entity Framework. SqfEntity also generates add/edit forms with validations and special controls (DropDown List, DateTime pickers, Checkboxes.. etc) for your table.
379 stars 101 forks source link

Rollback mechanism #265

Closed SrujanMungara closed 2 years ago

SrujanMungara commented 2 years ago

How can i perform a rollback on a transactional DB?

hhtokpinar commented 2 years ago

Hi, You can perform a rollback just like below:

  await MyDbModel().batchStart();
  try {
    for (final obj in productList) {
      await obj.save(ignoreBatch: false); // Remember, if you use CRUD methods without the ignoreBatch parameter
                                         // it will be sent default with true, 
                                         // so it causes to perform the action out of the transaction 
    }
    final List<dynamic>? result = await MyDbModel().batchCommit();
  } catch (e) {
    MyDbModel().batchRollback();
  }
SrujanMungara commented 2 years ago

Thank you. it has worked