-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (40 loc) · 1.09 KB
/
Copy pathconfig.go
File metadata and controls
51 lines (40 loc) · 1.09 KB
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
package sqlz
import (
"cmp"
"github.com/rfberaldo/sqlz/internal/parser"
)
const (
defaultStructTag = "db"
defaultBind = parser.BindQuestion
defaultStmtCacheCapacity = 16
)
var (
defaultFieldNameTransformer = ToSnakeCase
)
// config contains flags that are used across internal objects.
type config struct {
defaultsApplied bool
bind parser.Bind
structTag string
fieldNameTransformer func(string) string
ignoreMissingFields bool
stmtCacheCapacity int
}
// applyDefaults returns a cfg with defaults applied, if not set.
func applyDefaults(cfg *config) *config {
if cfg == nil {
cfg = &config{}
}
// make it easy to create custom configs during tests and avoid data racing
if cfg.defaultsApplied {
return cfg
}
cfg.defaultsApplied = true
cfg.bind = cmp.Or(cfg.bind, defaultBind)
cfg.structTag = cmp.Or(cfg.structTag, defaultStructTag)
cfg.stmtCacheCapacity = cmp.Or(cfg.stmtCacheCapacity, defaultStmtCacheCapacity)
if cfg.fieldNameTransformer == nil {
cfg.fieldNameTransformer = defaultFieldNameTransformer
}
return cfg
}