-
Notifications
You must be signed in to change notification settings - Fork 4
/
markdown_const.go
125 lines (112 loc) · 2.33 KB
/
markdown_const.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
119
120
121
122
123
124
125
package twowaysql
import (
"encoding/json"
"fmt"
)
// ParamType is for describing parameters
type ParamType int
const (
InvalidType ParamType = iota
BoolType
ByteType
FloatType
IntType
TextType
TimestampType
)
var paramTypeMap = map[string]ParamType{
"text": TextType,
"string": TextType,
"str": TextType,
"varchar": TextType,
"integer": IntType,
"int": IntType,
"float": FloatType,
"float64": FloatType,
"double": FloatType,
"bool": BoolType,
"boolean": BoolType,
"time": TimestampType,
"timestamp": TimestampType,
"byte": ByteType,
"tinyint": ByteType,
}
func (p ParamType) String() string {
switch p {
case InvalidType:
return "invalid"
case BoolType:
return "bool"
case ByteType:
return "byte"
case FloatType:
return "float"
case IntType:
return "integer"
case TextType:
return "text"
case TimestampType:
return "timestamp"
default:
return "unknown"
}
}
func (p ParamType) MarshalJSON() ([]byte, error) {
return json.Marshal(p.String())
}
func (p *ParamType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("data should be a string, got %s", data)
}
pt, ok := paramTypeMap[s]
if !ok {
return fmt.Errorf("invalid UserRole %s", s)
}
*p = pt
return nil
}
type MatchRule int
const (
SelectExactMatch MatchRule = iota + 1
SelectMatch
ExecExactMatch
ExecMatch
)
var matchRuleMap = map[string]MatchRule{
"select(exact-order)": SelectExactMatch,
"select": SelectExactMatch,
"select(free-order)": SelectMatch,
"exec(exact-order)": ExecExactMatch,
"exec(free-order)": ExecMatch,
"exec": ExecMatch,
}
func (m MatchRule) String() string {
switch m {
case SelectExactMatch:
return "select(exact-order)"
case SelectMatch:
return "select(free-order)"
case ExecExactMatch:
return "exec(exact-order)"
case ExecMatch:
return "exec(free-order)"
default:
return ""
}
}
func (m MatchRule) MarshalJSON() ([]byte, error) {
return json.Marshal(m.String())
}
func (m *MatchRule) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("data should be a string, got %s", data)
}
mr, ok := matchRuleMap[s]
if !ok {
return fmt.Errorf("invalid UserRole %s", s)
}
*m = mr
return nil
}