forked from zhuxiujia/GoMybatis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoMybatisSqlArgTypeConvert.go
118 lines (111 loc) · 2.19 KB
/
GoMybatisSqlArgTypeConvert.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
108
109
110
111
112
113
114
115
116
117
118
package GoMybatis
import (
"bytes"
"fmt"
"time"
)
const Adapter_FormateDate = `2006-01-02 15:04:05`
//Sql内容类型转换器
type GoMybatisSqlArgTypeConvert struct {
}
//Sql内容类型转换器
func (it GoMybatisSqlArgTypeConvert) Convert(argValue interface{}) string {
if argValue == nil {
return "''"
}
switch argValue.(type) {
case string:
var argStr bytes.Buffer
argStr.WriteString(`'`)
argStr.WriteString(argValue.(string))
argStr.WriteString(`'`)
return argStr.String()
case *string:
var v = argValue.(*string)
if v == nil {
return "''"
}
var argStr bytes.Buffer
argStr.WriteString(`'`)
argStr.WriteString(*v)
argStr.WriteString(`'`)
return argStr.String()
case bool:
if argValue.(bool) {
return "true"
} else {
return "false"
}
case *bool:
var v = argValue.(*bool)
if v == nil {
return "''"
}
if *v {
return "true"
} else {
return "false"
}
case time.Time:
var argStr bytes.Buffer
argStr.WriteString(`'`)
argStr.WriteString(argValue.(time.Time).Format(Adapter_FormateDate))
argStr.WriteString(`'`)
return argStr.String()
case *time.Time:
var timePtr = argValue.(*time.Time)
if timePtr == nil {
return "''"
}
var argStr bytes.Buffer
argStr.WriteString(`'`)
argStr.WriteString(timePtr.Format(Adapter_FormateDate))
argStr.WriteString(`'`)
return argStr.String()
case int, int16, int32, int64, float32, float64:
return fmt.Sprint(argValue)
case *int:
var v = argValue.(*int)
if v == nil {
return ""
}
return fmt.Sprint(*v)
case *int16:
var v = argValue.(*int16)
if v == nil {
return ""
}
return fmt.Sprint(*v)
case *int32:
var v = argValue.(*int32)
if v == nil {
return ""
}
return fmt.Sprint(*v)
case *int64:
var v = argValue.(*int64)
if v == nil {
return ""
}
return fmt.Sprint(*v)
case *float32:
var v = argValue.(*float32)
if v == nil {
return ""
}
return fmt.Sprint(*v)
case *float64:
var v = argValue.(*float64)
if v == nil {
return ""
}
return fmt.Sprint(*v)
}
return it.toString(argValue)
}
func (it GoMybatisSqlArgTypeConvert) toString(argValue interface{}) string {
if argValue == nil {
return ""
}
return fmt.Sprint(argValue)
}