You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
964 B
Smarty
27 lines
964 B
Smarty
func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, tx *gorm.DB, data *{{.upperStartCamelObject}}) error {
|
|
{{if .withCache}}old, err:=m.FindOne(ctx, data.{{.upperStartCamelPrimaryKey}})
|
|
if err!=nil && err != ErrNotFound{
|
|
return err
|
|
}
|
|
err = m.ExecCtx(ctx, func(conn *gorm.DB) error {
|
|
result := gormx.WithTx(ctx, conn, tx).Save(data)
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
}, m.getCacheKeys(old)...){{else}}
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
{{end}}
|
|
}
|
|
{{if .withCache}}
|
|
func (m *default{{.upperStartCamelObject}}Model) getCacheKeys(data *{{.upperStartCamelObject}}) []string {
|
|
if data == nil {
|
|
return []string{}
|
|
}
|
|
{{.keys}}
|
|
cacheKeys := []string{
|
|
{{.keyValues}},
|
|
}
|
|
cacheKeys = append(cacheKeys, m.customCacheKeys(data)...)
|
|
return cacheKeys
|
|
}
|
|
{{end}}
|