-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
config.go
76 lines (69 loc) · 1.47 KB
/
config.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
package sql
import (
"time"
"github.com/go-rel/rel"
)
// Config holds configuration for adapter.
type Config struct {
Placeholder string
Ordinal bool
InsertDefaultValues bool
DropIndexOnTable bool
EscapeChar string
ErrorFunc func(error) error
IncrementFunc func(Adapter) int
IndexToSQL func(config Config, buffer *Buffer, index rel.Index) bool
MapColumnFunc func(column *rel.Column) (string, int, int)
}
// MapColumn func.
func MapColumn(column *rel.Column) (string, int, int) {
var (
typ string
m, n int
timeLayout = "2006-01-02 15:04:05"
)
switch column.Type {
case rel.ID:
typ = "INT UNSIGNED AUTO_INCREMENT PRIMARY KEY"
case rel.BigID:
typ = "BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY"
case rel.Bool:
typ = "BOOL"
case rel.Int:
typ = "INT"
m = column.Limit
case rel.BigInt:
typ = "BIGINT"
m = column.Limit
case rel.Float:
typ = "FLOAT"
m = column.Precision
case rel.Decimal:
typ = "DECIMAL"
m = column.Precision
n = column.Scale
case rel.String:
typ = "VARCHAR"
m = column.Limit
if m == 0 {
m = 255
}
case rel.Text:
typ = "TEXT"
m = column.Limit
case rel.Date:
typ = "DATE"
timeLayout = "2006-01-02"
case rel.DateTime:
typ = "DATETIME"
case rel.Time:
typ = "TIME"
timeLayout = "15:04:05"
default:
typ = string(column.Type)
}
if t, ok := column.Default.(time.Time); ok {
column.Default = t.Format(timeLayout)
}
return typ, m, n
}