Skip to content

Implement native query builder in the CLI plugin #511

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

Merged
merged 31 commits into from
Jul 4, 2024

Conversation

i-am-tom
Copy link
Contributor

@i-am-tom i-am-tom commented Jun 26, 2024

What

To improve the DX of native queries, we want a CLI interface with which we can point the CLI at a SQL(ish - a native query) file and generate the stanzas for V3 metadata. This PR sort of does it.

Design

Introduce the following subcommands:

Commands on Native Operations

Usage: ndc-postgres-cli native-operation <COMMAND>

Commands:
  list    List the existing Native Operations
  create  Create a new Native Operation from a SQL file
  delete  Delete an existing Native Operation from the configuration
  help    Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help

Create

Create a new Native Operation from a SQL file

Usage: ndc-postgres-cli native-operation create [OPTIONS] --operation-path <OPERATION_PATH> --kind <KIND>

Options:
      --operation-path <OPERATION_PATH>
          Relative path to the SQL file inside the connector configuration directory
      --kind <KIND>
          Operation kind [possible values: query, mutation]
      --override
          Override the Native Operation definition if it exists
  -h, --help
          Print help

Delete

Delete an existing Native Operation from the configuration

Usage: ndc-postgres-cli native-operation delete --name <NAME> --kind <KIND>

Options:
      --name <NAME>  The name of the Native Operation
      --kind <KIND>  Operation kind [possible values: query, mutation]
  -h, --help         Print help

List

List the existing Native Operations

Usage: ndc-postgres-cli native-operation list

Options:
  -h, --help  Print help

How

The user supplies a file containing SQL(ish - a native operation) code, and specifies the operation kind, and we use the sqlx describe method to fetch information about the operation. Specifically, whether it compiles or not, and what is the error if not, and what are the oids of the types of the arguments and returning columns.

From this information, we construct a NativeQueryInfo and add it to the configuration, then update it to fetch information about types we might not have tracked in the configuration yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

We add the new commands

@@ -227,6 +229,23 @@ impl From<NativeQueryParts> for String {
}
}

impl NativeQueryParts {
Copy link
Contributor

Choose a reason for hiding this comment

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

We introduce a method to prettyprint a native query.

Copy link
Contributor

Choose a reason for hiding this comment

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

We infer information about a Native Operation from a Native Operation SQL string.

/// with other tests.
///
/// If you have changed it intentionally, run `just generate-configuration`.
pub async fn introspection_is_idempotent(
Copy link
Contributor

Choose a reason for hiding this comment

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

we moved this here from the other tests file.

@soupi soupi changed the title [WIP] Implement native query builder in the CLI plugin Implement native query builder in the CLI plugin Jul 3, 2024
@soupi soupi marked this pull request as ready for review July 3, 2024 15:31
@i-am-tom
Copy link
Contributor Author

i-am-tom commented Jul 4, 2024

I'm not allowed to review this because GitHub thinks I wrote it, but I wanted to say that I'm a big fan and would approve it if I could

@i-am-tom i-am-tom enabled auto-merge July 4, 2024 09:05
Copy link
Contributor

@soupi soupi left a comment

Choose a reason for hiding this comment

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

obama meme

@i-am-tom i-am-tom added this pull request to the merge queue Jul 4, 2024
Merged via the queue into main with commit aa0100d Jul 4, 2024
31 checks passed
@i-am-tom i-am-tom deleted the gjm-tjh/native-query-cli branch July 4, 2024 09:14
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.

4 participants