sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Is it possible to use transaction with web worker?

Open quolpr opened this issue 4 years ago • 0 comments

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?

quolpr avatar Oct 21 '21 09:10 quolpr