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
+40 -1
View File
@@ -6,7 +6,46 @@ import (
"strings"
)
var selectTableRegexp = regexp.MustCompile("^(from|left join|inner join|right join) ([^ ]+)( (as) ([^ ]+))?( (on) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+)( (and) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+))*)?$")
var (
insertTableRegexp = regexp.MustCompile("^into ([^ ]+)( (as) ([^ ]+))?$")
selectTableRegexp = regexp.MustCompile("^(from|left join|inner join|right join) ([^ ]+)( (as) ([^ ]+))?( (on) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+)( (and) ([^ ]+) (=|!=|>|>=|<|<=) ([^ ]+))*)?$")
)
type InsertTable string
func (t InsertTable) IsValid() bool {
return insertTableRegexp.MatchString(string(t))
}
func (t InsertTable) 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 InsertTable) String() string {
return string(t)
}
func Into(def string) InsertTable {
if strings.Index(def, "into ") == 0 {
return InsertTable(def)
}
return InsertTable(fmt.Sprintf("into %s", def))
}
type SelectTable string