sql-js / sql-js/sql.js

Is it possible to use transaction with web worker?

Open
#490 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I am just curious, will the transaction work as expected if I do this:

    worker.postMessage({
      id: 2,
      action: "exec",
      sql: "BEGIN TRANSACTION"
    });

    worker.postMessage({
      id: 3,
      action: "exec",
      sql: "INSERT ...",
      params: { "$id": 1 }
    });

    worker.postMessage({
      id: 4,
      action: "exec",
      sql: "INSERT ...",
      params: { "$id": 2 }
    });


    worker.postMessage({
      id: 5,
      action: "exec",
      sql: "COMMIT"
    });

How can I be sure, that only id 3, 4 will be committed in the current transaction? I mean, after the transaction started I can't guarantee that other async codes could be executed that could not relate to the current transaction(for example, when setTimeout happens). Is there something like the ID of the transaction, under which other queries should be executed?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by reviewing how web-worker exec messages are handled and how SQLite transactions span asynchronous calls. Done would require a documented answer or a clearly scoped change, but the issue does not define which.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, sqlite
Domain
database, web-dev
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.