修复数据非ddl sql, panixc问题

This commit is contained in:
白茶清欢 2022-01-14 18:34:28 +08:00
parent ab74a47a78
commit 1b603bfd93

View File

@ -8,6 +8,7 @@
package sql2go package sql2go
import ( import (
"errors"
"strings" "strings"
"git.zhangdeman.cn/zhangdeman/gopkg/util" "git.zhangdeman.cn/zhangdeman/gopkg/util"
@ -54,7 +55,10 @@ func ParseCreateTableSql(sql string) (string, *BasicTableInfo, error) {
return "", nil, err return "", nil, err
} }
r := stmt.(*sqlparser.DDL) r, ok := stmt.(*sqlparser.DDL)
if !ok {
return "", nil, errors.New("input sql is not ddl")
}
basic.TableName = sqlparser.String(r.NewName) basic.TableName = sqlparser.String(r.NewName)
basic.ModelStruct = util.SnakeCaseToCamel(basic.TableName) basic.ModelStruct = util.SnakeCaseToCamel(basic.TableName)
structResult := "type " + basic.ModelStruct + " struct { \n" structResult := "type " + basic.ModelStruct + " struct { \n"