-
Notifications
You must be signed in to change notification settings - Fork 3
/
option.go
154 lines (132 loc) · 3.18 KB
/
option.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package sql
import "time"
// WithUsername 设置账号
func WithUsername(username string) Option {
return func(r *Client) {
r.Username = username
}
}
// WithPassword 设置密码
func WithPassword(password string) Option {
return func(r *Client) {
r.Password = password
}
}
// WithHost 设置host
func WithHost(host string) Option {
return func(r *Client) {
r.Host = host
}
}
// WithPort 设置端口
func WithPort(port string) Option {
return func(r *Client) {
r.Port = port
}
}
// WithCharset 设置字符编码
func WithCharset(charset string) Option {
return func(r *Client) {
r.Charset = charset
}
}
// WithDatabase 设置默认连接数据库
func WithDatabase(database string) Option {
return func(r *Client) {
r.Database = database
}
}
// WithTimeZone 设置数据库时区
func WithTimeZone(timeZone string) Option {
return func(r *Client) {
r.TimeZone = timeZone
}
}
// WithMaxOpenConns 设置连接池最多同时打开的连接数
func WithMaxOpenConns(maxOpenConns int) Option {
return func(r *Client) {
r.MaxOpenConns = maxOpenConns
}
}
// WithMaxIdleConns 设置连接池里最大空闲连接数。必须要比maxOpenConns小
func WithMaxIdleConns(maxIdleConns int) Option {
return func(r *Client) {
r.MaxIdleConns = maxIdleConns
}
}
// WithMaxLifetime 设置连接池里面的连接最大存活时长
func WithMaxLifetime(maxLifetime time.Duration) Option {
return func(r *Client) {
r.MaxLifetime = maxLifetime
}
}
// WithMaxIdleTime 设置连接池里面的连接最大空闲时长
func WithMaxIdleTime(maxIdleTime time.Duration) Option {
return func(r *Client) {
r.MaxIdleTime = maxIdleTime
}
}
// WithDriverName 设置驱动名称
func WithDriverName(driverName string) Option {
return func(r *Client) {
r.DriverName = driverName
}
}
// WithDisableMetric 关闭指标采集
func WithDisableMetric(disableMetric bool) Option {
return func(r *Client) {
r.DisableMetric = disableMetric
}
}
// WithDisableTrace 关闭链路追踪
func WithDisableTrace(disableTrace bool) Option {
return func(r *Client) {
r.DisableTrace = disableTrace
}
}
// WithAddr 设置ip:port
func WithAddr(addr []string) Option {
return func(r *Client) {
r.Addr = addr
}
}
// WithDialTimeout 设置200ms
func WithDialTimeout(dialTimeout string) Option {
return func(r *Client) {
r.DialTimeout = dialTimeout
}
}
// WithOpenStrategy 设置random/in_order (default random)
func WithOpenStrategy(openStrategy string) Option {
return func(r *Client) {
r.OpenStrategy = openStrategy
}
}
// WithCompress 设置enable lz4 compression
func WithCompress(compress bool) Option {
return func(r *Client) {
r.Compress = compress
}
}
// WithMaxExecutionTime 设置执行超时时间
func WithMaxExecutionTime(maxExecutionTime string) Option {
return func(r *Client) {
r.MaxExecutionTime = maxExecutionTime
}
}
// WithDisableDebug 关闭 debug模式
func WithDisableDebug(disableDebug bool) Option {
return func(r *Client) {
r.DisableDebug = disableDebug
}
}
func WithDisablePrepare(disablePrepare bool) Option {
return func(r *Client) {
r.DisablePrepare = disablePrepare
}
}
func WithParseTime(parseTime bool) Option {
return func(r *Client) {
r.ParseTime = parseTime
}
}