walterwanderley / sqlc-grpc

Create a gRPC server from code generated by sqlc
MIT License
127 stars 13 forks source link

Implement as a sqlc WASM plugin using `sqlc-dev/plugin-sdk-go` #8

Open andrewmbenton opened 11 months ago

andrewmbenton commented 11 months ago

A suggestion from this Twitter thread is to implement the project as a sqlc WASM plugin. This would allow users to get the grpc codegen output from this project directly from sqlc generate. An example sqlc.yaml config might look like:

version: '2'
plugins:
- name: walterwanderley-sqlc-grpc
  wasm:
    url: https://some.cdn/walterwanderley-sqlc-grpc.wasm
    sha256: ""
sql:
- schema: schema.sql
  queries: query.sql
  engine: postgresql
  codegen:
  - plugin: walterwanderley-sqlc-grpc
    out: sqlc
    options:
      module: "my-module"
      tracing: true
      litefs: true
  gen:
    go:
      out: sqlc
      sql_package: pgx/v5

Running sqlc generate with this config would put both the typical sqlc Go codegen output and the grpc output from this project in the sqlc directory.

There's a sqlc plugin sdk for Go which should make the implementation a little more straightforward.

The only hiccup I can think of would be that sqlc's GenerateRequest proto message that sqlc hands to a plugin may not have enough information to support the grpc codegen work as you've currently implemented it.

walterwanderley commented 9 months ago

Hi @andrewmbenton!

Since this project was created before the possibility of writing plugins, the architecture is quite different. In my opinion, the best approach would be to fork the sqlc-gen-go repository and implement gRPC support. What do you think?

walterwanderley commented 9 months ago

sqlc WASM plugin: https://github.com/walterwanderley/sqlc-gen-go-server