Expose sqlite3_interrupt() as db.interrupt() — closes #406#407
Open
benhoweblog-dot wants to merge 1 commit into
Open
Expose sqlite3_interrupt() as db.interrupt() — closes #406#407benhoweblog-dot wants to merge 1 commit into
benhoweblog-dot wants to merge 1 commit into
Conversation
ospfranco
requested changes
May 18, 2026
| #ifdef OP_SQLITE_USE_LIBSQL | ||
| throw std::runtime_error("[op-sqlite][interrupt] sqlite3_interrupt is not " | ||
| "supported with libsql"); | ||
| #else |
| throw std::runtime_error("[op-sqlite][interrupt] database is null"); | ||
| } | ||
|
|
||
| sqlite3_interrupt(db); |
Contributor
There was a problem hiding this comment.
You also probably want to call interrupt on close() and delete()?
|
|
||
| const queryPromise = db.execute(longQuery); | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, 50)); |
Contributor
There was a problem hiding this comment.
There is already a sleep function somewhere on the test suite, please use that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #406.
Summary
Exposes SQLite's native
sqlite3_interrupt()as adb.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 callssqlite3_interrupt(db)on the underlying connectionsrc/functions.ts/src/types.ts- TypeScript wrapper and DB interface exposinginterrupt(): voidsrc/functions.web.ts- explicit unsupported web stub for type/API paritydocs/docs/api.mdandREADME.md- documentation for the new APIexample/src/tests/queries.ts- tests for no-op interrupt and aborting a long recursive CTE with rollbackWhy
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.jsas sql-js/sql.js#545.Testing
corepack yarn typecheckcorepack yarn test:nodegit diff --checkI 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.