feat(database/gdb): Optimize SoftTime feature#4559
Merged
gqcn merged 4 commits intogogf:masterfrom Dec 12, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the soft delete SoftTime feature in the GoFrame ORM by introducing type safety and reducing code duplication. The changes introduce a new SoftTimeFieldType enum to distinguish between create, update, and delete field purposes, replacing the previous magic number approach.
Key Changes:
- Introduced
SoftTimeFieldTypeenum with three constants:SoftTimeFieldCreate,SoftTimeFieldUpdate,SoftTimeFieldDelete - Consolidated three nearly identical
GetFieldNameAndTypeFor*methods into a single unifiedGetFieldInfomethod - Renamed and refactored interface methods for better clarity (e.g.,
GetWhereConditionForDelete→GetDeleteCondition,GetDataByFieldNameAndTypeForDelete→GetDeleteData) - Extracted and simplified helper methods (
getEmptyValue,getAutoValue,getTimestampValue) to improve code organization
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| database/gdb/gdb_model_soft_time.go | Core refactoring: adds SoftTimeFieldType enum, consolidates methods, refactors helper functions, and improves code organization |
| database/gdb/gdb_model_update.go | Updates method calls to use new GetFieldInfo and GetFieldValue methods |
| database/gdb/gdb_model_insert.go | Updates method calls to use new GetFieldInfo and GetFieldValue methods |
| database/gdb/gdb_model_delete.go | Updates method calls to use new GetFieldInfo and GetDeleteData methods |
| database/gdb/gdb_model_select.go | Updates method call to use new GetDeleteCondition method |
| database/gdb/gdb_func.go | Adds utility functions for cache key generation: genTableNamesCacheKey and genSoftTimeFieldNameTypeCacheKey |
| database/gdb/gdb_core.go | Refactors to use new genTableNamesCacheKey utility function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@LanceAdd 我对整体改动没什么疑问,注意修正下copilot提出的comment就好。我近期也会改动这里,希望尽快修正提交。 |
Member
Author
改完了 |
gqcn
approved these changes
Dec 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本次PR主要针对GoFrame ORM中的软删除
SoftTime功能进行了优化SoftTimeFieldType枚举类型,用于区分创建、更新、删除三种不同的软时间字段GetFieldNameAndTypeFor*方法为统一的方法This pull request refactors and simplifies the "soft time" (created/updated/deleted timestamp) handling logic in the database layer, making the codebase more maintainable and extensible. The changes consolidate multiple similar methods into general-purpose ones, improve cache key generation, and clarify the logic for generating and applying soft time field values and conditions.
Key changes include:
Soft Time API Refactoring and Simplification
GetFieldNameAndTypeForCreate,GetFieldNameAndTypeForUpdate,GetFieldNameAndTypeForDelete) into a single, parameterized methodGetFieldInfo, reducing code duplication and making it easier to support new soft time field types. The interface and implementation for soft time maintenance (iSoftTimeMaintainer,softTimeMaintainer) have been updated accordingly. [1] [2]GetValueByFieldTypeForCreateOrUpdateintoGetFieldValue, andGetWhereConditionForDeleteintoGetDeleteCondition. Related usages throughout the codebase have been updated to use the new methods. [1] [2] [3] [4] [5] [6]Soft Delete Logic Improvements
buildDeleteCondition,GetDeleteData, and improved error logging for invalid field types. [1] [2]Cache Key Generation Enhancements
General Code Cleanup
Let me know if you'd like a walkthrough of any specific part of the refactored soft time logic!