Skip to content

sqlite: add StatementSync.prototype.close() and [Symbol.dispose]()#64232

Open
araujogui wants to merge 4 commits into
nodejs:mainfrom
araujogui:sqlite-statement-sync-dispose
Open

sqlite: add StatementSync.prototype.close() and [Symbol.dispose]()#64232
araujogui wants to merge 4 commits into
nodejs:mainfrom
araujogui:sqlite-statement-sync-dispose

Conversation

@araujogui

Copy link
Copy Markdown
Member

No description provided.

This extends explicit resource management support to prepared
statements, allowing a StatementSync to be deterministically
finalized via a `using` declaration, mirroring the existing
DatabaseSync and Session dispose methods.

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Copilot AI review requested due to automatic review settings July 1, 2026 14:22
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Jul 1, 2026

This comment was marked as low quality.

@aduh95 aduh95 added semver-minor PRs that contain new features and should be released in the next minor version. backport-requested-v24.x PRs awaiting manual backport to the v24.x-staging branch. labels Jul 2, 2026
@Renegade334

Copy link
Copy Markdown
Member

We are currently finalizing statements when the wrapper is deconstructed after GC. This PR only makes sense if we are going to change this to an explicit "user should finalize statements themselves" model, in which case we should also expose a named .finalize() method that does the same thing. If not, then this probably isn't a logical addition.

@araujogui

araujogui commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

We are currently finalizing statements when the wrapper is deconstructed after GC. This PR only makes sense if we are going to change this to an explicit "user should finalize statements themselves" model, in which case we should also expose a named .finalize() method that does the same thing. If not, then this probably isn't a logical addition.

I think we can support both approaches. I don't see any issue with that.

We can either let the GC finalize statements as they are today, or let users finalize them explicitly with a dispose() or the using keyword. The choice is theirs. Explicit finalization is very useful in memory-constrained environments.

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui araujogui changed the title sqlite: add StatementSync.prototype[Symbol.dispose]() sqlite: add StatementSync.prototype.close() and [Symbol.dispose]() Jul 4, 2026
Comment thread src/node_sqlite.cc Outdated
@jasnell

jasnell commented Jul 4, 2026

Copy link
Copy Markdown
Member

... We are currently finalizing statements when the wrapper is deconstructed after GC. This PR only makes sense if we are going to change this to an explicit "user should finalize statements themselves" model ...

Honestly, I'm not a fan at all of relying on GC timing. It's too unpredictable and can expose GC timing details (which can be problematic on its own). We originally had FileHandle automatically close on GC but have since backed away from that to require explicit closing. I think it makes sense to do the same here.

@Renegade334

Copy link
Copy Markdown
Member

That's the case I had in mind. I don't have a problem with the approach, we just need to be very clear to consumers that the contract is changing.

Comment thread src/node_sqlite.cc Outdated
araujogui added 2 commits July 4, 2026 12:58
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui araujogui force-pushed the sqlite-statement-sync-dispose branch from cb5696c to 9ed6fae Compare July 4, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested-v24.x PRs awaiting manual backport to the v24.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants