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