70 lines
982 B
Go
70 lines
982 B
Go
package sqimple
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// https://www.sqlite.org/lang_delete.html
|
|
type DeleteQuery struct {
|
|
table SelectTable
|
|
|
|
where []Where
|
|
args []any
|
|
}
|
|
|
|
func (q *DeleteQuery) Args() []any {
|
|
return q.args
|
|
}
|
|
|
|
func (q *DeleteQuery) IsValid() bool {
|
|
if !q.table.IsValid() {
|
|
return false
|
|
}
|
|
|
|
for _, w := range q.where {
|
|
if !w.IsValid() {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (q *DeleteQuery) String() string {
|
|
strs := []string{"delete", q.table.String()}
|
|
|
|
if len(q.where) > 0 {
|
|
strs = append(strs, "where")
|
|
|
|
for _, w := range q.where {
|
|
strs = append(strs, w.String())
|
|
}
|
|
}
|
|
|
|
return strings.Join(strs, " ")
|
|
}
|
|
|
|
func (q *DeleteQuery) Where(def string, args ...any) *DeleteQuery {
|
|
q.where = append(q.where, Where(def))
|
|
|
|
if len(args) > 0 {
|
|
if q.args == nil {
|
|
q.args = []any{}
|
|
}
|
|
|
|
q.args = append(q.args, args...)
|
|
}
|
|
|
|
return q
|
|
}
|
|
|
|
func Delete(from string) *DeleteQuery {
|
|
q := &DeleteQuery{
|
|
table: From(from),
|
|
|
|
where: []Where{},
|
|
}
|
|
|
|
return q
|
|
}
|