You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(golang): emit models to a different package (#4421)
* feat(golang): emit models to a different package
Closes#835.
Adds four Go codegen options that let users place table model structs
and enums in a Go package distinct from the queries package, optionally
shared across multiple SQL blocks:
- output_models_path: directory for the models file
- output_models_package: Go package name for the models file
- output_models_import: import path for the models package
- output_models_emit: when false, skip emitting models.go and only
reference an externally-emitted models package
When the models package differs from the queries package, query files
import the models package and reference types as `model.User` instead of
`User`. Embedded model structs in synthetic Row structs and enum types
in synthetic Params structs are qualified consistently.
End-to-end fixtures cover both shapes: a single block with models in a
sibling directory, and two query blocks that share one models package.
https://claude.ai/code/session_01Nj4LbGbqFBTU1EPKKNHtNn
* default models package, always import as `models`
Two refinements on top of the initial #835 work:
1. output_models_package now defaults to filepath.Base(output_models_path)
when unset, matching how `package` defaults to base(out). When only
output_models_emit: false is configured (no path), it falls back to
filepath.Base(output_models_import).
2. Query files always import the models package under the alias `models`
and reference types as `models.User`, regardless of the actual package
name. This keeps generated query code readable without users having to
think about import aliases. The actual `package X` declaration in
models.go still uses the configured (or defaulted) package name.
https://claude.ai/code/session_01Nj4LbGbqFBTU1EPKKNHtNn
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments