/
option.go
137 lines (117 loc) · 3.35 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
package gorm_mysql
import (
"github.com/donetkit/contrib-log/glog"
"github.com/donetkit/contrib/tracer"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"time"
)
type Option func(p *config)
// WithDNS dsn
func WithDNS(dsn map[string]string) Option {
return func(p *config) {
p.dsn = dsn
}
}
// WithSlowThreshold slowThreshold
func WithSlowThreshold(slowThreshold time.Duration) Option {
return func(p *config) {
p.slowThreshold = slowThreshold
}
}
// WithIgnoreRecordNotFoundError ignoreRecordNotFoundError
func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option {
return func(p *config) {
p.ignoreRecordNotFoundError = ignoreRecordNotFoundError
}
}
// WithTracer tracerServer tracer.Server
func WithTracer(tracerServer *tracer.Server) Option {
return func(p *config) {
p.tracerServer = tracerServer
}
}
// WithAttributes configures attributes that are used to create a span.
func WithAttributes(attrs ...attribute.KeyValue) Option {
return func(p *config) {
p.attrs = append(p.attrs, attrs...)
}
}
// WithDBName configures a db.name attribute.
func WithDBName(name string) Option {
return func(p *config) {
p.attrs = append(p.attrs, semconv.DBNameKey.String(name))
}
}
// WithoutQueryVariables configures the db.statement attribute to exclude query variables
func WithoutQueryVariables() Option {
return func(p *config) {
p.excludeQueryVars = true
}
}
// WithQueryFormatter configures a query formatter
func WithQueryFormatter(queryFormatter func(query string) string) Option {
return func(p *config) {
p.queryFormatter = queryFormatter
}
}
// WithoutMetrics prevents DBStats metrics from being reported.
func WithoutMetrics() Option {
return func(p *config) {
p.excludeMetrics = true
}
}
// WithLogger prevents logger.
func WithLogger(logger glog.ILogger) Option {
return func(p *config) {
p.logger = logger
}
}
// WithDefaultStringSize defaultStringSize
func WithDefaultStringSize(defaultStringSize uint) Option {
return func(p *config) {
p.defaultStringSize = defaultStringSize
}
}
// WithDisableDatetimePrecision disableDatetimePrecision
func WithDisableDatetimePrecision(disableDatetimePrecision bool) Option {
return func(p *config) {
p.disableDatetimePrecision = disableDatetimePrecision
}
}
// WithDontSupportRenameIndex dontSupportRenameIndex
func WithDontSupportRenameIndex(dontSupportRenameIndex bool) Option {
return func(p *config) {
p.dontSupportRenameIndex = dontSupportRenameIndex
}
}
// WithDontSupportRenameColumn dontSupportRenameColumn
func WithDontSupportRenameColumn(dontSupportRenameColumn bool) Option {
return func(p *config) {
p.dontSupportRenameColumn = dontSupportRenameColumn
}
}
// WithSkipInitializeWithVersion skipInitializeWithVersion
func WithSkipInitializeWithVersion(skipInitializeWithVersion bool) Option {
return func(p *config) {
p.skipInitializeWithVersion = skipInitializeWithVersion
}
}
// WithConnMaxIdleTime connMaxIdleTime
func WithConnMaxIdleTime(connMaxIdleTime time.Duration) Option {
return func(p *config) {
p.connMaxIdleTime = connMaxIdleTime
}
}
// WithMaxOpenCons maxOpenCons
func WithMaxOpenCons(maxOpenCons int) Option {
return func(p *config) {
p.maxOpenCons = maxOpenCons
}
}
// WithMaxIdleCons maxIdleCons
func WithMaxIdleCons(maxIdleCons int) Option {
return func(p *config) {
p.maxIdleCons = maxIdleCons
}
}