tauri-apps / tauri-apps/plugins-workspace
[sql] Add support for transactions
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 602
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
Here's the method I use to execute a bunch of queries within a transaction:
```
async executeTransaction(transaction: Transaction): Promise {
let wasError: boolean = false;
try {
this._db.execute('BEGIN;');
await transaction();
} catch (err) {
wasError = true;
this._db.execute('ROLLBACK;');
throw err;
} finally {
if (!wasError) {
this._db.execute('COMMIT;');
}
}
}
```
Example:
```
await db.executeTransaction(async () => {
// A bunch of await db.execute() statements
});
```
When I do this, and throw an error, rollback is executed, but rollback doesn't take place.
Contributor guide
Assessment
This issue has not been assessed yet.