diff --git a/tool/sql2go/parser.go b/tool/sql2go/parser.go index c497cf1..e92331f 100644 --- a/tool/sql2go/parser.go +++ b/tool/sql2go/parser.go @@ -8,7 +8,6 @@ package sql2go import ( - "fmt" "strings" "git.zhangdeman.cn/zhangdeman/gopkg/util" @@ -37,6 +36,8 @@ func ParseCreateTableSql(sql string) (string, error) { } r := stmt.(*sqlparser.DDL) + structResult := "type " + util.SnakeCaseToCamel(sqlparser.String(r.NewName)) + " struct { \n" + for _, item := range r.TableSpec.Columns { data := map[string]string{ "{FIELD}": util.SnakeCaseToCamel(item.Name.String()), @@ -56,7 +57,8 @@ func ParseCreateTableSql(sql string) (string, error) { for k, v := range data { val = strings.ReplaceAll(val, k, v) } - fmt.Println(val) + structResult += val + "\n" } - return "", nil + structResult = structResult + "}" + return structResult, nil }