Last active
May 3, 2020 19:39
-
-
Save mbdavid/9a8daddb1fe8e73732cf156f5b622022 to your computer and use it in GitHub Desktop.
LiteDB v3 Transaction Syntax Options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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