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
|
|
|
// Delete defines a delete template
|
2020-07-29 17:11:41 +08:00
|
|
|
var Delete = `
|
2022-02-17 10:28:55 +08:00
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
|
2022-03-17 17:16:53 +08:00
|
|
|
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, {{.lowerStartCamelPrimaryKey}})
|
2020-07-29 17:11:41 +08:00
|
|
|
if err!=nil{
|
|
|
|
return err
|
2022-02-17 10:28:55 +08:00
|
|
|
}
|
2020-08-27 22:54:18 +08:00
|
|
|
|
2022-02-17 10:28:55 +08:00
|
|
|
{{end}} {{.keys}}
|
|
|
|
_, err {{if .containsIndexCache}}={{else}}:={{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("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table)
|
2022-02-17 10:28:55 +08:00
|
|
|
return conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}})
|
2021-07-23 11:45:15 +08:00
|
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table)
|
2022-02-17 10:28:55 +08:00
|
|
|
_,err:=m.conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}){{end}}
|
2020-07-29 17:11:41 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
`
|
2020-11-24 22:36:23 +08:00
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// DeleteMethod defines a delete template for interface method
|
2022-02-17 10:28:55 +08:00
|
|
|
var DeleteMethod = `Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error`
|