提交 36c26555 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

parse ddl sql, retrieve all columns

上级 35251ea3
......@@ -4,8 +4,10 @@ import (
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"time"
)
......@@ -13,10 +15,42 @@ func ParseSql(file string, out string) {
startTime := time.Now().Unix()
vari.InputDir = filepath.Dir(file) + string(os.PathSeparator)
files := make([]string, 0)
sents := getCreateSent(file)
for _, sent := range sents {
fields := getFieldsFromCreateSent(sent)
fields = fields
}
entTime := time.Now().Unix()
logUtils.Screen(i118Utils.I118Prt.Sprintf("generate_yaml", len(sents), out, entTime - startTime ))
}
func getCreateSent(file string) []string {
sents := make([]string, 0)
entTime := time.Now().Unix()
logUtils.Screen(i118Utils.I118Prt.Sprintf("generate_yaml", len(files), out, entTime - startTime ))
content, err := ioutil.ReadFile(file)
if err != nil {
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", file))
return sents
}
re := regexp.MustCompile(`(?siU)(CREATE TABLE.*;)`)
arr := re.FindAllString(string(content), -1)
for _, item := range arr {
sents = append(sents,item)
}
return sents
}
func getFieldsFromCreateSent(sent string) []string {
fieldLines := make([]string, 0)
re := regexp.MustCompile("(?iU)`(.+)`\\s.*,")
arr := re.FindAllStringSubmatch(string(sent), -1)
for _, item := range arr {
fieldLines = append(fieldLines, item[1])
}
return fieldLines
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册