Skip to content

JSON plugin interop? #1885

Description

@kswope

What do you want to change?

I can't find it anywhere, is there a plugin setting for communicating with a plugin via JSON rather than protobuf?

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

Activity

  1. added
    enhancementNew feature or request
    triageNew issues that hasn't been reviewed
    on Oct 7, 2022
  2. kyleconroy commented on Oct 7, 2022

    @kyleconroy
    Collaborator

    There currently isn't a way to do this. I'm a bit hesitant to add it, as it's difficult to ensure backwards compatibility.

    What language are you using? I'd be happy to help you get set up. There's also a plugin that outputs the codegen request as JSON.

  3. kswope commented on Oct 7, 2022

    @kswope
    Author

    This is what I'm trying now, I found it here but doesn't imply "plugin" in any way, it generates codegen_request.json

          "gen": {
            "json": {
              "out": "."
            }
          }
    
    

    This is whats on the plugins page, its very confusing that it does the same thing, I think it might be out of date documentation. (btw, "codegen" isn't documented anywhere)

    {
      "version": "2",
      "plugins": [
        {
          "name": "jsonb",
          "process": {
            "cmd": "sqlc-gen-json"
          }
        }
      ],
       "sql": [
        {
          "schema": "schema.sql",
          "queries": "query.sql",
          "engine": "postgresql",
          "codegen": [
            {
              "out": "gen",
              "plugin": "jsonb",
              "options": {
                "indent": "  ",
                "filename": "codegen.json"
              }
            }
          ]
        }
      ]
    }
    

    Anyway, if the output from the first config is all I need, then all I need is to let sqlc do the heavy lifting and I can get started on some templeting.

    The reason I was looking into making a "plugin" is because I didn't want this potentially stale, possibly confusing, otherwise meaningless to the user, json output file sitting around.

    Suggestion: maybe offer this option

          "gen": {
            "json": {
              "stdout": true
            }
          }
    
    

    This raises the question, why not support every language this way? sqlc does the heavy lifting, and pipes the metadata to plugins written in their own language. It just seems counterproductive to the community to write kotlin/python/typescript/etc support in go.

    Btw what I'm doing is experimenting with using sqlc with rescript. Using intermediate JSON might be the solution now, but writing go to output rescript would simply never happen, not only because nobody uses rescript, but the two languages are natural enemies :)

  4. kyleconroy commented on Nov 9, 2022

    @kyleconroy
    Collaborator

    This raises the question, why not support every language this way? sqlc does the heavy lifting, and pipes the metadata to plugins written in their own language. It just seems counterproductive to the community to write kotlin/python/typescript/etc support in go.

    This is how plugin support works today, but instead of JSON you need to use Protobuf. An example of a process-based plugin can be found here: https://github.com/kyleconroy/sqlc/tree/main/cmd/sqlc-gen-json

    Instead of outputting JSON, you can change that plugin to output anything you'd like. It also doesn't need to be written in Go. Your plugin just needs to be able to parse Protobuf from Stdin.

  5. added
    questionFurther information is requested
    and removed
    enhancementNew feature or request
    triageNew issues that hasn't been reviewed
    on Nov 9, 2022
  6. locked and limited conversation to collaborators on Nov 9, 2022
  7. converted this issue into a discussion #1938 on Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions