Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
berk-karaal wants to merge3 commits intosqlc-dev:main
base:main
Choose a base branch
Loading
fromberk-karaal:main

Conversation

berk-karaal
Copy link

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 thedocs/howto/separate-models-file.md file.

Main code changes made in this PR

  • Added optionaloutput_models_package,models_package_import_path andoutput_query_files_directory options to gen/go configuration. (internal/codegen/golang/opts/options.go)
  • AddedPackage 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)
  • Added{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)
  • Deciding whether the generated file needs to import the separated models file package. (internal/codegen/golang/imports.go)

Note for sqlc users

You can simply try this feature using mysqlc-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.

jlisthood, Esequiel378, dw-0, pdarulewski, Hjaltebb, dinopuguh, skewb1k, Ghibranalj, gvuyk, dimkaufo, and 3 more reacted with hooray emojisezaakgun, Esequiel378, giuliano-macedo, jlisthood, Ghibranalj, gvuyk, eray-alp, mwdev22, thara, dimkaufo, and 3 more reacted with heart emoji
@dosubotdosubotbot added size:LThis PR changes 100-499 lines, ignoring generated files. 🔧 golang labelsMar 6, 2025
dimkaufo added a commit to dimkaufo/sqlc that referenced this pull requestMay 26, 2025
@nicklasos
Copy link

Any plans to merge this PR? It’s a really useful feature for large projects using sqlc.

pdarulewski reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
size:LThis PR changes 100-499 lines, ignoring generated files.🔧 golang
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Export models to a different package
2 participants
@berk-karaal@nicklasos

[8]ページ先頭

©2009-2025 Movatter.jp