add delete query

This commit is contained in:
2026-07-07 20:07:15 +01:00
parent b302622d0a
commit 1585f945a4
3 changed files with 171 additions and 55 deletions
+69
View File
@@ -0,0 +1,69 @@
package simql
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
}