Documentation
¶
Overview ¶
Package codegen runs the external generators of the postgres module: sqlc for static queries and jet for dynamic ones.
Both run through go tool, at the versions the project pins in go.mod, so every developer and CI produce the same code.
Index ¶
- Constants
- Variables
- func Buf(ctx context.Context, dir string, out io.Writer) error
- func BufCheck(ctx context.Context, dir string) error
- func DSN(dir, flag string) (string, error)
- func Jet(ctx context.Context, dir, dsn string, out io.Writer) error
- func Protos(dir string) ([]string, error)
- func Queries(dir string) ([]string, error)
- func Sqlc(ctx context.Context, dir string, out io.Writer) error
- func SqlcCheck(ctx context.Context, dir string) error
Constants ¶
const ( ProtoDir = "proto" APIGenDir = "internal/api/gen" OpenAPIFile = "api/openapi/openapi.yaml" )
Paths of the API generation, relative to the project root.
const ( QueriesDir = "db/queries" MigrationsDir = "db/migrations" SqlcConfig = "db/sqlc.yaml" SqlcOut = "internal/db/sqlcgen" JetOut = "internal/db/jetgen" )
Paths of the query generation, relative to the project root.
Variables ¶
var GoCommand = func(ctx context.Context, dir string, out io.Writer, args ...string) error { cmd := exec.CommandContext(ctx, "go", args...) cmd.Dir = dir var stderr bytes.Buffer cmd.Stdout = out cmd.Stderr = &stderr if err := cmd.Run(); err != nil { msg := strings.TrimSpace(stderr.String()) if strings.Contains(msg, "missing go.sum entry") || strings.Contains(msg, "no required module provides") { msg += "\nrun platformgo apply to add the generators to go.mod and go.sum" } return fmt.Errorf("go %s: %w\n%s", strings.Join(args, " "), err, msg) } return nil }
GoCommand runs the go command. Tests replace it.
Functions ¶
func Buf ¶
Buf regenerates the Go code and the OpenAPI description of the proto files. Without proto files it only removes what was generated before.
func BufCheck ¶
BufCheck fails when the generated API code does not match the proto files: for CI. It generates into a scratch directory and compares, so the project is not touched.
func DSN ¶
DSN finds the database address for generation: the flag, then DATABASE_URL, then the .env and .env.example of the project — the same order make run uses.
func Jet ¶
Jet regenerates the dynamic query builder from the database at dsn. The schema must already be migrated; the tables of goose, River and platform modules are left out.
jet writes into <path>/<database>/<schema>. The database name differs between developers, and it would end up in import paths, so the output is generated into a scratch directory and its packages are moved straight under internal/db/jetgen.
Types ¶
This section is empty.