Add support for DELETE statements.

This commit is contained in:
zer0sub 2019-04-20 19:49:29 +02:00
parent 70d6f84375
commit bc6a2bbcac
14 changed files with 492 additions and 543 deletions

View file

@ -2,9 +2,9 @@ package sqlbuilder
import (
"bytes"
"database/sql"
"fmt"
"github.com/dropbox/godropbox/errors"
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
"github.com/sub0zero/go-sqlbuilder/types"
)
@ -13,7 +13,6 @@ type SelectStatement interface {
Expression
Where(expression BoolExpression) SelectStatement
AndWhere(expression BoolExpression) SelectStatement
GroupBy(expressions ...Expression) SelectStatement
HAVING(expressions BoolExpression) SelectStatement
@ -27,9 +26,6 @@ type SelectStatement interface {
Copy() SelectStatement
AsTable(alias string) *SelectStatementTable
Execute(db types.Db, destination interface{}) error
//ExecuteInTx(tx *sql.Tx, destination interface{}) error
}
// NOTE: SelectStatement purposely does not implement the Table interface since
@ -86,14 +82,12 @@ func (s *selectStatementImpl) AsTable(alias string) *SelectStatementTable {
}
}
func (s *selectStatementImpl) Execute(db types.Db, destination interface{}) error {
query, err := s.String()
func (s *selectStatementImpl) Query(db types.Db, destination interface{}) error {
return Query(s, db, destination)
}
if err != nil {
return err
}
return execution.Execute(db, query, destination)
func (u *selectStatementImpl) Execute(db types.Db) (res sql.Result, err error) {
return Execute(u, db)
}
func (s *selectStatementImpl) Copy() SelectStatement {
@ -101,17 +95,6 @@ func (s *selectStatementImpl) Copy() SelectStatement {
return &ret
}
// Further filter the query, instead of replacing the filter
func (q *selectStatementImpl) AndWhere(
expression BoolExpression) SelectStatement {
if q.where == nil {
return q.Where(expression)
}
q.where = And(q.where, expression)
return q
}
func (q *selectStatementImpl) Where(expression BoolExpression) SelectStatement {
q.where = expression
return q