diff --git a/tool/sql2go/define.go b/tool/sql2go/define.go new file mode 100644 index 0000000..49ff0aa --- /dev/null +++ b/tool/sql2go/define.go @@ -0,0 +1,51 @@ +// Package sql2go... +// +// Description : sql2go... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-10-25 4:50 下午 +package sql2go + +// sqlTypeMap mysql数据类型 => go 数据类型映射 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:50 下午 2021/10/25 +var sqlTypeMap = map[string]string{ + "int": "int", + "integer": "int", + "tinyint": "int8", + "smallint": "int16", + "mediumint": "int32", + "bigint": "int64", + "int unsigned": "uint", + "integer unsigned": "uint", + "tinyint unsigned": "uint8", + "smallint unsigned": "uint16", + "mediumint unsigned": "uint32", + "bigint unsigned": "uint64", + "bit": "byte", + "bool": "bool", + "enum": "string", + "set": "string", + "varchar": "string", + "char": "string", + "tinytext": "string", + "mediumtext": "string", + "text": "string", + "longtext": "string", + "blob": "string", + "tinyblob": "string", + "mediumblob": "string", + "longblob": "string", + "date": "time.Time", + "datetime": "time.Time", + "timestamp": "time.Time", + "time": "time.Time", + "float": "float64", + "double": "float64", + "decimal": "float64", + "binary": "string", + "varbinary": "string", +} diff --git a/tool/sql2go/parser.go b/tool/sql2go/parser.go new file mode 100644 index 0000000..adfbb5d --- /dev/null +++ b/tool/sql2go/parser.go @@ -0,0 +1,30 @@ +// Package sql2go... +// +// Description : sql2go... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-10-25 4:49 下午 +package sql2go + +import ( + "fmt" + + "github.com/xwb1989/sqlparser" +) + +// ParseSql 解析sql +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:49 下午 2021/10/25 +func ParseSql(sql string) { + var ( + stmt sqlparser.Statement + err error + ) + if stmt, err = sqlparser.Parse(sql); nil != err { + return + } + fmt.Println(stmt) +}