add insert statement

This commit is contained in:
2026-07-07 21:20:58 +01:00
parent 275c4a8cdd
commit 87517d247a
7 changed files with 258 additions and 22 deletions
+19 -19
View File
@@ -5,23 +5,23 @@ import (
)
// https://www.sqlite.org/lang_delete.html
type DeleteQuery struct {
type DeleteStatement struct {
table SelectTable
where []Where
args []any
}
func (q *DeleteQuery) Args() []any {
return q.args
func (s *DeleteStatement) Args() []any {
return s.args
}
func (q *DeleteQuery) IsValid() bool {
if !q.table.IsValid() {
func (s *DeleteStatement) IsValid() bool {
if !s.table.IsValid() {
return false
}
for _, w := range q.where {
for _, w := range s.where {
if !w.IsValid() {
return false
}
@@ -30,13 +30,13 @@ func (q *DeleteQuery) IsValid() bool {
return false
}
func (q *DeleteQuery) String() string {
strs := []string{"delete", q.table.String()}
func (s *DeleteStatement) String() string {
strs := []string{"delete", s.table.String()}
if len(q.where) > 0 {
if len(s.where) > 0 {
strs = append(strs, "where")
for _, w := range q.where {
for _, w := range s.where {
strs = append(strs, w.String())
}
}
@@ -44,26 +44,26 @@ func (q *DeleteQuery) String() string {
return strings.Join(strs, " ")
}
func (q *DeleteQuery) Where(def string, args ...any) *DeleteQuery {
q.where = append(q.where, Where(def))
func (s *DeleteStatement) Where(def string, args ...any) *DeleteStatement {
s.where = append(s.where, Where(def))
if len(args) > 0 {
if q.args == nil {
q.args = []any{}
if s.args == nil {
s.args = []any{}
}
q.args = append(q.args, args...)
s.args = append(s.args, args...)
}
return q
return s
}
func Delete(from string) *DeleteQuery {
q := &DeleteQuery{
func Delete(from string) *DeleteStatement {
s := &DeleteStatement{
table: From(from),
where: []Where{},
}
return q
return s
}