Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions database/gdb/gdb_model_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link

Copilot AI Sep 28, 2025

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.

Copilot uses AI. Check for mistakes.
}()
Comment on lines +162 to +165
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to the Core schema without synchronization could cause race conditions if multiple goroutines access the same database instance simultaneously. Consider using atomic operations or mutex protection for the schema field access.

Copilot uses AI. Check for mistakes.
}
return h.Model.db.DoSelect(ctx, h.link, toBeCommittedSql, h.Args...)
}
Expand Down Expand Up @@ -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()
Copy link

Copilot AI Sep 28, 2025

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.

Copilot uses AI. Check for mistakes.
}()
}
return h.Model.db.DoInsert(ctx, h.link, h.Table, h.Data, h.Option)
}
Expand Down Expand Up @@ -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()
Copy link

Copilot AI Sep 28, 2025

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.

Copilot uses AI. Check for mistakes.
}()
}
return h.Model.db.DoUpdate(ctx, h.link, h.Table, h.Data, h.Condition, h.Args...)
}
Expand Down Expand Up @@ -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()
Copy link

Copilot AI Sep 28, 2025

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.

Copilot uses AI. Check for mistakes.
}()
}
return h.Model.db.DoDelete(ctx, h.link, h.Table, h.Condition, h.Args...)
}
Expand Down
Loading