Skip to content

feat(codegen): Remove Go-specific overrides from codegen proto #2929

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 14 commits into from
Oct 31, 2023

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Oct 30, 2023

As part of our long-term plans for additional languages, we're cleaning up the interface between sqlc and codegen plugins. This change removes the rename and overrides struct, as it had Go-specific information. In it's place is a plugin-agnostic global options block. The current Go-specific configuration looks like this:

version: "2"
overrides:
  go:
    rename:
      one: "ONE"
    overrides:
      - db_type: "text"
        go_type: "github.com/sqlc-dev/sqlc-testdata/pkg.CustomType"
      - column: "overrides.three"
        go_type:
          import: "github.com/sqlc-dev/sqlc-testdata/pkg"
          type: "CustomType"
sql:
- schema: "schema.sql"
  queries: "query.sql"
  engine: "postgresql"
  gen:
    go: 
      out: "db"
      rename:
        one: "ONE"
      overrides:
        - column: "overrides.three"
          go_type:
            import: "invalid/import"
            type: "ShouldNotSeeThis"

A two line change to use this with a theoretical Go plugin

version: "2"
plugins:
- name: go
  wasm:
    url: https://downloads.sqlc.dev/plugin/sqlc-gen-go_X.X.X.wasm
    sha256: ""
options:
  go:
    rename:
      one: "ONE"
    overrides:
      - db_type: "text"
        go_type: "github.com/sqlc-dev/sqlc-testdata/pkg.CustomType"
      - column: "overrides.three"
        go_type:
          import: "github.com/sqlc-dev/sqlc-testdata/pkg"
          type: "CustomType"
sql:
- schema: "schema.sql"
  queries: "query.sql"
  engine: "postgresql"
  codegen:
  - out: "db"
    plugin: go 
    options:
      rename:
        one: "ONE"
      overrides:
        - column: "overrides.three"
          go_type:
            import: "invalid/import"
            type: "ShouldNotSeeThis"

Supersedes #2918

@kyleconroy kyleconroy marked this pull request as ready for review October 30, 2023 22:43
@@ -156,6 +122,7 @@ message CodeGenRequest {
repeated Query queries = 3 [json_name = "queries"];
string sqlc_version = 4 [json_name = "sqlc_version"];
bytes plugin_options = 5 [json_name = "plugin_options"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

sadly this should probably be queryset_options but not worth changing.

if found {
opts, err := convert.YAMLtoJSON(global)
if err != nil {
return "", nil, fmt.Errorf("invalid plugin options")
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably should have %w in here to give user some idea of what the error was

@kyleconroy kyleconroy merged commit d9e233e into main Oct 31, 2023
@kyleconroy kyleconroy deleted the andrew/override-config-tests branch October 31, 2023 18:36
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