Skip to content

Fix readTransaction errors on node and op-sqlite drivers#941

Merged
simolus3 merged 4 commits into
mainfrom
read-transaction-fix
May 6, 2026
Merged

Fix readTransaction errors on node and op-sqlite drivers#941
simolus3 merged 4 commits into
mainfrom
read-transaction-fix

Conversation

@simolus3

@simolus3 simolus3 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Currently, we run a BEGIN IMMEDIATE statement to start transactions (both readonly and readwrite). Technically, we're not really supposed to use BEGIN IMMEDIATE for readonly transactions since that statement is documented as taking a write lock, but for readonly connections in WAL mode it's still very convenient because there it uses the current state of the database as a snapshot. This has benefits over a regular BEGIN because writes between the start of the readonly transaction and its first statement would not be seen (ensuring the entire readTransaction block forms a logical transaction).

If we use readwrite connections with pragma query_only = TRUE however, attempting to use BEGIN IMMEDIATE throws and we shouldn't do it. So, this PR:

  1. Changes the Node SDK to use readonly connections instead of the pragma query_only workaround.
  2. Changes the common package to avoid BEGIN IMMEDIATE for connections using the pragma query_only = TRUE workaround (which is the case for op-sqlite which can't open actual readonly connections).
  3. Adds tests for both behaviors to the node, op-sqlite and web pacakges.

@changeset-bot

changeset-bot Bot commented May 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 12c4def

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@powersync/node Patch
@powersync/common Patch
@powersync/op-sqlite Patch
@powersync/adapter-sql-js Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@simolus3 simolus3 requested a review from stevensJourney May 4, 2026 14:42

@stevensJourney stevensJourney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me

Comment thread packages/common/src/db/DBAdapter.ts
@simolus3 simolus3 force-pushed the read-transaction-fix branch from 4d04b90 to 12c4def Compare May 5, 2026 12:55
@simolus3 simolus3 marked this pull request as ready for review May 5, 2026 12:58
@simolus3 simolus3 merged commit 947ca21 into main May 6, 2026
11 checks passed
@simolus3 simolus3 deleted the read-transaction-fix branch May 6, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants