Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex & array types in native query creation cli utility #742

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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
@@ -22,6 +24,37 @@ pub enum Kind {
Mutation,
}

/// Recursively figure out the underlying type oid for a given type
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we tested what happens with nested arrays with all this? IIRC Postgres introspection of those isn't great.

@danieljharvey
Copy link
Contributor

Can we add tests for this functionality?

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