-
-
Notifications
You must be signed in to change notification settings - Fork 4k
(WIP) Implement Generics API #7424
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
base: master
Are you sure you want to change the base?
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 implements a type-safe, generic CRUD and query API layer on top of GORM. Key changes include:
- Introduction of generic constructor and API methods for CRUD and raw SQL operations.
- Updates to join handling and inline condition building across query and preload callbacks.
- Dependency updates and minor test adjustments.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/joins_test.go | Removed DB.Debug() calls from preload and join tests. |
tests/go.mod | Updated dependency versions and removed toolchain declarations. |
tests/connpool_test.go | Inherited Logger from DB to ensure consistent logging. |
statement.go | Refactored join struct to include Alias and Expression; unified table references in conditions. |
scan.go | Updated nested relation name handling in scan to account for join alias changes. |
clause/joins.go | Added JoinTarget helper functions to support new join APIs. |
chainable_api.go | Improved inline documentation for chainable API usage. |
callbacks/query.go | Changed join alias resolution by referencing join.Alias and adjusted join expression handling. |
callbacks/preload.go | Modified the way inline conditions are applied to improve query composition. |
Comments suppressed due to low confidence (1)
callbacks/preload.go:288
- The change in how inline conditions are applied alters the original query behavior; please verify that merging these conditions with existing WHERE clauses is intentional.
if len(inlineConds) > 0 { tx = tx.Where(inlineConds[0], inlineConds[1:]...) }
@@ -146,9 +146,13 @@ func BuildQuerySQL(db *gorm.DB) { | |||
|
|||
if isRelations { | |||
genJoinClause := func(joinType clause.JoinType, parentTableName string, relation *schema.Relationship) clause.Join { |
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 variable 'join' is not defined in the closure; consider using the appropriate parameter or property (e.g., relation's alias) for alias resolution.
genJoinClause := func(joinType clause.JoinType, parentTableName string, relation *schema.Relationship) clause.Join { | |
genJoinClause := func(join clause.Join, joinType clause.JoinType, parentTableName string, relation *schema.Relationship) clause.Join { |
Copilot uses AI. Check for mistakes.
@@ -244,6 +245,12 @@ func Scan(rows Rows, db *DB, mode ScanMode) { | |||
matchedFieldCount[column] = 1 | |||
} | |||
} else if names := utils.SplitNestedRelationName(column); len(names) > 1 { // has nested relation | |||
for _, join := range db.Statement.Joins { | |||
if join.Alias == names[0] { | |||
names = append(strings.Split(join.Name, "."), names[len(names)-1]) |
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] Appending the split join name to the existing names slice may lead to an unexpected structure; consider reassigning names if the intent is to replace the existing value.
names = append(strings.Split(join.Name, "."), names[len(names)-1]) | |
names = append([]string{}, append(strings.Split(join.Name, "."), names[len(names)-1])...) |
Copilot uses AI. Check for mistakes.
feat(gorm): add generic CRUD & query interfaces
This commit introduces a type-safe, generic API layer on top of GORM that
allows you to perform Create, Read, Update, Delete and raw SQL operations
Helper constructor:
Basic usage: