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 YAML anchors in sqlc.yaml #2653

Closed
kevinvalk opened this issue Aug 24, 2023 · 1 comment · Fixed by #2733
Closed

Support YAML anchors in sqlc.yaml #2653

kevinvalk opened this issue Aug 24, 2023 · 1 comment · Fixed by #2733
Labels
bug Something isn't working ⚙️ process Process-based plugins panic
Milestone

Comments

@kevinvalk
Copy link

kevinvalk commented Aug 24, 2023

What do you want to change?

Currently I am working on a microservices project using SQLC. All is fine, but I find myself repeating the same configuration options for each codegen section. Using YAML anchors this would be trivial and very nice, but this is currently not supported.

Then I could do something like the following.

sql:
  - schema: database
    queries: services/a
    engine: postgresql
    codegen:
      - out: gateway/src/gateway/services/organization
        plugin: py
        options: &base-options
          query_parameter_limit: 1
          package: gateway
          output_models_file_name: null
          emit_module: true
          emit_generators: false
          emit_async: true

  - schema: database
    queries: services/b
    engine: postgresql
    codegen:
      - out: gateway/src/gateway/services/project
        plugin: py
        options: *base-options

https://play.sqlc.dev/p/32c6b52785ce13ddfeb2311a2a835800d2578b56bf1addd95887e3fe45d2ace0

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

@kevinvalk kevinvalk added enhancement New feature or request triage New issues that hasn't been reviewed labels Aug 24, 2023
@kyleconroy kyleconroy added bug Something isn't working panic and removed triage New issues that hasn't been reviewed enhancement New feature or request labels Sep 14, 2023
@kyleconroy kyleconroy changed the title YAML anchors in sqlc.yaml Support YAML anchors in sqlc.yaml Sep 14, 2023
@kyleconroy kyleconroy added the ⚙️ process Process-based plugins label Sep 14, 2023
@kyleconroy
Copy link
Collaborator

We parse YAML using https://github.com/go-yaml/yaml which has support for anchors. You can see a working example here.

version: "2"
sql:
- schema: "query.sql"
  queries: "query.sql"
  engine: "postgresql"
  gen:
    go: 
      package: "authors"
      out: "postgresql"
  database:
    uri: "postgresql://postgres:postgres@localhost:5432/postgres"
  rules: &base-rules
    - sqlc/db-prepare
- schema: "query.sql"
  queries: "query.sql"
  engine: "postgresql"
  gen:
    go:
      package: "authors"
      out: "mysql"
  rules: *base-rules

The bug you're seeing is due to how the plugin system serializes options. I've updated this issue to be a bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ⚙️ process Process-based plugins panic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants