[nexus] use raw query builder for sitrep version insertion CTE #9380
+265
−304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #9335.
In this comment on PR #9335, @smklein suggested using the
raw_query_builderAPI for writing CTEs, rather than using Diesel'sQueryFragmentAPI. This turns out to be a lot less unpleasant and, despite performing less validation of the generated SQL, actually is a lot less likely to introduce hard-to-debug SQL syntax errors. Since most of the query can be written in a single string literal, you actually see more or less what you're gonna get, which is much less obvious with Diesel's API. TheInsertSitrepVersionQueryCTE in the same module still uses theQueryFragmentAPI, rather than theraw_query_buildermodule, since I didn't want to change the existing code in that branch.This PR refactors the CTE for inserting a new sitrep version to also use
raw_query_builder, which is much nicer and should be easier to modify in the future. There should be no functional changes here, just a change to use a different API to generate the query.Incidentally, this was one of the first times I had real success getting Claude to do a fairly trivial "transform this code from using one API to using another" task --- it wrote most of the first commit, and I tweaked some of its style decisions I didn't love.