-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathoptions.go
52 lines (42 loc) · 1.24 KB
/
options.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
package mssqlx
import "database/sql"
// ReadQuerySource enums.
type ReadQuerySource int
const (
// ReadQuerySourceSlaves setting indicates: read-queries will be distributed only among slaves.
//
// Note: there is no option for Master. One could use functions like `QueryMaster`, etc
// to query from masters only.
ReadQuerySourceSlaves ReadQuerySource = iota
// ReadQuerySourceAll setting indicates: read-queries will be distributed among both masters and slaves.
//
// Note: this is default setting.
ReadQuerySourceAll
)
type clusterOptions struct {
instantiate Instantiate
readQuerySource ReadQuerySource
isWsrep bool
}
// Option setter.
type Option func(*clusterOptions)
// Instantiate db.
type Instantiate func(driverName, dsn string) (*sql.DB, error)
// WithWsrep indicates galera/wsrep cluster
func WithWsrep() Option {
return func(o *clusterOptions) {
o.isWsrep = true
}
}
// WithReadQuerySource sets default sources for read-queries.
func WithReadQuerySource(source ReadQuerySource) Option {
return func(o *clusterOptions) {
o.readQuerySource = source
}
}
// WithDBInstantiate overwrite instantiate for db conn.
func WithDBInstantiate(f Instantiate) Option {
return func(o *clusterOptions) {
o.instantiate = f
}
}