修复序列化代码
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
_ int = iota
|
||||
LongVarBinary
|
||||
LongVarChar
|
||||
GeometryCollection
|
||||
GeomCollection
|
||||
LineString
|
||||
MultiLineString
|
||||
MultiPoint
|
||||
MultiPolygon
|
||||
Point
|
||||
Polygon
|
||||
Json
|
||||
Geometry
|
||||
Enum
|
||||
Set
|
||||
Bit
|
||||
Time
|
||||
Timestamp
|
||||
DateTime
|
||||
Binary
|
||||
VarBinary
|
||||
Blob
|
||||
Year
|
||||
Decimal
|
||||
Dec
|
||||
Fixed
|
||||
Numeric
|
||||
Float
|
||||
Float4
|
||||
Float8
|
||||
Double
|
||||
Real
|
||||
TinyInt
|
||||
SmallInt
|
||||
MediumInt
|
||||
Int
|
||||
Integer
|
||||
BigInt
|
||||
MiddleInt
|
||||
Int1
|
||||
Int2
|
||||
Int3
|
||||
Int4
|
||||
Int8
|
||||
Date
|
||||
TinyBlob
|
||||
MediumBlob
|
||||
LongBlob
|
||||
Bool
|
||||
Boolean
|
||||
Serial
|
||||
NVarChar
|
||||
NChar
|
||||
Char
|
||||
Character
|
||||
VarChar
|
||||
TinyText
|
||||
Text
|
||||
MediumText
|
||||
LongText
|
||||
)
|
||||
|
||||
var SQLTypeToGoTypeMap = map[int]string{
|
||||
LongVarBinary: "[]byte",
|
||||
Binary: "[]byte",
|
||||
VarBinary: "[]byte",
|
||||
Blob: "[]byte",
|
||||
TinyBlob: "[]byte",
|
||||
MediumBlob: "[]byte",
|
||||
LongBlob: "[]byte",
|
||||
|
||||
LongVarChar: "*string",
|
||||
NVarChar: "*string",
|
||||
NChar: "*string",
|
||||
Char: "*string",
|
||||
Character: "*string",
|
||||
VarChar: "*string",
|
||||
TinyText: "*string",
|
||||
Text: "*string",
|
||||
MediumText: "*string",
|
||||
LongText: "*string",
|
||||
|
||||
Time: "*time.Time",
|
||||
Timestamp: "*time.Time",
|
||||
DateTime: "*time.Time",
|
||||
Date: "*time.Time",
|
||||
|
||||
Year: "*int64",
|
||||
TinyInt: "*int64",
|
||||
SmallInt: "*int64",
|
||||
MediumInt: "*int64",
|
||||
Int: "*int64",
|
||||
Integer: "*int64",
|
||||
BigInt: "*int64",
|
||||
MiddleInt: "*int64",
|
||||
Int1: "*int64",
|
||||
Int2: "*int64",
|
||||
Int3: "*int64",
|
||||
Int4: "*int64",
|
||||
Int8: "*int64",
|
||||
Serial: "*int64",
|
||||
|
||||
Decimal: "*float64",
|
||||
Dec: "*float64",
|
||||
Fixed: "*float64",
|
||||
Numeric: "*float64",
|
||||
Float: "*float64",
|
||||
Float4: "*float64",
|
||||
Float8: "*float64",
|
||||
Double: "*float64",
|
||||
Real: "*float64",
|
||||
|
||||
Bool: "*bool",
|
||||
Boolean: "*bool",
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var targerDir = "ddl"
|
||||
var ddlDir = "ddl"
|
||||
var genDir = "model/gmodel_gen"
|
||||
|
||||
func toPascalCase(s string) string {
|
||||
@@ -28,15 +28,27 @@ func toPascalCase(s string) string {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var name string
|
||||
var name string // 需要序列化的单独文件名
|
||||
var gdir string // 需要修改的序列化路径 model
|
||||
var ddir string // 需要修改的序列化路径 ddl
|
||||
flag.StringVar(&name, "name", "", "输入需要序列化的ddl文件名, 不需要后缀.ddl")
|
||||
flag.StringVar(&gdir, "mdir", "", "输入需要生成model的Go文件所在目录")
|
||||
flag.StringVar(&ddir, "ddir", "", "输入需要生成ddl的Go文件所在目录")
|
||||
flag.Parse()
|
||||
|
||||
if gdir != "" {
|
||||
genDir = gdir
|
||||
}
|
||||
|
||||
if ddir != "" {
|
||||
ddlDir = ddir
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
name = fmt.Sprintf("%s/%s.sql", targerDir, name)
|
||||
name = fmt.Sprintf("%s/%s.sql", ddlDir, name)
|
||||
GenFromPath(name)
|
||||
} else {
|
||||
matches, err := filepath.Glob(fmt.Sprintf("%s/*.sql", targerDir))
|
||||
matches, err := filepath.Glob(fmt.Sprintf("%s/*.sql", ddlDir))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -128,6 +140,134 @@ func GenFromPath(pth string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// log.Println(fcontent)
|
||||
|
||||
fcontent = "package model\n// TODO: 使用model的属性做你想做的"
|
||||
genGoFileName = fmt.Sprintf("%s/%s_logic.go", genDir, table.Name)
|
||||
f2, err := os.OpenFile(genGoFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f2.WriteString(fcontent)
|
||||
err = f2.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
_ int = iota
|
||||
LongVarBinary
|
||||
LongVarChar
|
||||
GeometryCollection
|
||||
GeomCollection
|
||||
LineString
|
||||
MultiLineString
|
||||
MultiPoint
|
||||
MultiPolygon
|
||||
Point
|
||||
Polygon
|
||||
Json
|
||||
Geometry
|
||||
Enum
|
||||
Set
|
||||
Bit
|
||||
Time
|
||||
Timestamp
|
||||
DateTime
|
||||
Binary
|
||||
VarBinary
|
||||
Blob
|
||||
Year
|
||||
Decimal
|
||||
Dec
|
||||
Fixed
|
||||
Numeric
|
||||
Float
|
||||
Float4
|
||||
Float8
|
||||
Double
|
||||
Real
|
||||
TinyInt
|
||||
SmallInt
|
||||
MediumInt
|
||||
Int
|
||||
Integer
|
||||
BigInt
|
||||
MiddleInt
|
||||
Int1
|
||||
Int2
|
||||
Int3
|
||||
Int4
|
||||
Int8
|
||||
Date
|
||||
TinyBlob
|
||||
MediumBlob
|
||||
LongBlob
|
||||
Bool
|
||||
Boolean
|
||||
Serial
|
||||
NVarChar
|
||||
NChar
|
||||
Char
|
||||
Character
|
||||
VarChar
|
||||
TinyText
|
||||
Text
|
||||
MediumText
|
||||
LongText
|
||||
)
|
||||
|
||||
var SQLTypeToGoTypeMap = map[int]string{
|
||||
LongVarBinary: "[]byte",
|
||||
Binary: "[]byte",
|
||||
VarBinary: "[]byte",
|
||||
Blob: "[]byte",
|
||||
TinyBlob: "[]byte",
|
||||
MediumBlob: "[]byte",
|
||||
LongBlob: "[]byte",
|
||||
|
||||
LongVarChar: "*string",
|
||||
NVarChar: "*string",
|
||||
NChar: "*string",
|
||||
Char: "*string",
|
||||
Character: "*string",
|
||||
VarChar: "*string",
|
||||
TinyText: "*string",
|
||||
Text: "*string",
|
||||
MediumText: "*string",
|
||||
LongText: "*string",
|
||||
|
||||
Time: "*time.Time",
|
||||
Timestamp: "*time.Time",
|
||||
DateTime: "*time.Time",
|
||||
Date: "*time.Time",
|
||||
|
||||
Year: "*int64",
|
||||
TinyInt: "*int64",
|
||||
SmallInt: "*int64",
|
||||
MediumInt: "*int64",
|
||||
Int: "*int64",
|
||||
Integer: "*int64",
|
||||
BigInt: "*int64",
|
||||
MiddleInt: "*int64",
|
||||
Int1: "*int64",
|
||||
Int2: "*int64",
|
||||
Int3: "*int64",
|
||||
Int4: "*int64",
|
||||
Int8: "*int64",
|
||||
Serial: "*int64",
|
||||
|
||||
Decimal: "*float64",
|
||||
Dec: "*float64",
|
||||
Fixed: "*float64",
|
||||
Numeric: "*float64",
|
||||
Float: "*float64",
|
||||
Float4: "*float64",
|
||||
Float8: "*float64",
|
||||
Double: "*float64",
|
||||
Real: "*float64",
|
||||
|
||||
Bool: "*bool",
|
||||
Boolean: "*bool",
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
// args := []string{"-name", "fs_guest"}
|
||||
targerDir = "../" + targerDir
|
||||
ddlDir = "../" + ddlDir
|
||||
genDir = "../" + genDir
|
||||
// os.Args = []string{"cmd", "-name=fs_guest"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user