Skip to content

Conversation

@smklein
Copy link
Collaborator

@smklein smklein commented Nov 10, 2025

Hopefully this is a little more readable.

  • Adds a "query validation via EXPLAIN" test
  • Adds an "expectorate" test

@smklein smklein changed the title Bp query insert Re-write Blueprint Target Insertion using QueryBuilder Nov 10, 2025
@smklein smklein requested review from hawkw and jgallagher November 10, 2025 21:58
@smklein smklein marked this pull request as ready for review November 10, 2025 21:58
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is lovely. I had some minor suggestions, but most of them aren't important.

.sql(") IS NULL, '")
.sql(NO_SUCH_BLUEPRINT_SENTINEL)
.sql(
"', \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turbo nit: it looks kinda weird to me how the comma is not indented to where the previous expression would be, here...

}

#[tokio::test]
async fn insert_target_query_sql_snapshot() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, take it or leave it: most of the other tests of this form i've seen are named expectorate_{query}, maybe we should make them consistent?

}

#[tokio::test]
async fn insert_target_query_is_valid() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar nit: most of these tests are named explain_{query}; should we make this consistent? also, the expectorate test also checks for the query's validity...

Comment on lines +4830 to +4833
let _ = query
.to_query()
.explain_async(&conn)
.await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, take it or leave it: i find it useful to also eprintln! the EXPLAIN output in these, so that you can run cargo nextest run {name_of_test} --success-output final if you want to see the query plan.

also, the other EXPLAIN tests generally include assertions that there's no FULL SCAN in the explanation, is that worth having here?

Comment on lines +2938 to +2939
impl InsertTargetQuery {
fn to_query(self) -> TypedSqlQuery<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take it or leave it: now that this is using QueryBuilder, it doesn't really need to be its own struct; we could just have a function that takes the query parameters and returns a TypedSqlQuery. i think it only had to be a struct in order to implement the QueryFragment trait, but now we don't need a trait imp.

it's up to you whether you think it's cleaner to just have a free function or not, though 🤷‍♀️

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.

3 participants