add update statement

This commit is contained in:
2026-07-07 22:07:50 +01:00
parent 87517d247a
commit f2ebd5b53f
5 changed files with 209 additions and 4 deletions
+29
View File
@@ -9,6 +9,7 @@ import (
var (
insertTableRegexp = regexp.MustCompile("^into ([^ ]+)( (as) ([^ ]+))?$")
selectTableRegexp = regexp.MustCompile("^(from|left join|inner join|right join) ([^ ]+)( (as) ([^ ]+))?( (on) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+)( (and) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+))*)?$")
updateTableRegexp = regexp.MustCompile("^([^ ]+)( (as) ([^ ]+))?$")
)
type InsertTable string
@@ -120,3 +121,31 @@ func RightJoin(def string) SelectTable {
return SelectTable(fmt.Sprintf("right join %s", def))
}
type UpdateTable string
func (t UpdateTable) IsValid() bool {
return insertTableRegexp.MatchString(string(t))
}
func (t UpdateTable) Parse() (table, as string, ok bool) {
if insertTableRegexp.MatchString(string(t)) {
ok = true
result := insertTableRegexp.FindAllStringSubmatch(string(t), -1)
for _, r := range result {
table = r[1]
if r[3] == "as" {
as = r[4]
}
}
}
return
}
func (t UpdateTable) String() string {
return string(t)
}