Skip to content

[mssql] Report transactional SQL to onSqlCommand - #307

Open
nltgpeterskoglund wants to merge 1 commit into
tinyplex:mainfrom
nltgpeterskoglund:mssql-onsqlcommand
Open

nltgpeterskoglund wants to merge 1 commit into
tinyplex:mainfrom
nltgpeterskoglund:mssql-onsqlcommand

Conversation

@nltgpeterskoglund

Copy link
Copy Markdown
Contributor

Follow-up to #295, as offered there.

onSqlCommand never fires for the mssql Persister. createMsSqlPersister gives the driver-level Transaction an execute command of its own, and that one never passes through getWrappedCommand — so the statements the JSON persister runs inside the transaction bypass the callback entirely. For the same save(), better-sqlite3 reports six statements and mssql reports none, on load() as well as save().

The unit tests did not catch it because they drive createCustomMsSqlPersister directly, without an executeTransaction, which falls back to the shared implementation that does use the wrapped command. This adds a test that goes through the real entry point with a stand-in for ConnectionPool, so the transaction path is covered. I checked that it fails without the one-line change and passes with it.

Also run against SQL Server 2022 in a container: mssql.test.ts and the mssql variants of json.test.ts and mergeable-json.test.ts, 72 tests, all green.

This has been there since the original branch, so it is a fix to my own code rather than a regression. Based on main; the two files are identical on beta, so it applies there just as well if that is the better home for it.

🤖 Generated with Claude Code

The Persister gives the driver-level Transaction an execute command of its
own, which never went through getWrappedCommand. Since the JSON persister
does its work inside that transaction, the callback stayed silent for both
load() and save(), where the other database Persisters report every
statement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant