crowdsec/pkg/database/delete.go
Thibault "bui" Koechlin 177480cff7
updated mysql plugin support (#135)
* add support for plugin, support mysql & so on

* fix queries

Co-authored-by: erenJag <erenJag>
Co-authored-by: AlteredCoder <AlteredCoder>
2020-07-16 16:05:03 +02:00

32 lines
703 B
Go

package database
import (
"fmt"
"github.com/crowdsecurity/crowdsec/pkg/types"
log "github.com/sirupsen/logrus"
)
/*try to delete entries with matching fields */
func (c *Context) DeleteBan(target string) (int, error) {
if target != "" {
ret := c.Db.Delete(types.BanApplication{}, "ip_text = ?", target)
if ret.Error != nil {
log.Errorf("Failed to delete record with BanTarget %s : %v", target, ret.Error)
return 0, ret.Error
}
return int(ret.RowsAffected), nil
}
return 0, fmt.Errorf("no target provided")
}
func (c *Context) DeleteAll() error {
allBa := types.BanApplication{}
records := c.Db.Delete(&allBa)
if records.Error != nil {
return records.Error
}
return nil
}