-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_options.go
More file actions
38 lines (31 loc) · 858 Bytes
/
batch_options.go
File metadata and controls
38 lines (31 loc) · 858 Bytes
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
package pgutil
import (
"fmt"
"strings"
)
type (
batchInserterOptions struct {
onConflictClause string
returningClause string
returningScanner ScanFunc
}
BatchInserterConfigFunc func(*batchInserterOptions)
)
func getBatchInserterOptions(configs []BatchInserterConfigFunc) *batchInserterOptions {
options := &batchInserterOptions{}
for _, f := range configs {
f(options)
}
return options
}
func WithBatchInserterOnConflict(clause string) BatchInserterConfigFunc {
return func(o *batchInserterOptions) {
o.onConflictClause = fmt.Sprintf("ON CONFLICT %s", clause)
}
}
func WithBatchInserterReturn(columns []string, scanner ScanFunc) BatchInserterConfigFunc {
return func(o *batchInserterOptions) {
o.returningClause = fmt.Sprintf("RETURNING %s", strings.Join(quoteColumnNames(columns), ", "))
o.returningScanner = scanner
}
}