-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[V3](gf/gen)生成的dao模版默认非Safe模式 #4256
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: feat/v3
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 changes the default behavior of generated DAO templates to use non-Safe mode by default, removing the Safe() method call from the Ctx method implementations.
- Removes
Safe()mode from generated DAO templates - Updates test data files to reflect the new template behavior
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 |
|---|---|
| cmd/gf/internal/consts/consts_gen_dao_template_dao.go | Updates the DAO template to remove Safe() mode |
| cmd/gf/internal/cmd/testdata/issue/3749/dao/internal/table_user.go | Test data updated to match new template |
| cmd/gf/internal/cmd/testdata/gendao/generated_user_type_mapping/dao/internal/table_user.go | Test data updated to match new template |
| cmd/gf/internal/cmd/testdata/gendao/generated_user_sqlite3/dao/internal/table_user.go | Test data updated to match new template |
| cmd/gf/internal/cmd/testdata/gendao/generated_user_field_mapping/dao/internal/table_user.go | Test data updated to match new template |
| cmd/gf/internal/cmd/testdata/gendao/generated_user/dao/internal/table_user.go | Test data updated to match new template |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return model.Ctx(ctx) | ||
| } | ||
Copilot
AI
Aug 24, 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.
Removing Safe() mode changes the default behavior of generated DAOs which could be a breaking change. Safe mode typically provides protections against concurrent modifications. Consider documenting this change or providing a configuration option to enable Safe mode when needed.
| return model.Ctx(ctx) | |
| } | |
| // SafeCtx creates and returns a Model for the current DAO with Safe mode enabled. | |
| // Safe mode provides protections against concurrent modifications. | |
| // Use this method if you need concurrency safety for your operations. | |
| func (dao *{{.TplTableNameCamelCase}}Dao) SafeCtx(ctx context.Context) *gdb.Model { | |
| model := dao.DB().Model(dao.table).Safe() | |
| for _, handler := range dao.handlers { | |
| model = handler(model) | |
| } | |
| return model.Ctx(ctx) | |
| } |
|
Please associate relevant issues so that everyone can quickly understand the reason. Thank you @CyJaySong |
生成的dao模版默认非Safe模式
#4173