Skip to content

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

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

sqlite: add StatementSync.prototype.close() and [Symbol.dispose]()#64232
araujogui wants to merge 3 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
Comment thread src/node_sqlite.cc Outdated
@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.

araujogui added 2 commits July 3, 2026 20:14
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Expose an explicit close() method on StatementSync that finalizes
the prepared statement, mirroring DatabaseSync.prototype.close().
Unlike Symbol.dispose, close() throws if the statement is already
finalized, so Dispose() is reintroduced as a thin wrapper that
swallows that exception to keep statement[Symbol.dispose]() a
no-op on an already-finalized statement.

Also add "throws if the statement is already finalized" test
coverage for get(), all(), iterate(), run(), sourceSQL,
expandedSQL, setReadBigInts(), setReturnArrays(),
setAllowBareNamedParameters(), and setAllowUnknownNamedParameters(),
matching the check already present in each of these methods'
native implementation. These tests use in-memory databases with
`using` declarations for explicit resource management, matching
the convention used by the neighboring Symbol.dispose() suite.

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
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.

5 participants