Added args to delete query builder

* Fixed delete query builder WHERE bug
* Finished Delete template tests
This commit is contained in:
Patrick O'brien 2016-06-10 15:20:26 +10:00
parent c34f09aa55
commit 9ede42c577
3 changed files with 10 additions and 6 deletions

View file

@ -79,18 +79,21 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
func buildDeleteQuery(q *Query) (*bytes.Buffer, []interface{}) {
buf := &bytes.Buffer{}
var args []interface{}
buf.WriteString("DELETE FROM ")
fmt.Fprintf(buf, `"%s"`, q.table)
if len(q.where) > 0 {
buf.WriteString(" WHERE ")
for i := 0; i < len(q.where); i++ {
buf.WriteString(fmt.Sprintf(` WHERE %s`, q.where[i].clause))
buf.WriteString(fmt.Sprintf("%s", q.where[i].clause))
args = append(args, q.where[i].args...)
if i != len(q.where)-1 {
if q.where[i].orSeperator {
buf.WriteString(` OR `)
buf.WriteString(" OR ")
} else {
buf.WriteString(` AND `)
buf.WriteString(" AND ")
}
}
}
@ -98,7 +101,7 @@ func buildDeleteQuery(q *Query) (*bytes.Buffer, []interface{}) {
buf.WriteByte(';')
return buf, nil
return buf, args
}
func buildUpdateQuery(q *Query) (*bytes.Buffer, []interface{}) {

View file

@ -53,7 +53,6 @@ func (o {{$varNameSingular}}Slice) DeleteAll() error {
if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
}
return o.DeleteAllX(boil.GetDB())
}

View file

@ -65,7 +65,9 @@ func Test{{$tableNamePlural}}Delete(t *testing.T) {
}
// test DeleteAll slice function
err = o.DeleteAll()
if err = o.DeleteAll(); err != nil {
t.Errorf("Unable to objSlice.DeleteAll(): %s", err)
}
// Check number of rows in table to ensure DeleteAll was successful
c, err = {{$tableNamePlural}}().Count()