Files
threshold/internal/oplog/options.go
T
Jim 591ec476e7 refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)
* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
2022-01-05 14:38:38 -05:00

69 lines
2.0 KiB
Go

package oplog
import "github.com/hashicorp/go-dbw"
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) Options {
opts := getDefaultOptions()
for _, o := range opt {
if o != nil {
o(opts)
}
}
return opts
}
// Option - how Options are passed as arguments
type Option func(Options)
// Options = how options are represented
type Options map[string]interface{}
func getDefaultOptions() Options {
return Options{
optionWithFieldMaskPaths: []string{},
optionWithSetToNullPaths: []string{},
optionWithAggregateNames: false,
optionWithOperationOptions: []dbw.Option{},
}
}
const optionWithOperationOptions = "optionWithOptions"
// WithOperationOptions represents an optional set dbw.Options. (see the dbw
// package for more info on the options)
func WithOperationOptions(opt ...dbw.Option) Option {
return func(o Options) {
o[optionWithOperationOptions] = opt
}
}
const optionWithFieldMaskPaths = "optionWithFieldMaskPaths"
// WithFieldMaskPaths represents an optional set of symbolic field paths (for example: "f.a", "f.b.d") used
// to specify a subset of fields that should be updated. (see google.golang.org/genproto/protobuf/field_mask)
func WithFieldMaskPaths(fieldMaskPaths []string) Option {
return func(o Options) {
o[optionWithFieldMaskPaths] = fieldMaskPaths
}
}
const optionWithSetToNullPaths = "optionWithSetToNullPaths"
// WithSetToNullPaths represents an optional set of symbolic field paths (for example: "f.a", "f.b.d") used
// to specify a subset of fields that should be set to null. (see google.golang.org/genproto/protobuf/field_mask)
func WithSetToNullPaths(setToNullPaths []string) Option {
return func(o Options) {
o[optionWithSetToNullPaths] = setToNullPaths
}
}
const optionWithAggregateNames = "optionWithAggregateNames"
// WithAggregateNames enables/disables the use of multiple aggregate names for Ticketers
func WithAggregateNames(enabled bool) Option {
return func(o Options) {
o[optionWithAggregateNames] = enabled
}
}