delete.go 923 B

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