Skip to content

Expose sqlite3_interrupt() as db.interrupt() — closes #406#407

Merged
ospfranco merged 4 commits into
OP-Engineering:mainfrom
benhoweblog-dot:feat-expose-sqlite3-interrupt
May 19, 2026
Merged

Expose sqlite3_interrupt() as db.interrupt() — closes #406#407
ospfranco merged 4 commits into
OP-Engineering:mainfrom
benhoweblog-dot:feat-expose-sqlite3-interrupt

Conversation

@benhoweblog-dot
Copy link
Copy Markdown
Contributor

Closes #406.

Summary

Exposes SQLite's native sqlite3_interrupt() as a db.interrupt() method on the database handle. It aborts any pending operation on the connection, is safe to call from a different thread per SQLite's contract, and rolls back in-flight transactions on interrupt.

Changes

  • cpp/DBHostObject.cpp - JSI binding that calls sqlite3_interrupt(db) on the underlying connection
  • src/functions.ts / src/types.ts - TypeScript wrapper and DB interface exposing interrupt(): void
  • src/functions.web.ts - explicit unsupported web stub for type/API parity
  • docs/docs/api.md and README.md - documentation for the new API
  • example/src/tests/queries.ts - tests for no-op interrupt and aborting a long recursive CTE with rollback

Why

Without this, JS-side timeouts on long queries can only mark a query "cancelled" at the orchestration layer; the underlying SQLite work continues to consume resources until it naturally finishes or the app is killed. This aligns op-sqlite with other SQLite bindings that expose this primitive.

Filed as a need by Pangea, a React Native health/nutrition app. The same need has also been raised in the JS SQLite ecosystem against sql-js/sql.js as sql-js/sql.js#545.

Testing

  • corepack yarn typecheck
  • corepack yarn test:node
  • git diff --check

I wasn't able to run the React Native native example suite in this environment, but I added example coverage for the native API path.

Happy to iterate on API name, error surface, docs wording, or test placement.

Comment thread cpp/DBHostObject.cpp
Comment thread cpp/DBHostObject.cpp
Comment thread example/src/tests/queries.ts Outdated

const queryPromise = db.execute(longQuery);

await new Promise((resolve) => setTimeout(resolve, 50));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is already a sleep function somewhere on the test suite, please use that

@benhoweblog-dot
Copy link
Copy Markdown
Contributor Author

Round 2 updates pushed. Addressed the three review items: added Turso handling/docs for interrupt(), call sqlite3_interrupt() from close()/delete() before teardown on native SQLite builds with a regression test for close() during an in-flight long query, and switched the interrupt test delay to the shared sleep() helper. Verification passed locally: git diff --check, corepack yarn typecheck, corepack yarn test:node.

@benhoweblog-dot benhoweblog-dot requested a review from ospfranco May 19, 2026 02:13
@benhoweblog-dot benhoweblog-dot force-pushed the feat-expose-sqlite3-interrupt branch from 097f70c to 7ba0a9a Compare May 19, 2026 02:27
@benhoweblog-dot
Copy link
Copy Markdown
Contributor Author

Rebased on upstream/main to resolve the conflicts in cpp/DBHostObject.cpp and src/types.ts. No logic changes from the round-2 review fixes — purely merge resolution. All 4 commits preserved on top of the new base. Local verification passed (typecheck + test:node + git diff --check). Ready for re-review when convenient.

@ospfranco ospfranco merged commit eca9a72 into OP-Engineering:main May 19, 2026
19 of 20 checks passed
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.

Feature: expose sqlite3_interrupt() to allow cancellation of in-flight queries

2 participants