/
mysql_type.go
107 lines (80 loc) · 2.26 KB
/
mysql_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package core
import (
plugin "github.com/tabbed/sqlc-go/codegen"
"github.com/tabbed/sqlc-go/sdk"
)
func mysqlType(req *plugin.CodeGenRequest, col *plugin.Column) (string, string, string, bool) {
columnType := sdk.DataType(col.Type)
switch columnType {
case "varchar", "text", "char", "tinytext", "mediumtext", "longtext":
if col.NotNull {
return "string", "string", "string", false
} else {
return "string option", "string", "string", false
}
case "int", "integer", "smallint", "mediumint", "year":
if col.NotNull {
return "int", "int", "int", false
} else {
return "int option", "int", "int", false
}
case "bigint":
if col.NotNull {
return "int64", "int64", "int64", false
} else {
return "int64 option", "int64", "int64", false
}
case "blob", "binary", "varbinary", "tinyblob", "mediumblob", "longblob":
if col.NotNull {
return "byte[]", "byte[]", "byte[]", false
} else {
return "byte[] option", "byte[]", "byte[]", false
}
case "double", "double precision":
if col.NotNull {
return "double", "double", "double", false
} else {
return "double option", "double", "double", false
}
case "real":
if col.NotNull {
return "real", "real", "real", false
} else {
return "float option", "real", "real", false
}
case "decimal", "dec", "fixed":
if col.NotNull {
return "decimal", "decimal", "decimal", false
} else {
return "decimal option", "decimal", "decimal", false
}
case "date", "datetime", "time":
if col.NotNull {
return "DateTime", "DateTime", "DateTime", false
} else {
return "DateTime option", "DateTime", "DateTime", false
}
case "timestamp":
if col.NotNull {
return "DateTimeOffset", "DateTimeOffset", "DateTimeOffset", false
} else {
return "DateTimeOffset option", "DateTimeOffset", "DateTimeOffset", false
}
case "boolean", "bool", "tinyint":
if col.NotNull {
return "bool", "bool", "bool", false
} else {
return "bool option", "bool", "bool", false
}
case "json":
if col.NotNull {
return "string", "string", "string", false
} else {
return "string option", "string", "string", false
}
case "any":
return "obj", "obj", "obj", false
default:
return columnType, "unhandled_report_issue", "unhandled_report_issue", false
}
}