Skip to content

Conversation

@BenoitRanque
Copy link
Contributor

What

The cli native query creation utility tries to figure out the argument & column types for the native query.

It currently assumes all columns & arguments are scalars, while the configuration supports array types & composite types.

This PR changes the utility to support composite types & array types.

How

We build on the existing system that uses sqlx utilities to describe a query. We get type info, then use the oid from that info to get a type name from the database.

We add an extra step, to check for arrays in the types, and if so get the underlying type before fetching an OID for that type.

We also add mapping to consider the type kind whether composite, scalar, or array, as we write the configuration.

We assume types are scalar if they're not composite nor array types. This matches previous behavior.

We also update a snapshot, which it turns out was wrong until this fix.

@BenoitRanque BenoitRanque requested a review from a team as a code owner April 3, 2025 21:53
@danieljharvey
Copy link
Contributor

Can we add tests for this functionality?

}
}

for (composite_type_name, info) in &configuration.metadata.composite_types.0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section was missing, and since v4 does have composite types I think this was a mistake

if info.schema_name == schema_name && info.type_name == type_name {
oids_map.insert(oid, scalar_type_name.inner().clone());
found = true;
continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This continue statement did nothing.

There's a couple options for intent:

  • either this was meant to be a break, to exit the inner loop on first match
  • or, the intent was to proceed to the next iteration of the outer loop

I think the intent was the latter, so

  • added label to loop
  • continue using label so the right loop is continued
  • removed found since that becomes redundant

We could, alternatively, use break, and keep found if we think that's more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that using break would mean we'd iterate over composite types always, even if we did find our type as a scalar

Using continue 'rows I think better matches the intent here:

  • iterate over rows
  • for each row, try to find a matching scalar type and insert that to the map
  • if no scalar found, try to find a matching composite
  • if neither found, use type name as is

"name": "characters",
"type": {
"scalarType": "characters"
"compositeType": "characters"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know why this changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this good?

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