Skip to content

Commit

Permalink
fix: "Cannot commit, no transaction is active" error in sql.js (#9234)
Browse files Browse the repository at this point in the history
* fix: fix "Cannot commit, no transaction is active" error in sql.js

Closes: #9100

* Flush database only if transaction is done

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
  • Loading branch information
Obiwan1995 and Obiwan1995 committed Sep 19, 2022
1 parent 83f7b88 commit 749809a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/driver/sqljs/SqljsDriver.ts
Expand Up @@ -199,9 +199,10 @@ export class SqljsDriver extends AbstractSqliteDriver {
* If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,
* otherwise the save method is called which saves it to file (Node.js), local storage (browser)
* or indexedDB (browser with enabled useLocalForage option).
* Don't auto-save when in transaction as the call to export will end the current transaction
*/
async autoSave() {
if (this.options.autoSave) {
if (this.options.autoSave && !this.queryRunner?.isTransactionActive) {
if (this.options.autoSaveCallback) {
await this.options.autoSaveCallback(this.export())
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/driver/sqljs/SqljsQueryRunner.ts
Expand Up @@ -66,7 +66,9 @@ export class SqljsQueryRunner extends AbstractSqliteQueryRunner {
*/
async commitTransaction(): Promise<void> {
await super.commitTransaction()
await this.flush()
if (!this.isTransactionActive) {
await this.flush()
}
}

/**
Expand Down

0 comments on commit 749809a

Please sign in to comment.