add update statement
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user