From 870836ae7b5aaf19d532ab8915bc0391d7449ce3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 13:25:49 +0000 Subject: [PATCH] chore(deps): Bump github.com/jacobbrewer1/patcher from 0.1.15 to 0.1.16 Bumps [github.com/jacobbrewer1/patcher](https://github.com/jacobbrewer1/patcher) from 0.1.15 to 0.1.16. - [Release notes](https://github.com/jacobbrewer1/patcher/releases) - [Commits](https://github.com/jacobbrewer1/patcher/compare/v0.1.15...v0.1.16) --- updated-dependencies: - dependency-name: github.com/jacobbrewer1/patcher dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../github.com/jacobbrewer1/patcher/README.md | 18 +++--- .../github.com/jacobbrewer1/patcher/joiner.go | 15 +++++ .../github.com/jacobbrewer1/patcher/loader.go | 4 +- .../jacobbrewer1/patcher/mock_MultiFilter.go | 59 +++++++++++++++++++ .../jacobbrewer1/patcher/multifilter.go | 28 +++++++++ .../jacobbrewer1/patcher/patch_opts.go | 35 +---------- vendor/github.com/jacobbrewer1/patcher/sql.go | 2 +- .../github.com/jacobbrewer1/patcher/wherer.go | 21 +++++++ vendor/modules.txt | 2 +- 11 files changed, 142 insertions(+), 48 deletions(-) create mode 100644 vendor/github.com/jacobbrewer1/patcher/mock_MultiFilter.go create mode 100644 vendor/github.com/jacobbrewer1/patcher/multifilter.go diff --git a/go.mod b/go.mod index 6adaf70..633aecb 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/subcommands v1.2.0 github.com/hashicorp/vault/api v1.15.0 github.com/huandu/xstrings v1.5.0 - github.com/jacobbrewer1/patcher v0.1.15 + github.com/jacobbrewer1/patcher v0.1.16 github.com/jacobbrewer1/vaulty v0.1.6 github.com/jmoiron/sqlx v1.4.0 github.com/pingcap/tidb/pkg/parser v0.0.0-20241220080229-acba0cd1e2b0 diff --git a/go.sum b/go.sum index 3eb7520..ff9ecd2 100644 --- a/go.sum +++ b/go.sum @@ -94,8 +94,8 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/jacobbrewer1/patcher v0.1.15 h1:DK0xrBKlPPSNt+mXUY1AuZ7lydSin8EcHkPMt/68aIE= -github.com/jacobbrewer1/patcher v0.1.15/go.mod h1:zEgOixvOt2wO2WmoUreN5L5qJpCOdP2eWiYd0XZULn8= +github.com/jacobbrewer1/patcher v0.1.16 h1:AO3Um5QVMQibV6akHVA+OjLNB7uQGyHz4NGp51BX/fs= +github.com/jacobbrewer1/patcher v0.1.16/go.mod h1:zEgOixvOt2wO2WmoUreN5L5qJpCOdP2eWiYd0XZULn8= github.com/jacobbrewer1/vaulty v0.1.6 h1:h+STKGtDwVugWmeVu3ixlWiuU/DQYmJj0x5ADq1jm5Y= github.com/jacobbrewer1/vaulty v0.1.6/go.mod h1:kKQcDjAdRZLTlaOv6HbhqDXObDjIBgWC7FBC9rdDfbA= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= diff --git a/vendor/github.com/jacobbrewer1/patcher/README.md b/vendor/github.com/jacobbrewer1/patcher/README.md index 2686de3..21326eb 100644 --- a/vendor/github.com/jacobbrewer1/patcher/README.md +++ b/vendor/github.com/jacobbrewer1/patcher/README.md @@ -1,9 +1,8 @@ # Patcher -[![Go Reference](https://pkg.go.dev/badge/github.com/Jacobbrewer1/patcher.svg)](https://pkg.go.dev/github.com/Jacobbrewer1/patcher) +[![Go Reference](https://pkg.go.dev/badge/github.com/jacobbrewer1/patcher.svg)](https://pkg.go.dev/github.com/jacobbrewer1/patcher) [![Go Report Card](https://goreportcard.com/badge/github.com/jacobbrewer1/patcher)](https://goreportcard.com/report/github.com/jacobbrewer1/patcher) - Patcher is a GO library that provides a simple way to generate and SQL patches from structs. The library was built out of the need to generate patches for a database; when a new field is added to a struct, this would result in a bunch of new `if` checks to be created in the codebase. This library aims to solve that problem by generating the SQL patches for @@ -19,8 +18,7 @@ you. * **Struct Diffs**: It allows injecting changes from one struct to another and generating update scripts based on differences, streamlining the process of synchronizing data changes. * **Join Support**: It supports generating SQL joins by creating structs that implement the Joiner interface, - simplifying - the process of managing related data across multiple tables. + simplifying the process of managing related data across multiple tables. ## Why Use Patcher? @@ -32,10 +30,10 @@ you. required to handle different struct fields, making the code easier to read and maintain. * **Streamlines Data Synchronization**: It streamlines the process of synchronizing data changes by allowing you to inject changes from one struct to another and generate update scripts based on differences. -* **Supports Joins**: It supports generating SQL joins by creating structs that implement the Joiner interface, making it - easier to manage related data across multiple tables. -* **Flexible Configuration**: It provides flexible configuration options to customize the SQL generation process, such as - including zero or nil values in the diff. +* **Supports Joins**: It supports generating SQL joins by creating structs that implement the Joiner interface, making + it easier to manage related data across multiple tables. +* **Flexible Configuration**: It provides flexible configuration options to customize the SQL generation process, such + as including zero or nil values in the diff. * **Easy Integration**: It is easy to integrate into existing projects and can be used with any Go project that needs to generate SQL queries from structs. * **Open Source**: It is open-source and available under the Apache 2.0 license. @@ -58,7 +56,9 @@ you. #### GenerateSQL Options * `WithTable(tableName string)`: Specify the table name for the SQL query. -* `WithWhere(whereClause WhereTyper)`: Provide a where clause for the SQL query. +* `WithWhere(whereClause Wherer)`: Provide a where clause for the SQL query. + * You can pass a struct that implements the `WhereTyper` interface to use `OR` in the where clause. Patcher will + default to `AND` if the `WhereTyper` interface is not implemented. * `WithJoin(joinClause Joiner)`: Add join clauses to the SQL query. * `includeZeroValues`: Set to true to include zero values in the diff. (Only for NewDiffSQLPatch) * `includeNilValues`: Set to true to include nil values in the diff. (Only for NewDiffSQLPatch) diff --git a/vendor/github.com/jacobbrewer1/patcher/joiner.go b/vendor/github.com/jacobbrewer1/patcher/joiner.go index 16d8e99..e492f80 100644 --- a/vendor/github.com/jacobbrewer1/patcher/joiner.go +++ b/vendor/github.com/jacobbrewer1/patcher/joiner.go @@ -1,6 +1,21 @@ package patcher +import "strings" + // Joiner is an interface that can be used to specify the JOIN clause to use when the SQL is being generated. type Joiner interface { Join() (string, []any) } + +func appendJoin(join Joiner, builder *strings.Builder, args *[]any) { + if join == nil { + return + } + jSQL, jArgs := join.Join() + if jArgs == nil { + jArgs = make([]any, 0) + } + builder.WriteString(strings.TrimSpace(jSQL)) + builder.WriteString("\n") + *args = append(*args, jArgs...) +} diff --git a/vendor/github.com/jacobbrewer1/patcher/loader.go b/vendor/github.com/jacobbrewer1/patcher/loader.go index 3239448..cfc7e45 100644 --- a/vendor/github.com/jacobbrewer1/patcher/loader.go +++ b/vendor/github.com/jacobbrewer1/patcher/loader.go @@ -114,7 +114,7 @@ func (s *SQLPatch) checkSkipTag(field reflect.StructField) bool { } func (s *SQLPatch) ignoredFieldsCheck(field reflect.StructField) bool { - return s.checkIgnoredFields(strings.ToLower(field.Name)) || s.checkIgnoreFunc(field) + return s.checkIgnoredFields(field.Name) || s.checkIgnoreFunc(field) } func (s *SQLPatch) checkIgnoreFunc(field reflect.StructField) bool { @@ -122,5 +122,5 @@ func (s *SQLPatch) checkIgnoreFunc(field reflect.StructField) bool { } func (s *SQLPatch) checkIgnoredFields(field string) bool { - return len(s.ignoreFields) > 0 && slices.Contains(s.ignoreFields, strings.ToLower(field)) + return len(s.ignoreFields) > 0 && slices.Contains(s.ignoreFields, field) } diff --git a/vendor/github.com/jacobbrewer1/patcher/mock_MultiFilter.go b/vendor/github.com/jacobbrewer1/patcher/mock_MultiFilter.go new file mode 100644 index 0000000..9575980 --- /dev/null +++ b/vendor/github.com/jacobbrewer1/patcher/mock_MultiFilter.go @@ -0,0 +1,59 @@ +// Code generated by mockery. DO NOT EDIT. + +package patcher + +import mock "github.com/stretchr/testify/mock" + +// MockMultiFilter is an autogenerated mock type for the MultiFilter type +type MockMultiFilter struct { + mock.Mock +} + +// Add provides a mock function with given fields: where +func (_m *MockMultiFilter) Add(where Wherer) { + _m.Called(where) +} + +// Where provides a mock function with no fields +func (_m *MockMultiFilter) Where() (string, []interface{}) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Where") + } + + var r0 string + var r1 []interface{} + if rf, ok := ret.Get(0).(func() (string, []interface{})); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() []interface{}); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]interface{}) + } + } + + return r0, r1 +} + +// NewMockMultiFilter creates a new instance of MockMultiFilter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMultiFilter(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMultiFilter { + mock := &MockMultiFilter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/vendor/github.com/jacobbrewer1/patcher/multifilter.go b/vendor/github.com/jacobbrewer1/patcher/multifilter.go new file mode 100644 index 0000000..1d8b595 --- /dev/null +++ b/vendor/github.com/jacobbrewer1/patcher/multifilter.go @@ -0,0 +1,28 @@ +package patcher + +import "strings" + +type MultiFilter interface { + Wherer + Add(where Wherer) +} + +type multiFilter struct { + whereSql *strings.Builder + whereArgs []any +} + +func NewMultiFilter() MultiFilter { + return &multiFilter{ + whereSql: new(strings.Builder), + whereArgs: nil, + } +} + +func (m *multiFilter) Add(where Wherer) { + appendWhere(where, m.whereSql, &m.whereArgs) +} + +func (m *multiFilter) Where() (string, []any) { + return m.whereSql.String(), m.whereArgs +} diff --git a/vendor/github.com/jacobbrewer1/patcher/patch_opts.go b/vendor/github.com/jacobbrewer1/patcher/patch_opts.go index 67b9e9c..695d4df 100644 --- a/vendor/github.com/jacobbrewer1/patcher/patch_opts.go +++ b/vendor/github.com/jacobbrewer1/patcher/patch_opts.go @@ -2,7 +2,6 @@ package patcher import ( "database/sql" - "strings" ) const ( @@ -31,38 +30,14 @@ func WithTable(table string) PatchOpt { // WithWhere sets the where clause to use in the SQL statement func WithWhere(where Wherer) PatchOpt { return func(s *SQLPatch) { - if s.whereSql == nil { - s.whereSql = new(strings.Builder) - } - fwSQL, fwArgs := where.Where() - if fwArgs == nil { - fwArgs = make([]any, 0) - } - wtStr := WhereTypeAnd // default to AND - wt, ok := where.(WhereTyper) - if ok && wt.WhereType().IsValid() { - wtStr = wt.WhereType() - } - s.whereSql.WriteString(string(wtStr) + " ") - s.whereSql.WriteString(strings.TrimSpace(fwSQL)) - s.whereSql.WriteString("\n") - s.whereArgs = append(s.whereArgs, fwArgs...) + appendWhere(where, s.whereSql, &s.whereArgs) } } // WithJoin sets the join clause to use in the SQL statement func WithJoin(join Joiner) PatchOpt { return func(s *SQLPatch) { - if s.joinSql == nil { - s.joinSql = new(strings.Builder) - } - fjSQL, fjArgs := join.Join() - if fjArgs == nil { - fjArgs = make([]any, 0) - } - s.joinSql.WriteString(strings.TrimSpace(fjSQL)) - s.joinSql.WriteString("\n") - s.joinArgs = append(s.joinArgs, fjArgs...) + appendJoin(join, s.joinSql, &s.joinArgs) } } @@ -96,13 +71,9 @@ func WithIncludeNilValues() PatchOpt { // This should be the actual field name, not the JSON tag name or the db tag name. // // Note. When we parse the slice of strings, we convert them to lowercase to ensure that the comparison is -// case-insensitive. +// case-sensitive. func WithIgnoredFields(fields ...string) PatchOpt { return func(s *SQLPatch) { - for i := range fields { - fields[i] = strings.ToLower(fields[i]) - } - s.ignoreFields = fields } } diff --git a/vendor/github.com/jacobbrewer1/patcher/sql.go b/vendor/github.com/jacobbrewer1/patcher/sql.go index bdacfa0..217b09e 100644 --- a/vendor/github.com/jacobbrewer1/patcher/sql.go +++ b/vendor/github.com/jacobbrewer1/patcher/sql.go @@ -261,7 +261,7 @@ func NewDiffSQLPatch[T any](old, newT *T, opts ...PatchOpt) (*SQLPatch, error) { if patch.ignoreFields == nil { patch.ignoreFields = make([]string, 0) } - patch.ignoreFields = append(patch.ignoreFields, strings.ToLower(oldElem.Type().Field(i).Name)) + patch.ignoreFields = append(patch.ignoreFields, oldElem.Type().Field(i).Name) continue } } diff --git a/vendor/github.com/jacobbrewer1/patcher/wherer.go b/vendor/github.com/jacobbrewer1/patcher/wherer.go index 051c164..39ef3fb 100644 --- a/vendor/github.com/jacobbrewer1/patcher/wherer.go +++ b/vendor/github.com/jacobbrewer1/patcher/wherer.go @@ -1,5 +1,7 @@ package patcher +import "strings" + // Wherer is an interface that can be used to specify the WHERE clause to use. By using this interface, // the package will default to using an "AND" WHERE clause. If you want to use an "OR" WHERE clause, you can // use the WhereTyper interface instead. @@ -28,3 +30,22 @@ func (w WhereType) IsValid() bool { } return false } + +func appendWhere(where Wherer, builder *strings.Builder, args *[]any) { + if where == nil { + return + } + wSQL, fwArgs := where.Where() + if fwArgs == nil { + fwArgs = make([]any, 0) + } + wtStr := WhereTypeAnd // default to AND + wt, ok := where.(WhereTyper) + if ok && wt.WhereType().IsValid() { + wtStr = wt.WhereType() + } + builder.WriteString(string(wtStr) + " ") + builder.WriteString(strings.TrimSpace(wSQL)) + builder.WriteString("\n") + *args = append(*args, fwArgs...) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 39cd092..b0ad3e9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -108,7 +108,7 @@ github.com/huandu/xstrings # github.com/imdario/mergo v0.3.11 ## explicit; go 1.13 github.com/imdario/mergo -# github.com/jacobbrewer1/patcher v0.1.15 +# github.com/jacobbrewer1/patcher v0.1.16 ## explicit; go 1.23 github.com/jacobbrewer1/patcher github.com/jacobbrewer1/patcher/inserter