Repository navigation
feat: end each statement with a comment naming its file - #43
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Important
Two things to fix before merge. In a running dev server, turning sqlcommenter on or off doesn't reach the build until a restart. The docs also say Cloud SQL Query Insights reads the file tag, but it drops that key.
Reviewed changes
I reviewed the opt-in sqlcommenter key end to end: the engine config, the comment builder, the build-step module, the type check's declaration and the docs.
- Config key:
sqlcommenter: Option<bool>on the engine'sProject, with all threeengine.wasmfiles rebuilt.resolveProjectdefaults it tofalse. withSqlcommenter: adds/*file='…'*/before any closing semicolon. After a--or#on the last line, the tag goes on a new line.encodeURIComponentencodes/,?,:and$, so the tag can't contain*/or a placeholder.tests/sqlcommenter.test.tspasses locally.sourceName: the query'ssourcenow comes from the file's own project. This matches the oldrelative(session.project.root, path), becauseSession.forresolves frompackageDir(dirname(path))too.- Loader and mapper: the module's
sql/textand the declaredsqlliteral both carry the tag. Structured-list offsets are still correct, because the tag only adds text at the end. The mapper'sconfigIdentityincludes the new flag. - Docs: the key is in the Configuration example and has its own section.
claude-opus-5-5 | 𝕏
There was a problem hiding this comment.
✅ No new issues found. Both must-fix items and the nit from the previous review are fixed.
Reviewed changes
This run covered 7ca1cdd, the one commit pushed since the previous review.
- Session cache key:
Session.fornow addsproject.sqlcommenterto its cache key. If the project file turns the key on or off, the next module gets a new session, so the module'ssqlmatches what the mapper declares. A session left behind this way closes its connection afterBUILD_IDLE, the same as whenurlchanges today. - Test:
tests/compiled.test.tsno longer closes sessions before the second build. It now tests the real case: a running build step picking up the change without a restart. - Docs and comments: removed the Cloud SQL Query Insights claim from the Configuration section and the
src/sqlcommenter.tsheader. - Loader: moved the structured-offsets comment back above the
structuredline.
claude-opus-5-5 | 𝕏
Every statement a build step writes ends with /*file='queries%2Fget_user.sql'*/ in sqlcommenter's format, so database monitoring that reads it groups statements by file. The sql doc comment shows the statement without it.
7ca1cdd to
d991d85
Compare
There was a problem hiding this comment.
✅ No new issues found. The branch was squashed and reworked so the comment is always on; I re-read the full diff.
Reviewed changes
The force-push to d991d85 removed the opt-in setting. Every built statement now gets the comment.
- Removed the
sqlcommenterkey: the engine config change, the rebuiltengine.wasmfiles, theSession.forcache-key change and the Configuration docs section are all gone. With no setting, a running build and the type check can't disagree about whether the comment is there. - Kept
withSqlcommenteras it was: trailing whitespace and;are trimmed, the tag goes before a closing;, and after a--or#on the last line it starts a new line. The compiled text no longer ends with a newline, and the tests now expect that.tests/sqlcommenter.test.tspasses locally on Node 24. - Made the declared
sqlmatch the module: the mapper now computessourceName(p.fileName)from the file's own project, the same way the loader does. Thesqldoc comment shows the text without the tag, since a doc comment can't contain*/.sourceis still typed asstring. - Updated the docs capture:
site/scripts/capture-types.tsfollows the mapper, using the block's name as the source, andsql-modules.jsonwas recaptured.02-usage.mdxgained one sentence andSQL_NOTEnow mentions the ending comment.
claude-opus-5-5 | 𝕏

Every statement a build step writes now ends with a comment naming its
.sqlfile, in sqlcommenter's format. It's always on, with no setting:Database monitoring that reads sqlcommenter tags (Datadog Database Monitoring, PlanetScale's query insights) then groups statements by file with no hook in the app, and
pg_stat_activityand slow-query logs show it as written. Cloud SQL Query Insights keeps only its six fixed tag names, so it ignoresfile.src/sqlcommenter.ts): at the end of the statement and before a closing semicolon. The path is URL-encoded, and a quote is escaped as the spec writes a value. After a line comment (--, or MySQL's#) it starts a line of its own, so the line comment cannot swallow it. The file is its one tag, so the text is the same on every call and a driver's statement cache keeps it. URL encoding leaves no?,:or$in it, so no driver reads a placeholder there.sql, which.run()sends) and the type check's declaration ofsqlcarry the same text. The path is the query's.source, computed from the file's own project in both (sourceNameinsrc/project.ts). A query defined by hand has none.sqldoc comment shows the statement without the comment, since a doc comment cannot hold its*/. The type itself shows the full text, and the note now says a comment naming the file ends it..sql, and the captured hover types regenerated (nub run capture).Test plan
nub run typechecknub run testagainst throwaway Postgres 18 and MySQL 8.4: 207 pass. The one failure, "SQLite: JSON a statement builds is the object its type says…", fails the same way onmainunder Node 26.11: itsnode:sqliteruns SQLite 3.54.1, which drops a nestedjson_group_array's JSON subtype. CI's Node 24 is unaffected; that bug gets its own PR.tests/sqlcommenter.test.ts: placement (plain, trailing newline, semicolon, a line comment, MySQL's#), encoding and escaping; every form prepared and run on SQLitesql, its declaration and the editor hover (tests/compiled.test.ts,tests/analyze.test.ts,tests/definition.test.ts). The cast tests check the comment once in their helper and compare the cast text without it.site:nub run capture,nub run build; the.sqlsection checked at desktop and phone widths