From de70997cbeb7e85b214c4d316b821de419e478d5 Mon Sep 17 00:00:00 2001 From: Joshua Williams <102987390+jwlv@users.noreply.github.com> Date: Tue, 21 Jan 2025 10:34:27 -0800 Subject: [PATCH] CASMHMS-5678: Update github.com/Masterminds/squirrel --- go.mod | 2 +- go.sum | 4 +- .../squirrel/{LICENSE.txt => LICENSE} | 18 ++++----- .../github.com/Masterminds/squirrel/README.md | 4 +- .../github.com/Masterminds/squirrel/case.go | 12 +++++- .../github.com/Masterminds/squirrel/delete.go | 10 +++++ .../github.com/Masterminds/squirrel/expr.go | 2 +- .../github.com/Masterminds/squirrel/insert.go | 10 +++++ .../github.com/Masterminds/squirrel/part.go | 12 +++++- .../github.com/Masterminds/squirrel/select.go | 35 ++++++++++++----- .../Masterminds/squirrel/squirrel_ctx.go | 2 +- .../github.com/Masterminds/squirrel/update.go | 38 ++++++++++++++++++- vendor/modules.txt | 4 +- 13 files changed, 121 insertions(+), 32 deletions(-) rename vendor/github.com/Masterminds/squirrel/{LICENSE.txt => LICENSE} (79%) diff --git a/go.mod b/go.mod index c649848c..76a99cda 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Cray-HPE/hms-securestorage v1.12.2 github.com/Cray-HPE/hms-xname v1.4.0 github.com/DATA-DOG/go-sqlmock v1.5.2 - github.com/Masterminds/squirrel v1.4.0 + github.com/Masterminds/squirrel v1.5.4 github.com/golang-migrate/migrate/v4 v4.11.0 github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 diff --git a/go.sum b/go.sum index 878bee84..29a6af1b 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Masterminds/squirrel v1.4.0 h1:he5i/EXixZxrBUWcxzDYMiju9WZ3ld/l7QBNuo/eN3w= -github.com/Masterminds/squirrel v1.4.0/go.mod h1:yaPeOnPG5ZRwL9oKdTsO/prlkPbXWZlRVMQ/gGlzIuA= +github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM= +github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= diff --git a/vendor/github.com/Masterminds/squirrel/LICENSE.txt b/vendor/github.com/Masterminds/squirrel/LICENSE similarity index 79% rename from vendor/github.com/Masterminds/squirrel/LICENSE.txt rename to vendor/github.com/Masterminds/squirrel/LICENSE index 74c20a2b..b459007f 100644 --- a/vendor/github.com/Masterminds/squirrel/LICENSE.txt +++ b/vendor/github.com/Masterminds/squirrel/LICENSE @@ -1,8 +1,8 @@ -Squirrel -The Masterminds -Copyright (C) 2014-2015, Lann Martin -Copyright (C) 2015-2016, Google -Copyright (C) 2015, Matt Farina and Matt Butcher +MIT License + +Squirrel: The Masterminds +Copyright (c) 2014-2015, Lann Martin. Copyright (C) 2015-2016, Google. Copyright (C) 2015, Matt Farina and Matt Butcher. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -11,13 +11,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/Masterminds/squirrel/README.md b/vendor/github.com/Masterminds/squirrel/README.md index 76092666..1d37f282 100644 --- a/vendor/github.com/Masterminds/squirrel/README.md +++ b/vendor/github.com/Masterminds/squirrel/README.md @@ -1,4 +1,4 @@ -[![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive) +[![Stability: Maintenance](https://masterminds.github.io/stability/maintenance.svg)](https://masterminds.github.io/stability/maintenance.html) ### Squirrel is "complete". Bug fixes will still be merged (slowly). Bug reports are welcome, but I will not necessarily respond to them. If another fork (or substantially similar project) actively improves on what Squirrel does, let me know and I may link to it here. @@ -64,7 +64,7 @@ Squirrel wants to make your life easier: ```go // StmtCache caches Prepared Stmts for you -dbCache := sq.NewStmtCacher(db) +dbCache := sq.NewStmtCache(db) // StatementBuilder keeps your syntax neat mydb := sq.StatementBuilder.RunWith(dbCache) diff --git a/vendor/github.com/Masterminds/squirrel/case.go b/vendor/github.com/Masterminds/squirrel/case.go index 2eb69dd5..299e14b9 100644 --- a/vendor/github.com/Masterminds/squirrel/case.go +++ b/vendor/github.com/Masterminds/squirrel/case.go @@ -27,7 +27,7 @@ func (b *sqlizerBuffer) WriteSql(item Sqlizer) { var str string var args []interface{} - str, args, b.err = item.ToSql() + str, args, b.err = nestedToSql(item) if b.err != nil { return @@ -100,6 +100,16 @@ func (b CaseBuilder) ToSql() (string, []interface{}, error) { return data.ToSql() } +// MustSql builds the query into a SQL string and bound args. +// It panics if there are any errors. +func (b CaseBuilder) MustSql() (string, []interface{}) { + sql, args, err := b.ToSql() + if err != nil { + panic(err) + } + return sql, args +} + // what sets optional value for CASE construct "CASE [value] ..." func (b CaseBuilder) what(expr interface{}) CaseBuilder { return builder.Set(b, "What", newPart(expr)).(CaseBuilder) diff --git a/vendor/github.com/Masterminds/squirrel/delete.go b/vendor/github.com/Masterminds/squirrel/delete.go index dd979047..f3f31e63 100644 --- a/vendor/github.com/Masterminds/squirrel/delete.go +++ b/vendor/github.com/Masterminds/squirrel/delete.go @@ -121,6 +121,16 @@ func (b DeleteBuilder) ToSql() (string, []interface{}, error) { return data.ToSql() } +// MustSql builds the query into a SQL string and bound args. +// It panics if there are any errors. +func (b DeleteBuilder) MustSql() (string, []interface{}) { + sql, args, err := b.ToSql() + if err != nil { + panic(err) + } + return sql, args +} + // Prefix adds an expression to the beginning of the query func (b DeleteBuilder) Prefix(sql string, args ...interface{}) DeleteBuilder { return b.PrefixExpr(Expr(sql, args...)) diff --git a/vendor/github.com/Masterminds/squirrel/expr.go b/vendor/github.com/Masterminds/squirrel/expr.go index 4c943e5e..eba1b457 100644 --- a/vendor/github.com/Masterminds/squirrel/expr.go +++ b/vendor/github.com/Masterminds/squirrel/expr.go @@ -372,7 +372,7 @@ func (c conj) join(sep, defaultExpr string) (sql string, args []interface{}, err } var sqlParts []string for _, sqlizer := range c { - partSQL, partArgs, err := sqlizer.ToSql() + partSQL, partArgs, err := nestedToSql(sqlizer) if err != nil { return "", nil, err } diff --git a/vendor/github.com/Masterminds/squirrel/insert.go b/vendor/github.com/Masterminds/squirrel/insert.go index 1f617422..c23a5793 100644 --- a/vendor/github.com/Masterminds/squirrel/insert.go +++ b/vendor/github.com/Masterminds/squirrel/insert.go @@ -216,6 +216,16 @@ func (b InsertBuilder) ToSql() (string, []interface{}, error) { return data.ToSql() } +// MustSql builds the query into a SQL string and bound args. +// It panics if there are any errors. +func (b InsertBuilder) MustSql() (string, []interface{}) { + sql, args, err := b.ToSql() + if err != nil { + panic(err) + } + return sql, args +} + // Prefix adds an expression to the beginning of the query func (b InsertBuilder) Prefix(sql string, args ...interface{}) InsertBuilder { return b.PrefixExpr(Expr(sql, args...)) diff --git a/vendor/github.com/Masterminds/squirrel/part.go b/vendor/github.com/Masterminds/squirrel/part.go index 2926d031..c58f68f1 100644 --- a/vendor/github.com/Masterminds/squirrel/part.go +++ b/vendor/github.com/Masterminds/squirrel/part.go @@ -19,7 +19,7 @@ func (p part) ToSql() (sql string, args []interface{}, err error) { case nil: // no-op case Sqlizer: - sql, args, err = pred.ToSql() + sql, args, err = nestedToSql(pred) case string: sql = pred args = p.args @@ -29,9 +29,17 @@ func (p part) ToSql() (sql string, args []interface{}, err error) { return } +func nestedToSql(s Sqlizer) (string, []interface{}, error) { + if raw, ok := s.(rawSqlizer); ok { + return raw.toSqlRaw() + } else { + return s.ToSql() + } +} + func appendToSql(parts []Sqlizer, w io.Writer, sep string, args []interface{}) ([]interface{}, error) { for i, p := range parts { - partSql, partArgs, err := p.ToSql() + partSql, partArgs, err := nestedToSql(p) if err != nil { return nil, err } else if len(partSql) == 0 { diff --git a/vendor/github.com/Masterminds/squirrel/select.go b/vendor/github.com/Masterminds/squirrel/select.go index 315fe02a..d55ce4c7 100644 --- a/vendor/github.com/Masterminds/squirrel/select.go +++ b/vendor/github.com/Masterminds/squirrel/select.go @@ -52,7 +52,7 @@ func (d *selectData) QueryRow() RowScanner { } func (d *selectData) ToSql() (sqlStr string, args []interface{}, err error) { - sqlStr, args, err = d.toSql() + sqlStr, args, err = d.toSqlRaw() if err != nil { return } @@ -62,10 +62,6 @@ func (d *selectData) ToSql() (sqlStr string, args []interface{}, err error) { } func (d *selectData) toSqlRaw() (sqlStr string, args []interface{}, err error) { - return d.toSql() -} - -func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) { if len(d.Columns) == 0 { err = fmt.Errorf("select statements must have at least one result column") return @@ -222,6 +218,13 @@ func (b SelectBuilder) ToSql() (string, []interface{}, error) { return data.ToSql() } +func (b SelectBuilder) toSqlRaw() (string, []interface{}, error) { + data := builder.GetStruct(b).(selectData) + return data.toSqlRaw() +} + +// MustSql builds the query into a SQL string and bound args. +// It panics if there are any errors. func (b SelectBuilder) MustSql() (string, []interface{}) { sql, args, err := b.ToSql() if err != nil { @@ -230,11 +233,6 @@ func (b SelectBuilder) MustSql() (string, []interface{}) { return sql, args } -func (b SelectBuilder) toSqlRaw() (string, []interface{}, error) { - data := builder.GetStruct(b).(selectData) - return data.toSqlRaw() -} - // Prefix adds an expression to the beginning of the query func (b SelectBuilder) Prefix(sql string, args ...interface{}) SelectBuilder { return b.PrefixExpr(Expr(sql, args...)) @@ -264,6 +262,13 @@ func (b SelectBuilder) Columns(columns ...string) SelectBuilder { return builder.Extend(b, "Columns", parts).(SelectBuilder) } +// RemoveColumns remove all columns from query. +// Must add a new column with Column or Columns methods, otherwise +// return a error. +func (b SelectBuilder) RemoveColumns() SelectBuilder { + return builder.Delete(b, "Columns").(SelectBuilder) +} + // Column adds a result column to the query. // Unlike Columns, Column accepts args which will be bound to placeholders in // the columns string, for example: @@ -304,6 +309,16 @@ func (b SelectBuilder) RightJoin(join string, rest ...interface{}) SelectBuilder return b.JoinClause("RIGHT JOIN "+join, rest...) } +// InnerJoin adds a INNER JOIN clause to the query. +func (b SelectBuilder) InnerJoin(join string, rest ...interface{}) SelectBuilder { + return b.JoinClause("INNER JOIN "+join, rest...) +} + +// CrossJoin adds a CROSS JOIN clause to the query. +func (b SelectBuilder) CrossJoin(join string, rest ...interface{}) SelectBuilder { + return b.JoinClause("CROSS JOIN "+join, rest...) +} + // Where adds an expression to the WHERE clause of the query. // // Expressions are ANDed together in the generated SQL. diff --git a/vendor/github.com/Masterminds/squirrel/squirrel_ctx.go b/vendor/github.com/Masterminds/squirrel/squirrel_ctx.go index 504e763d..c20148ad 100644 --- a/vendor/github.com/Masterminds/squirrel/squirrel_ctx.go +++ b/vendor/github.com/Masterminds/squirrel/squirrel_ctx.go @@ -32,7 +32,7 @@ type QueryRowerContext interface { QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner } -// RunnerContext groups the Runner interface, along with the Contect versions of each of +// RunnerContext groups the Runner interface, along with the Context versions of each of // its methods type RunnerContext interface { Runner diff --git a/vendor/github.com/Masterminds/squirrel/update.go b/vendor/github.com/Masterminds/squirrel/update.go index e4927d79..eb2a9c4d 100644 --- a/vendor/github.com/Masterminds/squirrel/update.go +++ b/vendor/github.com/Masterminds/squirrel/update.go @@ -16,6 +16,7 @@ type updateData struct { Prefixes []Sqlizer Table string SetClauses []setClause + From Sqlizer WhereParts []Sqlizer OrderBys []string Limit string @@ -86,7 +87,11 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) { if err != nil { return "", nil, err } - valSql = vsql + if _, ok := vs.(SelectBuilder); ok { + valSql = fmt.Sprintf("(%s)", vsql) + } else { + valSql = vsql + } args = append(args, vargs...) } else { valSql = "?" @@ -96,6 +101,14 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) { } sql.WriteString(strings.Join(setSqls, ", ")) + if d.From != nil { + sql.WriteString(" FROM ") + args, err = appendToSql([]Sqlizer{d.From}, sql, "", args) + if err != nil { + return + } + } + if len(d.WhereParts) > 0 { sql.WriteString(" WHERE ") args, err = appendToSql(d.WhereParts, sql, " AND ", args) @@ -183,6 +196,16 @@ func (b UpdateBuilder) ToSql() (string, []interface{}, error) { return data.ToSql() } +// MustSql builds the query into a SQL string and bound args. +// It panics if there are any errors. +func (b UpdateBuilder) MustSql() (string, []interface{}) { + sql, args, err := b.ToSql() + if err != nil { + panic(err) + } + return sql, args +} + // Prefix adds an expression to the beginning of the query func (b UpdateBuilder) Prefix(sql string, args ...interface{}) UpdateBuilder { return b.PrefixExpr(Expr(sql, args...)) @@ -219,6 +242,19 @@ func (b UpdateBuilder) SetMap(clauses map[string]interface{}) UpdateBuilder { return b } +// From adds FROM clause to the query +// FROM is valid construct in postgresql only. +func (b UpdateBuilder) From(from string) UpdateBuilder { + return builder.Set(b, "From", newPart(from)).(UpdateBuilder) +} + +// FromSelect sets a subquery into the FROM clause of the query. +func (b UpdateBuilder) FromSelect(from SelectBuilder, alias string) UpdateBuilder { + // Prevent misnumbered parameters in nested selects (#183). + from = from.PlaceholderFormat(Question) + return builder.Set(b, "From", Alias(from, alias)).(UpdateBuilder) +} + // Where adds WHERE expressions to the query. // // See SelectBuilder.Where for more information. diff --git a/vendor/modules.txt b/vendor/modules.txt index 42e80ef4..9ef6bc28 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -25,8 +25,8 @@ github.com/Cray-HPE/hms-xname/xnametypes # github.com/DATA-DOG/go-sqlmock v1.5.2 ## explicit; go 1.15 github.com/DATA-DOG/go-sqlmock -# github.com/Masterminds/squirrel v1.4.0 -## explicit +# github.com/Masterminds/squirrel v1.5.4 +## explicit; go 1.14 github.com/Masterminds/squirrel # github.com/cenkalti/backoff/v4 v4.3.0 ## explicit; go 1.18