Skip to content

Instantly share code, notes, and snippets.

@mbdavid
Last active May 3, 2020 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbdavid/9a8daddb1fe8e73732cf156f5b622022 to your computer and use it in GitHub Desktop.
Save mbdavid/9a8daddb1fe8e73732cf156f5b622022 to your computer and use it in GitHub Desktop.
LiteDB v3 Transaction Syntax Options
// 1
db.BeginTrans();
// ... do stuffs
db.Commit(); // or db.Rollback();
// 2
using(var t = db.BeginTrans()) // where t is LiteTransaction
{
// ... do stuffs
t.Commit(); // or t.Rollback();
}
// 3
db.Transaction((t) => // where t is LiteTransaction
{
// ... do stuffs
t.Commit(); // or t.Rollback();
});
// Propose: 4
db.Transaction(() =>
{
// ... do stuffs
return true; //to commit (or false to rollback)
});
// Propose: 5
db.Transact(() =>
{
// ... do stuffs
// auto commit when finish ok or rollback if throws any exception
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment