2020-08-19 10:41:19 +08:00
package template
2020-07-29 17:11:41 +08:00
2021-02-26 16:11:47 +08:00
// Update defines a template for generating update codes
2020-07-29 17:11:41 +08:00
var Update = `
2022-02-17 10:28:55 +08:00
func ( m * default { { . upperStartCamelObject } } Model ) Update ( ctx context . Context , data * { { . upperStartCamelObject } } ) error {
2021-03-12 17:49:28 +08:00
{ { if . withCache } } { { . keys } }
2022-02-17 10:28:55 +08:00
_ , err := 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
}
`
2020-11-24 22:36:23 +08:00
2021-02-26 16:11:47 +08:00
// UpdateMethod defines an interface method template for generating update codes
2022-02-17 10:28:55 +08:00
var UpdateMethod = ` Update(ctx context.Context, data * {{ .upperStartCamelObject }} ) error `