2022-05-23 09:12:06 +08:00
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, {{if .containsIndexCache}}newData{{else}}data{{end}} *{{.upperStartCamelObject}}) error {
|
|
|
|
|
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, newData.{{.upperStartCamelPrimaryKey}})
|
|
|
|
|
if err!=nil{
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{end}} {{.keys}}
|
|
|
|
|
_, {{if .containsIndexCache}}err{{else}}err:{{end}}= m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
2021-07-23 11:45:15 +08:00
|
|
|
query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
|
2022-02-17 10:28:55 +08:00
|
|
|
return conn.ExecCtx(ctx, query, {{.expressionValues}})
|
2021-07-23 11:45:15 +08:00
|
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
|
2022-02-17 10:28:55 +08:00
|
|
|
_,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
|
2020-10-27 22:42:53 +08:00
|
|
|
return err
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|