Commit 8dc8664b authored by jianhua.zhang's avatar jianhua.zhang

1.生成结构体按照驼峰命名法

2.添加sql映射结构体类型
parent 81e205e1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/postgre-struct-maker-master.iml" filepath="$PROJECT_DIR$/.idea/postgre-struct-maker-master.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/codebuilder.iml" filepath="$PROJECT_DIR$/.idea/codebuilder.iml" />
</modules> </modules>
</component> </component>
</project> </project>
\ No newline at end of file
package util package util
import ( import (
"../model"
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/BlackCarDriver/config" "github.com/BlackCarDriver/config"
"github.com/BlackCarDriver/log" "github.com/BlackCarDriver/log"
"github.com/codebuilder/model"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"strings" "strings"
) )
...@@ -90,6 +90,7 @@ func Report() { ...@@ -90,6 +90,7 @@ func Report() {
} }
jsonName := strings.ToLower(colName) jsonName := strings.ToLower(colName)
vname := strings.ToUpper(jsonName[0:1]) + jsonName[1:] vname := strings.ToUpper(jsonName[0:1]) + jsonName[1:]
vname = CamelCase(vname)
goRes.Write("\t%-10s %-10s `json:\"%s\"`\n", vname, retype, jsonName) goRes.Write("\t%-10s %-10s `json:\"%s\"`\n", vname, retype, jsonName)
record += "\n" record += "\n"
record += vname record += vname
...@@ -109,3 +110,17 @@ func Report() { ...@@ -109,3 +110,17 @@ func Report() {
fmt.Println("表", tableName, "映射结构体已完成.") fmt.Println("表", tableName, "映射结构体已完成.")
} }
} }
func CamelCase(field string) string {
var ret string
if strings.Contains(field, "_") {
arr := strings.Split(field, "_")
for str := range arr {
ret += strings.ToUpper(arr[str][0:1]) + arr[str][1:]
}
} else {
return field
}
return ret
}
...@@ -11,6 +11,7 @@ var MGMap = map[string]string{ ...@@ -11,6 +11,7 @@ var MGMap = map[string]string{
"boolean": "bool", "boolean": "bool",
"timestamp": "time.Time", "timestamp": "time.Time",
"date": "time.Time", "date": "time.Time",
"text": "string",
} }
//MySQL type -> typeScript type //MySQL type -> typeScript type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment