完成结构体拼接

This commit is contained in:
白茶清欢 2021-10-25 21:05:42 +08:00
parent d49f21dd30
commit f6db0286a2

View File

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