tauri-apps / tauri-apps/plugins-workspace

[sql] Add support for transactions

Open
#886 13 comments 13 reactions 0 assignees View on GitHub
plugin: sql status: help wanted type: feature request
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.