Skip to content

Clarification on what read concurrency + write serialization means in implementation? #142

Answered by rhashimoto
abhay-agarwal asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, I can see how this could be confusing. The underlying SQLite C library API returns integer result codes from almost every function, but my JavaScript wrapper API throws an exception for most codes that are not SQLITE_OK, including SQLITE_BUSY. This is an opinionated policy to prevent lazy developers (e.g. me) from ignoring the return codes. The original code is available as the property "code" on the exception object.

You should handle this in a try/catch block or rejected Promise handler. So something like:

while (true) {
  try {
    // Execute some SQL transaction, e.g.:
    const results = [];
    await sqlite3.exec(`
      BEGIN IMMEDIATE;
      ...
      COMMIT;
    `, (row, columns

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@abhay-agarwal
Comment options

@rhashimoto
Comment options

Answer selected by abhay-agarwal
@abhay-agarwal
Comment options

@rhashimoto
Comment options

@abhay-agarwal
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants