Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilled-birds-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/web': patch
---

Use `BEGIN EXCLUSIVE` to open write transactions
6 changes: 3 additions & 3 deletions packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class LockedAsyncDatabaseAdapter
}

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

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