-
Notifications
You must be signed in to change notification settings - Fork 5
Support complex & array types in native query creation cli utility #742
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
base: main
Are you sure you want to change the base?
Conversation
|
Can we add tests for this functionality? |
…al to single dimensional arrays
Fix redundant continue statements to make compiler happy
| } | ||
| } | ||
|
|
||
| for (composite_type_name, info) in &configuration.metadata.composite_types.0 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
foundsince that becomes redundant
We could, alternatively, use break, and keep found if we think that's more readable?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this good?
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.