Repository navigation
Expand file tree
/
Copy pathmysql_type.go
More file actions
74 lines (56 loc) · 1.6 KB
/
Copy pathmysql_type.go
File metadata and controls
74 lines (56 loc) · 1.6 KB
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
package kotlin
import (
"log"
"github.com/kyleconroy/sqlc/internal/compiler"
"github.com/kyleconroy/sqlc/internal/config"
"github.com/kyleconroy/sqlc/internal/debug"
"github.com/kyleconroy/sqlc/internal/sql/catalog"
)
func mysqlType(r *compiler.Result, col *compiler.Column, settings config.CombinedSettings) (string, bool) {
columnType := col.DataType
switch columnType {
case "varchar", "text", "char", "tinytext", "mediumtext", "longtext":
return "String", false
case "int", "integer", "smallint", "mediumint", "year":
return "Int", false
case "bigint":
return "Long", false
case "blob", "binary", "varbinary", "tinyblob", "mediumblob", "longblob":
return "String", false
case "double", "double precision", "real":
return "Double", false
case "decimal", "dec", "fixed":
return "String", false
case "enum":
// TODO: Proper Enum support
return "String", false
case "date", "datetime", "time":
return "LocalDateTime", false
case "timestamp":
return "Instant", false
case "boolean", "bool", "tinyint":
return "Boolean", false
case "json":
return "String", false
case "any":
return "Any", false
default:
for _, schema := range r.Catalog.Schemas {
for _, typ := range schema.Types {
switch t := typ.(type) {
case *catalog.Enum:
if t.Name == columnType {
if schema.Name == r.Catalog.DefaultSchema {
return DataClassName(t.Name, settings), true
}
return DataClassName(schema.Name+"_"+t.Name, settings), true
}
}
}
}
if debug.Active {
log.Printf("Unknown MySQL type: %s\n", columnType)
}
return "Any", false
}
}