diff --git a/.changeset/chilled-birds-cheer.md b/.changeset/chilled-birds-cheer.md new file mode 100644 index 000000000..9d9fedc55 --- /dev/null +++ b/.changeset/chilled-birds-cheer.md @@ -0,0 +1,5 @@ +--- +'@powersync/web': patch +--- + +Use `BEGIN EXCLUSIVE` to open write transactions diff --git a/packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts b/packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts index bd41da199..35c8dfa0d 100644 --- a/packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts +++ b/packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts @@ -196,7 +196,7 @@ export class LockedAsyncDatabaseAdapter } writeTransaction(fn: (tx: Transaction) => Promise, options?: DBLockOptions | undefined): Promise { - return this.writeLock(this.wrapTransaction(fn)); + return this.writeLock(this.wrapTransaction(fn, true)); } private generateDBHelpers< @@ -240,9 +240,9 @@ export class LockedAsyncDatabaseAdapter /** * Wraps a lock context into a transaction context */ - private wrapTransaction(cb: (tx: Transaction) => Promise) { + private wrapTransaction(cb: (tx: Transaction) => Promise, write = false) { return async (tx: LockContext): Promise => { - await this._execute('BEGIN TRANSACTION'); + await this._execute(write ? 'BEGIN EXCLUSIVE' : 'BEGIN'); let finalized = false; const commit = async (): Promise => { if (finalized) {