Skip to content

Conversation

@CyJaySong
Copy link
Contributor

@CyJaySong CyJaySong commented Apr 24, 2025

生成的dao模版默认非Safe模式
#4173

@CyJaySong CyJaySong changed the title 生成的dao模版默认非Safe模式 [V3](gf/gen)生成的dao模版默认非Safe模式 Apr 24, 2025
@CyJaySong CyJaySong closed this Jun 11, 2025
@CyJaySong CyJaySong reopened this Jun 11, 2025
Copy link
Contributor

Copilot AI left a 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.

Comment on lines +127 to 129
return model.Ctx(ctx)
}
Copy link

Copilot AI Aug 24, 2025

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
@houseme
Copy link
Member

houseme commented Aug 24, 2025

Please associate relevant issues so that everyone can quickly understand the reason. Thank you @CyJaySong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants