Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions builder/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,14 @@ func buildUpdate(table string, update map[string]interface{}, limit uint, condit

func buildDelete(table string, limit uint, conditions ...Comparable) (string, []interface{}, error) {
whereString, vals := whereConnector("AND", conditions...)
if "" == whereString {
return fmt.Sprintf("DELETE FROM %s", table), nil, nil
}
format := "DELETE FROM %s WHERE %s"

cond := fmt.Sprintf(format, quoteField(table), whereString)
format := "DELETE FROM %s"
args := make([]interface{}, 0, 2)
args = append(args, quoteField(table))
if len(whereString) > 0 {
format += " WHERE %s"
args = append(args, whereString)
}
cond := fmt.Sprintf(format, args...)
if limit > 0 {
cond += " LIMIT ?"
vals = append(vals, int(limit))
Expand Down
14 changes: 14 additions & 0 deletions builder/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,20 @@ func TestBuildDelete(t *testing.T) {
outVals: []interface{}{2, "tt", 1, 5},
outErr: nil,
},
{
table: "tb",
limit: 5,
outStr: "DELETE FROM tb LIMIT ?",
outVals: []interface{}{5},
outErr: nil,
},
{
table: "tb",
limit: 0,
outStr: "DELETE FROM tb",
outVals: nil,
outErr: nil,
},
}
ass := assert.New(t)
for _, tc := range data {
Expand Down