-
Notifications
You must be signed in to change notification settings - Fork 927
feat(codegen/golang): Allow exporting models to a different package #3874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nicklasos
commented
Jul 10, 2025
Any plans to merge this PR? It’s a really useful feature for large projects using sqlc.
pgmitche
commented
Aug 27, 2025
Would love to see some movement on this one, pretty handy feature. What's keeping this from being integrated?
nicklasos
commented
Aug 31, 2025
@kyleconroy hey! I’m working on a big project using SQLC, and it keeps growing. This PR would have a huge positive impact on my project as well as many others. From my perspective, this is the only weak spot in SQLC, and it could be resolved with this PR. I already tested this PR on our codebase, and it works like a charm. Please consider reviewing it when you have a chance, and please let me know if I can help in any way. Thank you!
nikitamarchenko
commented
Aug 31, 2025
I need this feature. Can't use without. Please.
Fixes #835
This PR adds exporting models to a different package feature to Go code generator.
I also added a how-to page for this feature, you can check the
docs/howto/separate-models-file.md
file.Main code changes made in this PR
output_models_package
,models_package_import_path
andoutput_query_files_directory
options to gen/go configuration. (internal/codegen/golang/opts/options.go
)Package
field toStruct
type to specify the correct type of the Struct since they can be in different package now. (internal/codegen/golang/struct.go
andinternal/codegen/golang/result.go
)Type()
method ofQueryValue
will return{Package}.{Name}
forStruct
types if thePackage
field of theStruct
is not empty. (internal/codegen/golang/query.go
){Package}.
prefix to enum types if configuration specifies separate models package. (changed onlyinternal/codegen/golang/postgresql_type.go
since only postgresql implementation supports typed enum values)internal/codegen/golang/imports.go
)Note for sqlc users
You can simply try this feature using my sqlc-gen-go plugin fork. I will try to keep that plugin and this PR in sync. Surely sqlc-gen-go plugin configuration is not same as the sqlc gen configuration but the feature implementation code is the same as this PR.