-
-
Notifications
You must be signed in to change notification settings - Fork 8
Fix support for query interfaces defined in model packages #17
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for query interfaces where models are defined, addressing type resolution issues in the code generator. The main change improves how the generator handles exported types by properly qualifying them with package names when necessary.
- Enhanced type resolution logic in the parser to handle exported types in the same package
- Generated query interface implementations for User and Query models
- Updated documentation to correct template syntax examples
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/gen/generator.go | Improved variable declaration style and added logic to handle exported type resolution with package qualification |
| examples/output/models/user_query.go | Generated query interface implementation for User model with QueryWith and UpdateWith methods |
| examples/output/models/query.go | Generated generic query interface implementation with GetByID and FilterWithColumn methods |
| examples/models/user_query.go | Added source interface definition for User-specific query operations |
| examples/models/query.go | Added source interface definition for generic query operations |
| README.md | Fixed template syntax in documentation examples by removing @ prefix from conditionals |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| // files contains config | ||
| filesWithCfg := []string{} | ||
| var filesWithCfg []string |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] While var filesWithCfg []string is more idiomatic than filesWithCfg := []string{}, this change appears cosmetic and doesn't address any functional issue. Consider whether this change is necessary for the PR's primary objective.
| var tmp strings.Builder | ||
| if user.Name != "" { | ||
| tmp.WriteString(" name=?,") | ||
| params = append(params, user.Name) | ||
| } | ||
| if user.Age > 0 { | ||
| tmp.WriteString(" age=?") | ||
| params = append(params, user.Age) | ||
| } | ||
| c := strings.TrimSpace(tmp.String()) | ||
| if c != "" { | ||
| c = strings.Trim(c, ", ") | ||
| sb.WriteString(" SET ") | ||
| sb.WriteString(c) |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UpdateWith method has inconsistent comma handling. Line 70 adds a comma after name=? but line 74 doesn't add a comma after age=?. This could result in malformed SQL when both fields are present.
| var tmp strings.Builder | |
| if user.Name != "" { | |
| tmp.WriteString(" name=?,") | |
| params = append(params, user.Name) | |
| } | |
| if user.Age > 0 { | |
| tmp.WriteString(" age=?") | |
| params = append(params, user.Age) | |
| } | |
| c := strings.TrimSpace(tmp.String()) | |
| if c != "" { | |
| c = strings.Trim(c, ", ") | |
| sb.WriteString(" SET ") | |
| sb.WriteString(c) | |
| assignments := make([]string, 0, 2) | |
| if user.Name != "" { | |
| assignments = append(assignments, "name=?") | |
| params = append(params, user.Name) | |
| } | |
| if user.Age > 0 { | |
| assignments = append(assignments, "age=?") | |
| params = append(params, user.Age) | |
| } | |
| if len(assignments) > 0 { | |
| sb.WriteString(" SET ") | |
| sb.WriteString(strings.Join(assignments, ", ")) |
support query interface in where is models define
Support for Query Interfaces Defined in Model Packages and Code Generation Improvements
This PR introduces enhanced support for query interfaces such as
UserQueryand genericQuery[T any]defined directly within model packages, allowing the code generation system to produce type-safe, concrete implementations for these interfaces. Key modifications include updates to the type resolution logic ininternal/gen/generator.go, addition of new and updated model/interface files, refreshed generated code for query/update methods, and corrections to SQL template documentation and example usage inREADME.md. These changes collectively improve ergonomics and correctness when binding SQL templates to interfaces within model code.Key Changes
• Added
UserQueryand genericQuery[T any]interfaces inexamples/models/user_query.goandexamples/models/query.go• Generated new query implementation files:
examples/output/models/user_query.goandexamples/output/models/query.go• Implemented concrete methods (
QueryWith,UpdateWith,GetByID,FilterWithColumn) for these interfaces• Enhanced
parseFieldTypeand type/package path resolution logic ininternal/gen/generator.go• Fixed initialization of
filesWithCfgininternal/gen/generator.go• Updated documentation and SQL template examples in
README.md• Minor output formatting fix in
internal/gen/generator_test.goAffected Areas
•
examples/models/user_query.go•
examples/models/query.go•
examples/output/models/user_query.go•
examples/output/models/query.go•
internal/gen/generator.go•
README.md•
internal/gen/generator_test.goThis summary was automatically generated by @propel-code-bot