[wip] Convert heavy generic CTEs to using the raw QueryBuilder #9432
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.
This isn't ready for prime-time - so, if you're reading this and not Sean, feel free to see what I'm up to, but know that this is not close to landing.
Where we've been
There are several CTE - and "CTE fragments" - we've attempted to make type-safe using Diesel. Many examples of these exist in
nexus/db-queries/src/db/queries- such as "find the next item in a set", or "attach a resource to a collection".Since these patterns attempted to fit in with Diesel's type system, they are notoriously heavy users of generics. These cause a lot of work for the compiler, and have a pretty steep learning/editing curve.
What I'm trying to do
nexus/db-queries/src/db/raw_query_builder.rscontains some tools for creating arbitrary, string-based queries with Diesel. This PR tries to migrate the generic-heavy queries to use these underlying tools instead. Hopefully this provides a "similar enough" API, while giving sufficient flexibility and avoiding heavy compile-time overhead.Also, these spots are (IMO) where we encounter some of our most complex Diesel queries. If we can convert these to use Diesel, the rest of e.g. integration with https://github.com/oxidecomputer/biofuel becomes significantly easier.
I'm diving into these head-first to understand what the hardest challenges for biofuel integration would be.
Code I've touched in this PR
FYI - this should definitely be smaller - but I'm using it as a bit of a prototype.
Problems I'm still facing
omicron.public.instancetable and thedb::model::Instancestruct are not aligned. I had to use some hacks to get all column names in matching order, which I'd like to clean up.