Skip to content

Commit 3f3f25b

Browse files
committed
Web: Use BEGIN EXCLUSIVE for write transactions
1 parent 8a9a5dc commit 3f3f25b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/chilled-birds-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/web': patch
3+
---
4+
5+
Use `BEGIN EXCLUSIVE` to open write transactions

packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class LockedAsyncDatabaseAdapter
196196
}
197197

198198
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T> {
199-
return this.writeLock(this.wrapTransaction(fn));
199+
return this.writeLock(this.wrapTransaction(fn, true));
200200
}
201201

202202
private generateDBHelpers<
@@ -240,9 +240,9 @@ export class LockedAsyncDatabaseAdapter
240240
/**
241241
* Wraps a lock context into a transaction context
242242
*/
243-
private wrapTransaction<T>(cb: (tx: Transaction) => Promise<T>) {
243+
private wrapTransaction<T>(cb: (tx: Transaction) => Promise<T>, write = false) {
244244
return async (tx: LockContext): Promise<T> => {
245-
await this._execute('BEGIN TRANSACTION');
245+
await this._execute(write ? 'BEGIN EXCLUSIVE' : 'BEGIN');
246246
let finalized = false;
247247
const commit = async (): Promise<QueryResult> => {
248248
if (finalized) {

0 commit comments

Comments
 (0)