调试完成解析create sql
This commit is contained in:
parent
9b900680ca
commit
3d90296c6a
@ -9,22 +9,35 @@ package sql2go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/xwb1989/sqlparser"
|
||||
)
|
||||
|
||||
// ParseSql 解析sql
|
||||
// ParseCreateTableSql 解析建表sql
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:49 下午 2021/10/25
|
||||
func ParseSql(sql string) {
|
||||
func ParseCreateTableSql(sql string) {
|
||||
var (
|
||||
stmt sqlparser.Statement
|
||||
err error
|
||||
)
|
||||
if stmt, err = sqlparser.Parse(sql); nil != err {
|
||||
sql = strings.ReplaceAll(sql, " ", "")
|
||||
if stmt, err = sqlparser.ParseStrictDDL(sql); nil != err {
|
||||
fmt.Println(err.Error(), string(sql[786:]))
|
||||
return
|
||||
}
|
||||
fmt.Println(stmt)
|
||||
|
||||
r := stmt.(*sqlparser.DDL)
|
||||
for _, item := range r.TableSpec.Columns {
|
||||
defaultV := item.Type.Default
|
||||
defaultVal := "-"
|
||||
if nil != defaultV {
|
||||
defaultVal += string(defaultV.Val) + "-"
|
||||
}
|
||||
fmt.Println(item.Name.String(), defaultVal, item.Type.NotNull, string(item.Type.Comment.Val))
|
||||
}
|
||||
// fmt.Println(r.TableSpec)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user