diff --git a/go.mod b/go.mod index 877d653..cf3eead 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.16 + github.com/jacobbrewer1/patcher v0.1.17 github.com/jacobbrewer1/vaulty v0.1.7 github.com/jmoiron/sqlx v1.4.0 github.com/magefile/mage v1.15.0 @@ -66,7 +66,6 @@ require ( github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/piglatin v0.0.0-20140311054444-ab61287b9936 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect diff --git a/go.sum b/go.sum index 2444451..5d1ca4b 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.16 h1:AO3Um5QVMQibV6akHVA+OjLNB7uQGyHz4NGp51BX/fs= -github.com/jacobbrewer1/patcher v0.1.16/go.mod h1:zEgOixvOt2wO2WmoUreN5L5qJpCOdP2eWiYd0XZULn8= +github.com/jacobbrewer1/patcher v0.1.17 h1:qxnRb5hIQWixcu6wE8Du9s9XHsJrX2GhwP3tG+mC1XE= +github.com/jacobbrewer1/patcher v0.1.17/go.mod h1:rurnK9D/WNAbHGO86m9naLmY5EXxrerZl6NeReFouZo= github.com/jacobbrewer1/vaulty v0.1.7 h1:Y1UVwFu/zwQK3octiLh95DefSfxZ0ano25UowpYfbfc= github.com/jacobbrewer1/vaulty v0.1.7/go.mod h1:8yPrEqRwBSjVK+CUo7vQ81cDJwIzrouoaqHYy9kX0cg= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= @@ -188,8 +188,6 @@ github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/piglatin v0.0.0-20140311054444-ab61287b9936 h1:QcF4JZjvg9uNP9SdKFXspe6keOBZ1XmXkb25badRIkY= -github.com/stretchr/piglatin v0.0.0-20140311054444-ab61287b9936/go.mod h1:fnVlYnscMLDEmGbdH+GXr7JHxZCj7pCoRap6A74K5lY= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/vendor/github.com/jacobbrewer1/patcher/joiner.go b/vendor/github.com/jacobbrewer1/patcher/joiner.go index e492f80..5e3949c 100644 --- a/vendor/github.com/jacobbrewer1/patcher/joiner.go +++ b/vendor/github.com/jacobbrewer1/patcher/joiner.go @@ -19,3 +19,12 @@ func appendJoin(join Joiner, builder *strings.Builder, args *[]any) { builder.WriteString("\n") *args = append(*args, jArgs...) } + +type joinStringOption struct { + join string + args []any +} + +func (j *joinStringOption) Join() (string, []any) { + return j.join, j.args +} diff --git a/vendor/github.com/jacobbrewer1/patcher/patch_opts.go b/vendor/github.com/jacobbrewer1/patcher/patch_opts.go index 695d4df..8b2b8e6 100644 --- a/vendor/github.com/jacobbrewer1/patcher/patch_opts.go +++ b/vendor/github.com/jacobbrewer1/patcher/patch_opts.go @@ -27,6 +27,19 @@ func WithTable(table string) PatchOpt { } } +// WithFilter takes in either a Wherer or a Joiner to set the filter to use in the SQL statement +func WithFilter(filter any) PatchOpt { + return func(s *SQLPatch) { + if join, ok := filter.(Joiner); ok { + WithJoin(join)(s) + } + + if where, ok := filter.(Wherer); ok { + WithWhere(where)(s) + } + } +} + // WithWhere sets the where clause to use in the SQL statement func WithWhere(where Wherer) PatchOpt { return func(s *SQLPatch) { @@ -34,6 +47,20 @@ func WithWhere(where Wherer) PatchOpt { } } +// WithWhereStr takes a string and args to set the where clause to use in the SQL statement. This is useful when you +// want to use a simple where clause. +// +// Note. The where string should not contain the "WHERE" keyword. We recommend using the WhereTyper interface if you +// want to specify the WHERE type or do a more complex WHERE clause. +func WithWhereStr(where string, args ...any) PatchOpt { + return func(s *SQLPatch) { + appendWhere(&whereStringOption{ + where: where, + args: args, + }, s.whereSql, &s.whereArgs) + } +} + // WithJoin sets the join clause to use in the SQL statement func WithJoin(join Joiner) PatchOpt { return func(s *SQLPatch) { @@ -41,6 +68,20 @@ func WithJoin(join Joiner) PatchOpt { } } +// WithJoinStr takes a string and args to set the join clause to use in the SQL statement. This is useful when you +// want to use a simple join clause. +// +// Note. The join string should not contain the "JOIN" keyword. We recommend using the Joiner interface if you +// want to specify the JOIN type or do a more complex JOIN clause. +func WithJoinStr(join string, args ...any) PatchOpt { + return func(s *SQLPatch) { + appendJoin(&joinStringOption{ + join: join, + args: args, + }, s.joinSql, &s.joinArgs) + } +} + // WithDB sets the database connection to use func WithDB(db *sql.DB) PatchOpt { return func(s *SQLPatch) { diff --git a/vendor/github.com/jacobbrewer1/patcher/sql.go b/vendor/github.com/jacobbrewer1/patcher/sql.go index 217b09e..95caaee 100644 --- a/vendor/github.com/jacobbrewer1/patcher/sql.go +++ b/vendor/github.com/jacobbrewer1/patcher/sql.go @@ -144,7 +144,7 @@ func GenerateSQL(resource any, opts ...PatchOpt) (string, []any, error) { // and returns the final SQL string along with the arguments. func (s *SQLPatch) GenerateSQL() (string, []any, error) { if err := s.validateSQLGen(); err != nil { - return "", nil, fmt.Errorf("validate perform patch: %w", err) + return "", nil, fmt.Errorf("validate SQL generation: %w", err) } sqlBuilder := new(strings.Builder) diff --git a/vendor/github.com/jacobbrewer1/patcher/wherer.go b/vendor/github.com/jacobbrewer1/patcher/wherer.go index 39ef3fb..207f14f 100644 --- a/vendor/github.com/jacobbrewer1/patcher/wherer.go +++ b/vendor/github.com/jacobbrewer1/patcher/wherer.go @@ -49,3 +49,12 @@ func appendWhere(where Wherer, builder *strings.Builder, args *[]any) { builder.WriteString("\n") *args = append(*args, fwArgs...) } + +type whereStringOption struct { + where string + args []any +} + +func (w *whereStringOption) Where() (string, []any) { + return w.where, w.args +} diff --git a/vendor/modules.txt b/vendor/modules.txt index abb1824..f407b46 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.16 +# github.com/jacobbrewer1/patcher v0.1.17 ## explicit; go 1.23 github.com/jacobbrewer1/patcher github.com/jacobbrewer1/patcher/inserter @@ -202,8 +202,6 @@ github.com/ryanuber/go-glob # github.com/stretchr/objx v0.5.2 ## explicit; go 1.20 github.com/stretchr/objx -# github.com/stretchr/piglatin v0.0.0-20140311054444-ab61287b9936 -## explicit # github.com/stretchr/testify v1.10.0 ## explicit; go 1.17 github.com/stretchr/testify/assert