Expose sqlite3_interrupt() as db.interrupt() — closes #406#407
Conversation
|
|
||
| const queryPromise = db.execute(longQuery); | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, 50)); |
There was a problem hiding this comment.
There is already a sleep function somewhere on the test suite, please use that
|
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. |
097f70c to
7ba0a9a
Compare
|
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. |
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.