Skip to content

Add type-safe Go code generation from migration schema#964

Draft
ljluestc wants to merge 1 commit intopressly:mainfrom
ljluestc:feature/code-generation
Draft

Add type-safe Go code generation from migration schema#964
ljluestc wants to merge 1 commit intopressly:mainfrom
ljluestc:feature/code-generation

Conversation

@ljluestc
Copy link

@ljluestc ljluestc commented Jul 4, 2025

- What I did
Implemented a goose generate command to generate type-safe Go code from SQL queries in a queries/ directory, using schema information from migration files. Supports read-only (pgx/v5) and read/write (sql/db) queries with basic dynamic query support.

- How I did it

  • Added generate command in cmd/goose/main.go with flags -dir, -queries, and -out.
  • Created internal/parser/schema.go to parse CREATE TABLE statements for schema inference.
  • Implemented internal/generator/generator.go to generate type-safe Go code using templates, with parameter inference for dynamic queries.
  • Updated goose.go to integrate parsing and generation.
  • Supported read-only vs. read/write queries via _read naming convention.
  • Used sql/db for write operations and pgx/v5 for read-only queries.

Signed-off-by: ljluestc <jeremykalilin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant