-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
46 lines (39 loc) · 938 Bytes
/
config.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
package sqlcomment
import (
"context"
)
// A Tagger is used by the driver to add tags to SQL queries.
type Tagger interface {
Tag(context.Context) Tags
}
type (
Option func(*options)
options struct {
taggers []Tagger
}
)
// WithTagger sets the taggers to be used to populate the SQL comment.
func WithTagger(taggers ...Tagger) Option {
return func(opts *options) {
opts.taggers = append(opts.taggers, taggers...)
}
}
// WithTags appends the given tags to every SQL query.
func WithTags(tags Tags) Option {
return func(opts *options) {
opts.taggers = append(opts.taggers, NewStaticTagger(tags))
}
}
// WithDriverVerTag adds `db_driver` tag with the current version of ent.
func WithDriverVerTag() Option {
return func(opts *options) {
opts.taggers = append(opts.taggers, NewDriverVersionTagger())
}
}
func buildOptions(opts []Option) options {
var o options
for _, opt := range opts {
opt(&o)
}
return o
}