Protocol Buffers plugin to generate SQL schema and queries with sqlc annotations.
Describe a library book and its author in Protobuf, mark their keys and relationship, and inspect the resulting tables and queries before compiling them into typed application code with sqlc. The library definitions and generated SQL show both sides of that contract.
This is an experimental generator. The included example targets PostgreSQL and Go with pgx. It generates a schema for an empty database and named CRUD queries. Existing databases need a migration plan when the schema changes. The generator currently treats every top-level message in its input as a table. Limit generation to files containing persistence models.
From a checkout with Go and the Go binary directory on your PATH, run
make sqlc to rebuild the plugin and regenerate the library SQL and Go
bindings. Run make test to exercise the Go test suite.
You can download and compile the latest version from source using Go directly:
go install github.com/pablojimpas/protoc-gen-sqlc/cmd/protoc-gen-sqlc@latestor you can download pre-built binaries from the Github releases page.
To use buf you have to make a config file called buf.gen.yaml with your
options, like this:
version: v2
plugins:
- local: protoc-gen-sqlc
out: outAnd then run buf generate. See the documentation on buf
generate for more
help.
This plugin works with protoc as well. Here's a basic usage example:
protoc example.proto --sqlc_out=gen