delete.go 824 B

1234567891011121314151617181920
  1. package template
  2. var Delete = `
  3. func (m *default{{.upperStartCamelObject}}Model) Delete({{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
  4. {{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne({{.lowerStartCamelPrimaryKey}})
  5. if err!=nil{
  6. return err
  7. }{{end}}
  8. {{.keys}}
  9. _, err {{if .containsIndexCache}}={{else}}:={{end}} m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
  10. query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = ?", m.table)
  11. return conn.Exec(query, {{.lowerStartCamelPrimaryKey}})
  12. }, {{.keyValues}}){{else}}query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = ?", m.table)
  13. _,err:=m.conn.Exec(query, {{.lowerStartCamelPrimaryKey}}){{end}}
  14. return err
  15. }
  16. `
  17. var DeleteMethod = `Delete({{.lowerStartCamelPrimaryKey}} {{.dataType}}) error`