-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(database/gdb): Resolved the schema error in the database output log when using the database sharding feature #4319
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,6 +159,10 @@ func (h *HookSelectInput) Next(ctx context.Context) (result Result, err error) { | |
| if err != nil { | ||
| return | ||
| } | ||
| h.Model.db.GetCore().schema = h.Schema | ||
| defer func() { | ||
| h.Model.db.GetCore().schema = h.originalSchemaName.String() | ||
| }() | ||
|
Comment on lines
+162
to
+165
|
||
| } | ||
| return h.Model.db.DoSelect(ctx, h.link, toBeCommittedSql, h.Args...) | ||
| } | ||
|
|
@@ -195,6 +199,10 @@ func (h *HookInsertInput) Next(ctx context.Context) (result sql.Result, err erro | |
| if err != nil { | ||
| return | ||
| } | ||
| h.Model.db.GetCore().schema = h.Schema | ||
| defer func() { | ||
| h.Model.db.GetCore().schema = h.originalSchemaName.String() | ||
|
||
| }() | ||
| } | ||
| return h.Model.db.DoInsert(ctx, h.link, h.Table, h.Data, h.Option) | ||
| } | ||
|
|
@@ -238,6 +246,10 @@ func (h *HookUpdateInput) Next(ctx context.Context) (result sql.Result, err erro | |
| if err != nil { | ||
| return | ||
| } | ||
| h.Model.db.GetCore().schema = h.Schema | ||
| defer func() { | ||
| h.Model.db.GetCore().schema = h.originalSchemaName.String() | ||
|
||
| }() | ||
| } | ||
| return h.Model.db.DoUpdate(ctx, h.link, h.Table, h.Data, h.Condition, h.Args...) | ||
| } | ||
|
|
@@ -281,6 +293,10 @@ func (h *HookDeleteInput) Next(ctx context.Context) (result sql.Result, err erro | |
| if err != nil { | ||
| return | ||
| } | ||
| h.Model.db.GetCore().schema = h.Schema | ||
| defer func() { | ||
| h.Model.db.GetCore().schema = h.originalSchemaName.String() | ||
|
||
| }() | ||
| } | ||
| return h.Model.db.DoDelete(ctx, h.link, h.Table, h.Condition, h.Args...) | ||
| } | ||
|
|
||
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 schema restoration logic is duplicated across all four hook methods. Consider extracting this into a helper method to reduce code duplication and improve maintainability.