feat: Add native bindings for sqlite3_interrupt and sqlite3_is_interrupted - #404
feat: Add native bindings for sqlite3_interrupt and sqlite3_is_interrupted#404dariyooo wants to merge 2 commits into
sqlite3_interrupt and sqlite3_is_interrupted#404Conversation
I agree this doesn't make sense for WASM.
I think this should be a stable API. We expose a separate interface for native-only methods that inherits from
This requires pretty significant changes to the isolate code in drift. Currently, isolates essentially act as servers running SQL statements, so the server isolate would be blocked for the entire duration of the connection. We don't currently share actual SQLite connections across threads, which would be necessary if we want a client isolate to be able to interrupt a connection it doesn't own. Maybe we could add this API to the Before landing this, it would be good to have a more complete plan for the approach here (especially how this would be wired up in drift). That can either be a WIP PR on drift depending on these unreleased changes, or at least some rough outline of an approach. |
|
That works, I'll add Claude and I had a look at The one thing that needs a decision is the rule that a pool connection must never be used concurrently. Which of the two should I plan for? I would like to use this in an app in about 4-5 months. If drift moving onto the pool lands within that (or kinda close), I would rather wait for it and put the work into the pool and leaving drift's isolate code alone. If it is significantly further out, I would need the drift side changes and would look more closely at it. |
Add bindings for
sqlite3_interruptandsqlite3_is_interruptedTwo declarations in
assets/sqlite3.h, the rest istool/generate_bindings.dartoutput. No public API, they only show up inunstable/ffi_bindings.dart, plus theused_symbolsentries so the symbols survive asource:build.sqlite3_is_interruptedneeds SQLite 3.41+, same situation assqlite3_error_offsetwhich is already bound.I need it to cancel superseded queries in an interactive search. Nothing in Dart can stop a statement that already sits in
sqlite3_step, since the isolate running it never gets to read a cancellation message andIsolate.killhas no safepoint to land on.I left wasm out because that build is single threaded and every worker has its own memory, so nothing could call interrupt while a statement runs. Easy to add if you disagree.
What I'm actually after is drift interrupting the connection when a request is cancelled, so it can stop a statement that is already running instead of only skipping ones that have not started yet. The isolate doing that never owns the
Database, it only has the handle address, so drift would have to go throughunstable/ffi_bindings.dart. Is that fine to depend on, or would you rather expose something stable taking aPointer<void>? I can move this to a drift issue if you'd rather keep it out of here.