[V3](gf/gen)生成的dao模版默认非Safe模式#4256
Conversation
There was a problem hiding this comment.
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) | ||
| } | ||
|
|
There was a problem hiding this comment.
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