Skip to content

Conversation

@smklein
Copy link
Collaborator

@smklein smklein commented Nov 20, 2025

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

  • CollectionAttach: Adds a new QueryBuilder-based approach. Old implementation still exists.
  • NextItem: Converts the API to use a QueryBuilder.
  • InsertVpcQuery was converted to use a QueryBuilder approach (it used NextItem).

Problems I'm still facing

  • Using the "CollectionAttach" CTE returns the "collection" and "resource" with all columns in a way that should be enumerated in "model order". However the omicron.public.instance table and the db::model::Instance struct are not aligned. I had to use some hacks to get all column names in matching order, which I'd like to clean up.

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.

2 participants