From 0b21ed81ffe0f750d96aedc132b1118e2924343d Mon Sep 17 00:00:00 2001 From: doug-martin Date: Tue, 17 Mar 2020 13:28:21 -0500 Subject: [PATCH] v9.7.1 * Fix all formatting for golangci-lint * Move to golangci-lint github action --- .github/workflows/go.yml | 2 + HISTORY.md | 5 ++ database_example_test.go | 1 - database_test.go | 2 +- delete_dataset_example_test.go | 1 - delete_dataset_test.go | 1 - dialect/mysql/mysql_test.go | 2 - dialect/sqlite3/sqlite3_dialect_test.go | 1 - dialect/sqlite3/sqlite3_test.go | 1 - docker-compose.yml | 6 ++ exec/query_executor_test.go | 5 +- exp/col.go | 1 - exp/exp_map.go | 2 +- exp/func.go | 36 +++++--- exp/insert.go | 1 - exp/join.go | 1 - exp/record.go | 5 +- exp/select_clauses_test.go | 8 -- exp/update_clauses_test.go | 5 -- expressions.go | 14 +-- expressions_example_test.go | 10 +-- goqu_example_test.go | 2 - insert_dataset_example_test.go | 4 +- insert_dataset_test.go | 3 - internal/util/column_map.go | 113 ++++++++++++++++++++++++ internal/util/reflect.go | 102 +-------------------- internal/util/reflect_test.go | 31 +------ issues_test.go | 10 +-- select_dataset_example_test.go | 9 +- select_dataset_test.go | 2 - sql_dialect_test.go | 1 - sqlgen/base_test.go | 1 - sqlgen/common_sql_generator_test.go | 3 - sqlgen/delete_sql_generator_test.go | 1 - sqlgen/expression_sql_generator.go | 5 +- sqlgen/expression_sql_generator_test.go | 3 - sqlgen/insert_sql_generator.go | 3 - sqlgen/insert_sql_generator_test.go | 2 - sqlgen/select_sql_generator_test.go | 3 - sqlgen/sql_dialect_options.go | 4 +- sqlgen/update_sql_generator.go | 1 - sqlgen/update_sql_generator_test.go | 2 - truncate_dataset_test.go | 1 - update_dataset_example_test.go | 2 +- update_dataset_test.go | 1 - 45 files changed, 178 insertions(+), 241 deletions(-) create mode 100644 internal/util/column_map.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 29651bba..95fe9434 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,6 +25,8 @@ jobs: steps: - name: checkout uses: actions/checkout@v1 + - name: Run golangci-lint + uses: actions-contrib/golangci-lint@v1 - name: Test env: GO_VERSION: ${{ matrix.go_version }} diff --git a/HISTORY.md b/HISTORY.md index 84cca2f8..d29eb47b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +# v9.7.1 + +* Fix all formatting for golangci-lint +* Move to golangci-lint github action + # v9.7.0 * [ADDED] Support for sqlserver dialect [#197](https://github.com/doug-martin/goqu/issues/197),[#205](https://github.com/doug-martin/goqu/issues/205) - [@vlanse](https://github.com/vlanse) diff --git a/database_example_test.go b/database_example_test.go index 746ce198..aecdf9ab 100644 --- a/database_example_test.go +++ b/database_example_test.go @@ -133,7 +133,6 @@ func ExampleDatabase_ExecContext() { } func ExampleDatabase_From() { - db := getDb() var names []string diff --git a/database_test.go b/database_test.go index 5e589617..cbf1e283 100644 --- a/database_test.go +++ b/database_test.go @@ -24,7 +24,7 @@ func (dtml *dbTestMockLogger) Printf(format string, v ...interface{}) { dtml.Messages = append(dtml.Messages, fmt.Sprintf(format, v...)) } -func (dtml *dbTestMockLogger) Reset(format string, v ...interface{}) { +func (dtml *dbTestMockLogger) Reset() { dtml.Messages = dtml.Messages[0:0] } diff --git a/delete_dataset_example_test.go b/delete_dataset_example_test.go index 6adbfeca..149ab653 100644 --- a/delete_dataset_example_test.go +++ b/delete_dataset_example_test.go @@ -54,7 +54,6 @@ func ExampleDeleteDataset_Executor_returning() { } func ExampleDeleteDataset_With() { - sql, _, _ := goqu.Delete("test"). With("check_vals(val)", goqu.From().Select(goqu.L("123"))). Where(goqu.C("val").Eq(goqu.From("check_vals").Select("val"))). diff --git a/delete_dataset_test.go b/delete_dataset_test.go index aef2f447..7d6fcfa1 100644 --- a/delete_dataset_test.go +++ b/delete_dataset_test.go @@ -449,7 +449,6 @@ func (dds *deleteDatasetSuite) TestExecutor() { } func (dds *deleteDatasetSuite) TestSetError() { - err1 := errors.New("error #1") err2 := errors.New("error #2") err3 := errors.New("error #3") diff --git a/dialect/mysql/mysql_test.go b/dialect/mysql/mysql_test.go index 98340558..f4850a59 100644 --- a/dialect/mysql/mysql_test.go +++ b/dialect/mysql/mysql_test.go @@ -11,7 +11,6 @@ import ( "github.com/doug-martin/goqu/v9" "github.com/doug-martin/goqu/v9/dialect/mysql" - _ "github.com/doug-martin/goqu/v9/dialect/mysql" _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/suite" ) @@ -388,7 +387,6 @@ func (mt *mysqlTest) TestInsertReturning() { e := entry{Int: 10, Float: 1.000000, String: "1.000000", Time: now, Bool: true, Bytes: []byte("1.000000")} _, err := ds.Insert().Rows(e).Returning(goqu.Star()).Executor().ScanStruct(&e) mt.Error(err) - } func (mt *mysqlTest) TestUpdate() { diff --git a/dialect/sqlite3/sqlite3_dialect_test.go b/dialect/sqlite3/sqlite3_dialect_test.go index 47067553..512536c7 100644 --- a/dialect/sqlite3/sqlite3_dialect_test.go +++ b/dialect/sqlite3/sqlite3_dialect_test.go @@ -192,7 +192,6 @@ func (sds *sqlite3DialectSuite) TestBooleanOperations() { sql, _, err = ds.Where(goqu.C("a").NotILike(regexp.MustCompile("(a|b)"))).ToSQL() sds.NoError(err) sds.Equal("SELECT * FROM `test` WHERE (`a` NOT REGEXP '(a|b)')", sql) - } func TestDatasetAdapterSuite(t *testing.T) { diff --git a/dialect/sqlite3/sqlite3_test.go b/dialect/sqlite3/sqlite3_test.go index f5e60ad4..ef604d74 100644 --- a/dialect/sqlite3/sqlite3_test.go +++ b/dialect/sqlite3/sqlite3_test.go @@ -397,7 +397,6 @@ func (st *sqlite3Suite) TestInsert_returning() { e := entry{Int: 10, Float: 1.000000, String: "1.000000", Time: now, Bool: true, Bytes: []byte("1.000000")} _, err := ds.Insert().Rows(e).Returning(goqu.Star()).Executor().ScanStruct(&e) st.Error(err) - } func (st *sqlite3Suite) TestUpdate() { diff --git a/docker-compose.yml b/docker-compose.yml index 3bd64176..3dd0c57d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: - "POSTGRES_HOST_AUTH_METHOD=trust" expose: - "5432" + ports: + - "5432:5432" mysql: image: "mysql:${MYSQL_VERSION}" @@ -17,6 +19,8 @@ services: - "MYSQL_ALLOW_EMPTY_PASSWORD=yes" expose: - "3306" + ports: + - "3306:3306" sqlserver: image: "mcr.microsoft.com/mssql/server:${SQLSERVER_VERSION}" @@ -25,6 +29,8 @@ services: - "SA_PASSWORD=qwe123QWE" expose: - "1433" + ports: + - "1433:1433" goqu: image: "golang:${GO_VERSION}" diff --git a/exec/query_executor_test.go b/exec/query_executor_test.go index 1e66e6ff..566c2ff9 100644 --- a/exec/query_executor_test.go +++ b/exec/query_executor_test.go @@ -62,7 +62,6 @@ func (qes *queryExecutorSuite) TestWithError() { } func (qes *queryExecutorSuite) TestToSQL() { - db, _, err := sqlmock.New() qes.NoError(err) @@ -71,7 +70,6 @@ func (qes *queryExecutorSuite) TestToSQL() { qes.NoError(err) qes.Equal(`SELECT * FROM "items"`, query) qes.Empty(args) - } func (qes *queryExecutorSuite) TestScanStructs_withTaggedFields() { @@ -160,7 +158,7 @@ func (qes *queryExecutorSuite) TestScanStructs_withPointerFields() { func (qes *queryExecutorSuite) TestScanStructs_withPrivateFields() { type StructWithPrivateTags struct { - private string // nolint:structcheck,unused + private string // nolint:structcheck,unused // need for test Address string `db:"address"` Name string `db:"name"` } @@ -1015,7 +1013,6 @@ func (qes *queryExecutorSuite) TestScanStruct_taggedStructs() { Age: testAge2, }, }, item) - } func (qes *queryExecutorSuite) TestScanVals() { diff --git a/exp/col.go b/exp/col.go index d3931c36..3c8bf9b2 100644 --- a/exp/col.go +++ b/exp/col.go @@ -42,7 +42,6 @@ func NewColumnListExpression(vals ...interface{}) ColumnListExpression { } else { panic(fmt.Sprintf("Cannot created expression from %+v", val)) } - } } return columnList{columns: cols} diff --git a/exp/exp_map.go b/exp/exp_map.go index c470a953..599e3052 100644 --- a/exp/exp_map.go +++ b/exp/exp_map.go @@ -108,7 +108,7 @@ func createOredExpressionFromMap(lhs IdentifierExpression, op Op) ([]Expression, return ors, nil } -// nolint:gocyclo +// nolint:gocyclo // not complex just long func createExpressionFromOp(lhs IdentifierExpression, opKey string, op Op) (exp Expression, err error) { switch strings.ToLower(opKey) { case EqOp.String(): diff --git a/exp/func.go b/exp/func.go index 55cf72d6..b128e982 100644 --- a/exp/func.go +++ b/exp/func.go @@ -16,21 +16,32 @@ func (sfe sqlFunctionExpression) Clone() Expression { return sqlFunctionExpression{name: sfe.name, args: sfe.args} } -func (sfe sqlFunctionExpression) Expression() Expression { return sfe } -func (sfe sqlFunctionExpression) Args() []interface{} { return sfe.args } -func (sfe sqlFunctionExpression) Name() string { return sfe.name } -func (sfe sqlFunctionExpression) As(val interface{}) AliasedExpression { return aliased(sfe, val) } -func (sfe sqlFunctionExpression) Eq(val interface{}) BooleanExpression { return eq(sfe, val) } -func (sfe sqlFunctionExpression) Neq(val interface{}) BooleanExpression { return neq(sfe, val) } -func (sfe sqlFunctionExpression) Gt(val interface{}) BooleanExpression { return gt(sfe, val) } -func (sfe sqlFunctionExpression) Gte(val interface{}) BooleanExpression { return gte(sfe, val) } -func (sfe sqlFunctionExpression) Lt(val interface{}) BooleanExpression { return lt(sfe, val) } -func (sfe sqlFunctionExpression) Lte(val interface{}) BooleanExpression { return lte(sfe, val) } -func (sfe sqlFunctionExpression) Between(val RangeVal) RangeExpression { return between(sfe, val) } -func (sfe sqlFunctionExpression) NotBetween(val RangeVal) RangeExpression { return notBetween(sfe, val) } +func (sfe sqlFunctionExpression) Expression() Expression { return sfe } + +func (sfe sqlFunctionExpression) Args() []interface{} { return sfe.args } + +func (sfe sqlFunctionExpression) Name() string { return sfe.name } + +func (sfe sqlFunctionExpression) As(val interface{}) AliasedExpression { return aliased(sfe, val) } + +func (sfe sqlFunctionExpression) Eq(val interface{}) BooleanExpression { return eq(sfe, val) } +func (sfe sqlFunctionExpression) Neq(val interface{}) BooleanExpression { return neq(sfe, val) } + +func (sfe sqlFunctionExpression) Gt(val interface{}) BooleanExpression { return gt(sfe, val) } +func (sfe sqlFunctionExpression) Gte(val interface{}) BooleanExpression { return gte(sfe, val) } +func (sfe sqlFunctionExpression) Lt(val interface{}) BooleanExpression { return lt(sfe, val) } +func (sfe sqlFunctionExpression) Lte(val interface{}) BooleanExpression { return lte(sfe, val) } + +func (sfe sqlFunctionExpression) Between(val RangeVal) RangeExpression { return between(sfe, val) } + +func (sfe sqlFunctionExpression) NotBetween(val RangeVal) RangeExpression { + return notBetween(sfe, val) +} + func (sfe sqlFunctionExpression) Like(val interface{}) BooleanExpression { return like(sfe, val) } func (sfe sqlFunctionExpression) NotLike(val interface{}) BooleanExpression { return notLike(sfe, val) } func (sfe sqlFunctionExpression) ILike(val interface{}) BooleanExpression { return iLike(sfe, val) } + func (sfe sqlFunctionExpression) NotILike(val interface{}) BooleanExpression { return notILike(sfe, val) } @@ -46,6 +57,7 @@ func (sfe sqlFunctionExpression) RegexpILike(val interface{}) BooleanExpression func (sfe sqlFunctionExpression) RegexpNotILike(val interface{}) BooleanExpression { return regexpNotILike(sfe, val) } + func (sfe sqlFunctionExpression) In(vals ...interface{}) BooleanExpression { return in(sfe, vals...) } func (sfe sqlFunctionExpression) NotIn(vals ...interface{}) BooleanExpression { return notIn(sfe, vals...) diff --git a/exp/insert.go b/exp/insert.go index 543a0e3c..83fc449c 100644 --- a/exp/insert.go +++ b/exp/insert.go @@ -32,7 +32,6 @@ func NewInsertExpression(rows ...interface{}) (insertExpression InsertExpression if ae, ok := rows[0].(AppendableExpression); ok { return &insert{from: ae}, nil } - } return newInsert(rows...) } diff --git a/exp/join.go b/exp/join.go index 44ca93f7..707aa7f3 100644 --- a/exp/join.go +++ b/exp/join.go @@ -8,7 +8,6 @@ type ( // The table expressions (e.g. LEFT JOIN "my_table", ON (....)) table Expression } - // todo fix this to use new interfaces // Container for all joins within a dataset conditionedJoin struct { joinExpression diff --git a/exp/record.go b/exp/record.go index c9fa0bb5..b4d6d047 100644 --- a/exp/record.go +++ b/exp/record.go @@ -47,10 +47,10 @@ func NewRecordFromStruct(i interface{}, forInsert, forUpdate bool) (r Record, er return } -func addFieldToRecord(r Record, val reflect.Value, f util.ColumnData) Record { +func addFieldToRecord(r Record, val reflect.Value, f util.ColumnData) { v, isAvailable := util.SafeGetFieldByIndex(val, f.FieldIndex) if !isAvailable { - return r + return } switch { case f.DefaultIfEmpty && util.IsEmptyValue(v): @@ -60,5 +60,4 @@ func addFieldToRecord(r Record, val reflect.Value, f util.ColumnData) Record { default: r[f.ColumnName] = reflect.Zero(f.GoType).Interface() } - return r } diff --git a/exp/select_clauses_test.go b/exp/select_clauses_test.go index dfe06056..4d998c93 100644 --- a/exp/select_clauses_test.go +++ b/exp/select_clauses_test.go @@ -69,7 +69,6 @@ func (scs *selectClausesSuite) TestSetSelect() { scs.Equal(NewColumnListExpression(Star()), c.Select()) scs.Equal(NewColumnListExpression("a"), c2.Select()) - } func (scs *selectClausesSuite) TestDistinct() { @@ -141,7 +140,6 @@ func (scs *selectClausesSuite) TestSetAlias() { } func (scs *selectClausesSuite) TestJoins() { - jc := NewConditionedJoinExpression( LeftJoinType, NewIdentifierExpression("", "test", ""), @@ -469,7 +467,6 @@ func (scs *selectClausesSuite) TestSetOffset() { } func (scs *selectClausesSuite) TestCompounds() { - ce := NewCompoundExpression(UnionCompoundType, newTestAppendableExpression("SELECT * FROM foo", []interface{}{})) c := NewSelectClauses() @@ -480,7 +477,6 @@ func (scs *selectClausesSuite) TestCompounds() { scs.Equal([]CompoundExpression{ce}, c2.Compounds()) } func (scs *selectClausesSuite) TestCompoundsAppend() { - ce := NewCompoundExpression(UnionCompoundType, newTestAppendableExpression("SELECT * FROM foo1", []interface{}{})) ce2 := NewCompoundExpression(UnionCompoundType, newTestAppendableExpression("SELECT * FROM foo2", []interface{}{})) @@ -493,7 +489,6 @@ func (scs *selectClausesSuite) TestCompoundsAppend() { } func (scs *selectClausesSuite) TestLock() { - l := NewLock(ForUpdate, Wait) c := NewSelectClauses() @@ -505,7 +500,6 @@ func (scs *selectClausesSuite) TestLock() { } func (scs *selectClausesSuite) TestSetLock() { - l := NewLock(ForUpdate, Wait) l2 := NewLock(ForUpdate, NoWait) @@ -518,7 +512,6 @@ func (scs *selectClausesSuite) TestSetLock() { } func (scs *selectClausesSuite) TestCommonTables() { - cte := NewCommonTableExpression(true, "test", newTestAppendableExpression(`SELECT * FROM "foo"`, []interface{}{})) c := NewSelectClauses() @@ -530,7 +523,6 @@ func (scs *selectClausesSuite) TestCommonTables() { } func (scs *selectClausesSuite) TestAddCommonTablesAppend() { - cte := NewCommonTableExpression(true, "test", testSQLExpression("test_cte")) cte2 := NewCommonTableExpression(true, "test", testSQLExpression("test_cte2")) diff --git a/exp/update_clauses_test.go b/exp/update_clauses_test.go index 5538c75d..dafbfe13 100644 --- a/exp/update_clauses_test.go +++ b/exp/update_clauses_test.go @@ -240,7 +240,6 @@ func (ucs *updateClausesSuite) TestSetLimit() { } func (ucs *updateClausesSuite) TestCommonTables() { - cte := NewCommonTableExpression(true, "test", newTestAppendableExpression(`SELECT * FROM "foo"`, []interface{}{})) c := NewUpdateClauses() @@ -252,7 +251,6 @@ func (ucs *updateClausesSuite) TestCommonTables() { } func (ucs *updateClausesSuite) TestAddCommonTablesAppend() { - cte := NewCommonTableExpression(true, "test", testSQLExpression("test_cte")) cte2 := NewCommonTableExpression(true, "test", testSQLExpression("test_cte2")) @@ -265,7 +263,6 @@ func (ucs *updateClausesSuite) TestAddCommonTablesAppend() { } func (ucs *updateClausesSuite) TestReturning() { - cl := NewColumnListExpression(NewIdentifierExpression("", "", "col")) c := NewUpdateClauses() @@ -277,7 +274,6 @@ func (ucs *updateClausesSuite) TestReturning() { } func (ucs *updateClausesSuite) TestHasReturning() { - cl := NewColumnListExpression(NewIdentifierExpression("", "", "col")) c := NewUpdateClauses() @@ -289,7 +285,6 @@ func (ucs *updateClausesSuite) TestHasReturning() { } func (ucs *updateClausesSuite) TestSetReturning() { - cl := NewColumnListExpression(NewIdentifierExpression("", "", "col")) cl2 := NewColumnListExpression(NewIdentifierExpression("", "", "col2")) diff --git a/expressions.go b/expressions.go index 1715fd15..4e20d057 100644 --- a/expressions.go +++ b/expressions.go @@ -120,7 +120,7 @@ func COALESCE(vals ...interface{}) exp.SQLFunctionExpression { return Func("COALESCE", vals...) } -// nolint: golint +//nolint:stylecheck,golint // sql function name func ROW_NUMBER() exp.SQLFunctionExpression { return Func("ROW_NUMBER") } @@ -129,17 +129,17 @@ func RANK() exp.SQLFunctionExpression { return Func("RANK") } -// nolint: golint +//nolint:stylecheck,golint // sql function name func DENSE_RANK() exp.SQLFunctionExpression { return Func("DENSE_RANK") } -// nolint: golint +//nolint:stylecheck,golint // sql function name func PERCENT_RANK() exp.SQLFunctionExpression { return Func("PERCENT_RANK") } -// nolint: golint +//nolint:stylecheck,golint //sql function name func CUME_DIST() exp.SQLFunctionExpression { return Func("CUME_DIST") } @@ -148,17 +148,17 @@ func NTILE(n int) exp.SQLFunctionExpression { return Func("NTILE", n) } -// nolint: golint +//nolint:stylecheck,golint //sql function name func FIRST_VALUE(val interface{}) exp.SQLFunctionExpression { return newIdentifierFunc("FIRST_VALUE", val) } -// nolint: golint +//nolint:stylecheck,golint //sql function name func LAST_VALUE(val interface{}) exp.SQLFunctionExpression { return newIdentifierFunc("LAST_VALUE", val) } -// nolint: golint +//nolint:stylecheck,golint //sql function name func NTH_VALUE(val interface{}, nth int) exp.SQLFunctionExpression { if s, ok := val.(string); ok { val = I(s) diff --git a/expressions_example_test.go b/expressions_example_test.go index 8c0d92ef..73c7bbb9 100644 --- a/expressions_example_test.go +++ b/expressions_example_test.go @@ -1,4 +1,4 @@ -// nolint:lll +// nolint:lll // sql statements are long package goqu_test import ( @@ -125,7 +125,6 @@ func ExampleAnd_withExOr() { } func ExampleC() { - sql, args, _ := goqu.From("test"). Select(goqu.C("*")). ToSQL() @@ -494,7 +493,6 @@ func ExampleDefault() { // Output: // INSERT INTO "items" ("address", "name") VALUES (DEFAULT, DEFAULT) [] // INSERT INTO "items" ("address", "name") VALUES (DEFAULT, DEFAULT) [] - } func ExampleDoNothing() { @@ -515,7 +513,6 @@ func ExampleDoNothing() { // Output: // INSERT INTO "items" ("address", "name") VALUES ('111 Address', 'bob') ON CONFLICT DO NOTHING [] // INSERT INTO "items" ("address", "name") VALUES (?, ?) ON CONFLICT DO NOTHING [111 Address bob] - } func ExampleDoUpdate() { @@ -1231,7 +1228,6 @@ func ExampleUsing_withIdentifier() { } func ExampleEx() { - ds := goqu.From("items").Where( goqu.Ex{ "col1": "a", @@ -1291,7 +1287,7 @@ func ExampleExOr() { ).ToSQL() fmt.Println(sql, args) - // nolint:lll + // nolint:lll // sql statements are long // Output: // SELECT * FROM "items" WHERE (("col1" = 'a') OR ("col2" = 1) OR ("col3" IS TRUE) OR ("col4" IS FALSE) OR ("col5" IS NULL) OR ("col6" IN ('a', 'b', 'c'))) [] } @@ -1333,11 +1329,9 @@ func ExampleExOr_withOp() { // SELECT * FROM "items" WHERE (("col1" > 1) OR ("col2" >= 1) OR ("col3" < 1) OR ("col4" <= 1)) // SELECT * FROM "items" WHERE (("col1" LIKE 'a%') OR ("col2" NOT LIKE 'a%') OR ("col3" ILIKE 'a%') OR ("col4" NOT ILIKE 'a%')) // SELECT * FROM "items" WHERE (("col1" ~ '^(a|b)') OR ("col2" !~ '^(a|b)') OR ("col3" ~* '^(a|b)') OR ("col4" !~* '^(a|b)')) - } func ExampleOp_comparisons() { - ds := goqu.From("test").Where(goqu.Ex{ "a": 10, "b": goqu.Op{"neq": 10}, diff --git a/goqu_example_test.go b/goqu_example_test.go index de8efd00..ba365bca 100644 --- a/goqu_example_test.go +++ b/goqu_example_test.go @@ -177,7 +177,6 @@ func ExampleDialect_datasetSqlite3() { // Creating a sqlite3 database. Be sure to import the sqlite3 adapter func ExampleDialect_dbSqlite3() { // import _ "github.com/doug-martin/goqu/v9/adapters/sqlite3" - type item struct { ID int64 `db:"id"` Address string `db:"address"` @@ -225,7 +224,6 @@ func ExampleDialect_dbSqlite3() { } func ExampleSetTimeLocation() { - loc, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) diff --git a/insert_dataset_example_test.go b/insert_dataset_example_test.go index 3c6a7720..9a3b148a 100644 --- a/insert_dataset_example_test.go +++ b/insert_dataset_example_test.go @@ -1,4 +1,4 @@ -// nolint:lll +// nolint:lll // SQL statements are long package goqu_test import ( @@ -161,7 +161,6 @@ func ExampleInsertDataset_Executor_recordReturning() { for _, u := range insertedUsers { fmt.Printf("Inserted user: [ID=%d], [FirstName=%+s] [LastName=%s]\n", u.ID.Int64, u.FirstName, u.LastName) } - } // Output: @@ -203,7 +202,6 @@ func ExampleInsertDataset_Executor_scanStructs() { for _, u := range insertedUsers { fmt.Printf("Inserted user: [ID=%d], [FirstName=%+s] [LastName=%s]\n", u.ID.Int64, u.FirstName, u.LastName) } - } // Output: diff --git a/insert_dataset_test.go b/insert_dataset_test.go index b27bb98b..2ef25d0d 100644 --- a/insert_dataset_test.go +++ b/insert_dataset_test.go @@ -208,7 +208,6 @@ func (ids *insertDatasetSuite) TestFromQuery() { } func (ids *insertDatasetSuite) TestVals() { - val1 := []interface{}{ "a", "b", } @@ -300,7 +299,6 @@ func (ids *insertDatasetSuite) TestClearRows() { clauses: exp.NewInsertClauses().SetInto(C("items")).SetRows([]interface{}{r}), }, ) - } func (ids *insertDatasetSuite) TestOnConflict() { @@ -452,7 +450,6 @@ func (ids *insertDatasetSuite) TestToSQL_ReturnedError() { } func (ids *insertDatasetSuite) TestSetError() { - err1 := errors.New("error #1") err2 := errors.New("error #2") err3 := errors.New("error #3") diff --git a/internal/util/column_map.go b/internal/util/column_map.go new file mode 100644 index 00000000..98a59ff7 --- /dev/null +++ b/internal/util/column_map.go @@ -0,0 +1,113 @@ +package util + +import ( + "reflect" + "sort" + "strings" + + "github.com/doug-martin/goqu/v9/internal/tag" +) + +type ( + ColumnData struct { + ColumnName string + FieldIndex []int + ShouldInsert bool + ShouldUpdate bool + DefaultIfEmpty bool + GoType reflect.Type + } + ColumnMap map[string]ColumnData +) + +func newColumnMap(t reflect.Type, fieldIndex []int, prefixes []string) ColumnMap { + cm, n := ColumnMap{}, t.NumField() + var subColMaps []ColumnMap + for i := 0; i < n; i++ { + f := t.Field(i) + if f.Anonymous && (f.Type.Kind() == reflect.Struct || f.Type.Kind() == reflect.Ptr) { + goquTag := tag.New("db", f.Tag) + if !goquTag.Contains("-") { + subColMaps = append(subColMaps, getStructColumnMap(&f, fieldIndex, goquTag.Values(), prefixes)) + } + } else if f.PkgPath == "" { + dbTag := tag.New("db", f.Tag) + // if PkgPath is empty then it is an exported field + columnName := getColumnName(&f, dbTag) + if !dbTag.Equals("-") { + if !implementsScanner(f.Type) { + subCm := getStructColumnMap(&f, fieldIndex, []string{columnName}, prefixes) + if len(subCm) != 0 { + subColMaps = append(subColMaps, subCm) + continue + } + } + goquTag := tag.New("goqu", f.Tag) + columnName = strings.Join(append(prefixes, columnName), ".") + cm[columnName] = newColumnData(&f, columnName, fieldIndex, goquTag) + } + } + } + return cm.Merge(subColMaps) +} + +func (cm ColumnMap) Cols() []string { + var structCols []string + for key := range cm { + structCols = append(structCols, key) + } + sort.Strings(structCols) + return structCols +} + +func (cm ColumnMap) Merge(colMaps []ColumnMap) ColumnMap { + for _, subCm := range colMaps { + for key, val := range subCm { + if _, ok := cm[key]; !ok { + cm[key] = val + } + } + } + return cm +} + +func implementsScanner(t reflect.Type) bool { + if IsPointer(t.Kind()) { + t = t.Elem() + } + if reflect.PtrTo(t).Implements(scannerType) { + return true + } + if !IsStruct(t.Kind()) { + return true + } + + return false +} + +func newColumnData(f *reflect.StructField, columnName string, fieldIndex []int, goquTag tag.Options) ColumnData { + return ColumnData{ + ColumnName: columnName, + ShouldInsert: !goquTag.Contains(skipInsertTagName), + ShouldUpdate: !goquTag.Contains(skipUpdateTagName), + DefaultIfEmpty: goquTag.Contains(defaultIfEmptyTagName), + FieldIndex: append(fieldIndex, f.Index...), + GoType: f.Type, + } +} + +func getStructColumnMap(f *reflect.StructField, fieldIndex []int, fieldNames, prefixes []string) ColumnMap { + subFieldIndexes := append(fieldIndex, f.Index...) + subPrefixes := append(prefixes, fieldNames...) + if f.Type.Kind() == reflect.Ptr { + return newColumnMap(f.Type.Elem(), subFieldIndexes, subPrefixes) + } + return newColumnMap(f.Type, subFieldIndexes, subPrefixes) +} + +func getColumnName(f *reflect.StructField, dbTag tag.Options) string { + if dbTag.IsEmpty() { + return columnRenameFunction(f.Name) + } + return dbTag.Values()[0] +} diff --git a/internal/util/reflect.go b/internal/util/reflect.go index 2e5ddef3..43da0b8c 100644 --- a/internal/util/reflect.go +++ b/internal/util/reflect.go @@ -3,24 +3,10 @@ package util import ( "database/sql" "reflect" - "sort" "strings" "sync" "github.com/doug-martin/goqu/v9/internal/errors" - "github.com/doug-martin/goqu/v9/internal/tag" -) - -type ( - ColumnData struct { - ColumnName string - FieldIndex []int - ShouldInsert bool - ShouldUpdate bool - DefaultIfEmpty bool - GoType reflect.Type - } - ColumnMap map[string]ColumnData ) const ( @@ -209,93 +195,7 @@ func GetColumnMap(i interface{}) (ColumnMap, error) { structMapCacheLock.Lock() defer structMapCacheLock.Unlock() if _, ok := structMapCache[t]; !ok { - structMapCache[t] = createColumnMap(t, []int{}, []string{}) + structMapCache[t] = newColumnMap(t, []int{}, []string{}) } return structMapCache[t], nil } - -func createColumnMap(t reflect.Type, fieldIndex []int, prefixes []string) ColumnMap { - cm, n := ColumnMap{}, t.NumField() - var subColMaps []ColumnMap - for i := 0; i < n; i++ { - f := t.Field(i) - if f.Anonymous && (f.Type.Kind() == reflect.Struct || f.Type.Kind() == reflect.Ptr) { - goquTag := tag.New("db", f.Tag) - if !goquTag.Contains("-") { - subFieldIndexes := append(fieldIndex, f.Index...) - subPrefixes := append(prefixes, goquTag.Values()...) - if f.Type.Kind() == reflect.Ptr { - subColMaps = append(subColMaps, createColumnMap(f.Type.Elem(), subFieldIndexes, subPrefixes)) - } else { - subColMaps = append(subColMaps, createColumnMap(f.Type, subFieldIndexes, subPrefixes)) - } - } - } else if f.PkgPath == "" { - dbTag := tag.New("db", f.Tag) - // if PkgPath is empty then it is an exported field - var columnName string - if dbTag.IsEmpty() { - columnName = columnRenameFunction(f.Name) - } else { - columnName = dbTag.Values()[0] - } - if !dbTag.Equals("-") { - if !implementsScanner(f.Type) { - subFieldIndexes := append(fieldIndex, f.Index...) - subPrefixes := append(prefixes, columnName) - var subCm ColumnMap - if f.Type.Kind() == reflect.Ptr { - subCm = createColumnMap(f.Type.Elem(), subFieldIndexes, subPrefixes) - } else { - subCm = createColumnMap(f.Type, subFieldIndexes, subPrefixes) - } - if len(subCm) != 0 { - subColMaps = append(subColMaps, subCm) - continue - } - } - goquTag := tag.New("goqu", f.Tag) - columnName = strings.Join(append(prefixes, columnName), ".") - cm[columnName] = ColumnData{ - ColumnName: columnName, - ShouldInsert: !goquTag.Contains(skipInsertTagName), - ShouldUpdate: !goquTag.Contains(skipUpdateTagName), - DefaultIfEmpty: goquTag.Contains(defaultIfEmptyTagName), - FieldIndex: append(fieldIndex, f.Index...), - GoType: f.Type, - } - } - } - } - for _, subCm := range subColMaps { - for key, val := range subCm { - if _, ok := cm[key]; !ok { - cm[key] = val - } - } - } - return cm -} - -func (cm ColumnMap) Cols() []string { - var structCols []string - for key := range cm { - structCols = append(structCols, key) - } - sort.Strings(structCols) - return structCols -} - -func implementsScanner(t reflect.Type) bool { - if IsPointer(t.Kind()) { - t = t.Elem() - } - if reflect.PtrTo(t).Implements(scannerType) { - return true - } - if !IsStruct(t.Kind()) { - return true - } - - return false -} diff --git a/internal/util/reflect_test.go b/internal/util/reflect_test.go index 8fc692b0..16912b84 100644 --- a/internal/util/reflect_test.go +++ b/internal/util/reflect_test.go @@ -89,7 +89,6 @@ type reflectTest struct { } func (rt *reflectTest) TestIsUint() { - for _, v := range uints { rt.True(IsUint(reflect.ValueOf(v).Kind())) } @@ -408,7 +407,6 @@ func (rt *reflectTest) TestColumnRename() { } func (rt *reflectTest) TestParallelGetColumnMap() { - type item struct { id uint name string @@ -438,7 +436,6 @@ func (rt *reflectTest) TestParallelGetColumnMap() { } func (rt *reflectTest) TestAssignStructVals_withStruct() { - type TestStruct struct { Str string Int int64 @@ -491,7 +488,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithPointerVals() { } func (rt *reflectTest) TestAssignStructVals_withStructWithEmbeddedStruct() { - type EmbeddedStruct struct { Str string } @@ -521,7 +517,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithEmbeddedStruct() { } func (rt *reflectTest) TestAssignStructVals_withStructWithEmbeddedStructPointer() { - type EmbeddedStruct struct { Str string } @@ -551,7 +546,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithEmbeddedStructPointer( } func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedEmbeddedStruct() { - type EmbeddedStruct struct { Str string } @@ -581,7 +575,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedEmbeddedStruct() } func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedEmbeddedPointer() { - type EmbeddedStruct struct { Str string } @@ -611,7 +604,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedEmbeddedPointer( } func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedStructField() { - type EmbeddedStruct struct { Str string } @@ -641,7 +633,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedStructField() { } func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedPointerField() { - type EmbeddedStruct struct { Str string } @@ -671,7 +662,6 @@ func (rt *reflectTest) TestAssignStructVals_withStructWithTaggedPointerField() { } func (rt *reflectTest) TestGetColumnMap_withStruct() { - type TestStruct struct { Str string Int int64 @@ -690,7 +680,6 @@ func (rt *reflectTest) TestGetColumnMap_withStruct() { } func (rt *reflectTest) TestGetColumnMap_withStructGoquTags() { - type TestStruct struct { Str string `goqu:"skipinsert,skipupdate"` Int int64 `goqu:"skipinsert"` @@ -718,7 +707,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructGoquTags() { } func (rt *reflectTest) TestGetColumnMap_withStructWithTag() { - type TestStruct struct { Str string `db:"s"` Int int64 `db:"i"` @@ -737,7 +725,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructWithTag() { } func (rt *reflectTest) TestGetColumnMap_withStructWithTagAndGoquTag() { - type TestStruct struct { Str string `db:"s" goqu:"skipinsert,skipupdate"` Int int64 `db:"i" goqu:"skipinsert"` @@ -756,7 +743,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructWithTagAndGoquTag() { } func (rt *reflectTest) TestGetColumnMap_withStructWithTransientFields() { - type TestStruct struct { Str string Int int64 @@ -774,7 +760,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructWithTransientFields() { } func (rt *reflectTest) TestGetColumnMap_withSliceOfStructs() { - type TestStruct struct { Str string Int int64 @@ -793,15 +778,12 @@ func (rt *reflectTest) TestGetColumnMap_withSliceOfStructs() { } func (rt *reflectTest) TestGetColumnMap_withNonStruct() { - var v int64 _, err := GetColumnMap(&v) rt.EqualError(err, "goqu: cannot scan into this type: int64") - } func (rt *reflectTest) TestGetColumnMap_withStructWithEmbeddedStruct() { - type EmbeddedStruct struct { Str string } @@ -823,7 +805,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructWithEmbeddedStruct() { } func (rt *reflectTest) TestGetColumnMap_withStructWithEmbeddedStructPointer() { - type EmbeddedStruct struct { Str string } @@ -845,7 +826,6 @@ func (rt *reflectTest) TestGetColumnMap_withStructWithEmbeddedStructPointer() { } func (rt *reflectTest) TestGetColumnMap_withIgnoredEmbeddedStruct() { - type EmbeddedStruct struct { Str string } @@ -866,7 +846,6 @@ func (rt *reflectTest) TestGetColumnMap_withIgnoredEmbeddedStruct() { } func (rt *reflectTest) TestGetColumnMap_withIgnoredEmbeddedPointerStruct() { - type EmbeddedStruct struct { Str string } @@ -887,9 +866,8 @@ func (rt *reflectTest) TestGetColumnMap_withIgnoredEmbeddedPointerStruct() { } func (rt *reflectTest) TestGetColumnMap_withPrivateFields() { - type TestStruct struct { - str string // nolint:structcheck,unused + str string // nolint:structcheck,unused // not used directly but needed for test Int int64 Bool bool Valuer *sql.NullString @@ -905,9 +883,8 @@ func (rt *reflectTest) TestGetColumnMap_withPrivateFields() { } func (rt *reflectTest) TestGetColumnMap_withPrivateEmbeddedFields() { - type TestEmbedded struct { - str string // nolint:structcheck,unused + str string // nolint:structcheck,unused // not used directly but need for test Int int64 } @@ -927,7 +904,6 @@ func (rt *reflectTest) TestGetColumnMap_withPrivateEmbeddedFields() { } func (rt *reflectTest) TestGetColumnMap_withEmbeddedTaggedStruct() { - type TestEmbedded struct { Bool bool Valuer *sql.NullString @@ -975,7 +951,6 @@ func (rt *reflectTest) TestGetColumnMap_withEmbeddedTaggedStruct() { } func (rt *reflectTest) TestGetColumnMap_withEmbeddedTaggedStructPointer() { - type TestEmbedded struct { Bool bool Valuer *sql.NullString @@ -1022,7 +997,6 @@ func (rt *reflectTest) TestGetColumnMap_withEmbeddedTaggedStructPointer() { } func (rt *reflectTest) TestGetColumnMap_withTaggedStructField() { - type TestEmbedded struct { Bool bool Valuer *sql.NullString @@ -1070,7 +1044,6 @@ func (rt *reflectTest) TestGetColumnMap_withTaggedStructField() { } func (rt *reflectTest) TestGetColumnMap_withTaggedStructPointerField() { - type TestEmbedded struct { Bool bool Valuer *sql.NullString diff --git a/issues_test.go b/issues_test.go index 7c3bdf20..78921c9d 100644 --- a/issues_test.go +++ b/issues_test.go @@ -45,7 +45,6 @@ func (gis *githubIssuesSuite) TestIssue49() { // Test for https://github.com/doug-martin/goqu/issues/115 func (gis *githubIssuesSuite) TestIssue115() { - type TestStruct struct { Field string } @@ -62,7 +61,7 @@ func (gis *githubIssuesSuite) TestIssue118_withEmbeddedStructWithoutExportedFiel // struct is in a custom package type SimpleRole struct { sync.RWMutex - permissions []string // nolint:structcheck,unused + permissions []string // nolint:structcheck,unused //needed for test } // ..... @@ -125,7 +124,6 @@ func (gis *githubIssuesSuite) TestIssue118_withEmbeddedStructWithoutExportedFiel `"created_at"='0001-01-01T00:00:00Z',"id"='',"key"='user',"name"='User role' RETURNING "id"`, sql, ) - } // Test for https://github.com/doug-martin/goqu/issues/118 @@ -133,7 +131,7 @@ func (gis *githubIssuesSuite) TestIssue118_withNilEmbeddedStructWithExportedFiel // struct is in a custom package type SimpleRole struct { sync.RWMutex - permissions []string // nolint:structcheck,unused + permissions []string // nolint:structcheck,unused // needed for test IDStr string } @@ -202,12 +200,10 @@ func (gis *githubIssuesSuite) TestIssue118_withNilEmbeddedStructWithExportedFiel `"created_at"='0001-01-01T00:00:00Z',"id"='',"idstr"='',"key"='user',"name"='User role' RETURNING "id"`, sql, ) - } // Test for https://github.com/doug-martin/goqu/issues/118 func (gis *githubIssuesSuite) TestIssue140() { - sql, arg, err := goqu.Insert(`test`).Returning().ToSQL() gis.NoError(err) gis.Empty(arg) @@ -249,7 +245,6 @@ func (gis *githubIssuesSuite) TestIssue140() { `DELETE FROM "test"`, sql, ) - } // Test for https://github.com/doug-martin/goqu/issues/164 @@ -425,7 +420,6 @@ func (gis *githubIssuesSuite) TestIssue185() { var i []int gis.NoError(ds.ScanValsContext(ctx, &i)) gis.Equal([]int{1, 2, 3, 4}, i) - } func TestGithubIssuesSuite(t *testing.T) { diff --git a/select_dataset_example_test.go b/select_dataset_example_test.go index 416b2de0..7e1f1994 100644 --- a/select_dataset_example_test.go +++ b/select_dataset_example_test.go @@ -1,4 +1,4 @@ -// nolint:lll +// nolint:lll // sql statements are long package goqu_test import ( @@ -118,7 +118,7 @@ func ExampleSelectDataset() { sql, args, _ = ds.Prepared(true).ToSQL() fmt.Println(sql, args) - // nolint:lll + // nolint:lll // SQL statements are long // Output: // SELECT COUNT(*) FROM "test" INNER JOIN "test2" ON ("test"."fkey" = "test2"."id") LEFT JOIN "test3" ON ("test2"."fkey" = "test3"."id") WHERE ((("test"."name" ~ '^(a|b)') AND ("test2"."amount" IS NOT NULL)) AND (("test3"."id" IS NULL) OR ("test3"."status" IN ('passed', 'active', 'registered')))) GROUP BY "test"."user_id" HAVING (AVG("test3"."age") > 10) ORDER BY "test"."created" DESC NULLS LAST [] // SELECT COUNT(*) FROM "test" INNER JOIN "test2" ON ("test"."fkey" = "test2"."id") LEFT JOIN "test3" ON ("test2"."fkey" = "test3"."id") WHERE ((("test"."name" ~ ?) AND ("test2"."amount" IS NOT NULL)) AND (("test3"."id" IS NULL) OR ("test3"."status" IN (?, ?, ?)))) GROUP BY "test"."user_id" HAVING (AVG("test3"."age") > ?) ORDER BY "test"."created" DESC NULLS LAST [^(a|b) passed active registered 10] @@ -615,7 +615,6 @@ func ExampleSelectDataset_Join() { // SELECT * FROM "test" INNER JOIN "test2" USING ("common_column") // SELECT * FROM "test" INNER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) ON ("test"."fkey" = "test2"."Id") // SELECT * FROM "test" INNER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") - } func ExampleSelectDataset_InnerJoin() { @@ -1228,7 +1227,7 @@ func ExampleSelectDataset_Prepared() { "col5": []string{"a", "b", "c"}, }).ToSQL() fmt.Println(sql, args) - // nolint:lll + // nolint:lll // sql statements are long // Output: // SELECT * FROM "items" WHERE (("col1" = ?) AND ("col2" = ?) AND ("col3" IS TRUE) AND ("col4" IS FALSE) AND ("col5" IN (?, ?, ?))) [a 1 a b c] } @@ -1496,7 +1495,6 @@ func ExampleSelectDataset_ScanVals() { } func ExampleSelectDataset_ScanVal() { - db := getDb() findUserIDByName := func(name string) { var id int64 @@ -1523,7 +1521,6 @@ func ExampleSelectDataset_ScanVal() { } func ExampleSelectDataset_Count() { - if count, err := getDb().From("goqu_user").Count(); err != nil { fmt.Println(err.Error()) } else { diff --git a/select_dataset_test.go b/select_dataset_test.go index f6d80803..46d57480 100644 --- a/select_dataset_test.go +++ b/select_dataset_test.go @@ -398,7 +398,6 @@ func (sds *selectDatasetSuite) TestJoin() { } func (sds *selectDatasetSuite) TestInnerJoin() { - bd := From("test") sds.assertCases( selectTestCase{ @@ -1471,7 +1470,6 @@ func (sds *selectDatasetSuite) TestPluck_WithPreparedStatement() { } func (sds *selectDatasetSuite) TestSetError() { - err1 := errors.New("error #1") err2 := errors.New("error #2") err3 := errors.New("error #3") diff --git a/sql_dialect_test.go b/sql_dialect_test.go index 3a8f2c25..43b621ed 100644 --- a/sql_dialect_test.go +++ b/sql_dialect_test.go @@ -45,7 +45,6 @@ func (dts *dialectTestSuite) TestToUpdateSQL() { d.ToUpdateSQL(b, uc) um.AssertExpectations(dts.T()) - } func (dts *dialectTestSuite) TestToInsertSQL() { diff --git a/sqlgen/base_test.go b/sqlgen/base_test.go index e6b40bff..cc0b9525 100644 --- a/sqlgen/base_test.go +++ b/sqlgen/base_test.go @@ -29,7 +29,6 @@ func (bsgs *baseSQLGeneratorSuite) assertPreparedSQL( } else { bsgs.Equal(expectedArgs, actualArgs) } - } func (bsgs *baseSQLGeneratorSuite) assertErrorSQL(b sb.SQLBuilder, errMsg string) { diff --git a/sqlgen/common_sql_generator_test.go b/sqlgen/common_sql_generator_test.go index a05895ba..0c5dd0e9 100644 --- a/sqlgen/common_sql_generator_test.go +++ b/sqlgen/common_sql_generator_test.go @@ -37,7 +37,6 @@ func (csgs *commonSQLGeneratorSuite) assertCases(testCases ...commonSQLTestCase) } func (csgs *commonSQLGeneratorSuite) TestReturningSQL() { - returningGen := func(csgs *commonSQLGenerator) func(sb.SQLBuilder) { return func(sb sb.SQLBuilder) { csgs.ReturningSQL(sb, exp.NewColumnListExpression("a", "b")) @@ -126,7 +125,6 @@ func (csgs *commonSQLGeneratorSuite) TestFromSQL() { } func (csgs *commonSQLGeneratorSuite) TestWhereSQL() { - whereAndGen := func(csgs *commonSQLGenerator, exps ...exp.Expression) func(sb.SQLBuilder) { return func(sb sb.SQLBuilder) { csgs.WhereSQL(sb, exp.NewExpressionList(exp.AndType, exps...)) @@ -198,7 +196,6 @@ func (csgs *commonSQLGeneratorSuite) TestWhereSQL() { } func (csgs *commonSQLGeneratorSuite) TestOrderSQL() { - orderGen := func(csgs *commonSQLGenerator, o ...exp.OrderedExpression) func(sb.SQLBuilder) { return func(sb sb.SQLBuilder) { csgs.OrderSQL(sb, exp.NewOrderedColumnList(o...)) diff --git a/sqlgen/delete_sql_generator_test.go b/sqlgen/delete_sql_generator_test.go index 6582ffca..b2738867 100644 --- a/sqlgen/delete_sql_generator_test.go +++ b/sqlgen/delete_sql_generator_test.go @@ -48,7 +48,6 @@ func (dsgs *deleteSQLGeneratorSuite) TestDialect() { } func (dsgs *deleteSQLGeneratorSuite) TestGenerate() { - dc := exp.NewDeleteClauses(). SetFrom(exp.NewIdentifierExpression("", "test", "")) diff --git a/sqlgen/expression_sql_generator.go b/sqlgen/expression_sql_generator.go index c52cc75c..0fdad8aa 100644 --- a/sqlgen/expression_sql_generator.go +++ b/sqlgen/expression_sql_generator.go @@ -37,8 +37,7 @@ var ( errEmptyIdentifier = errors.New( `a empty identifier was encountered, please specify a "schema", "table" or "column"`, ) - errUnexpectedNamedWindow = errors.New(`unexpected named window function`) - errNoReturnColumnsForAppendableExpression = errors.New(`no return columns found for appendable expression`) + errUnexpectedNamedWindow = errors.New(`unexpected named window function`) ) func errUnsupportedExpressionType(e exp.Expression) error { @@ -144,6 +143,7 @@ func (esg *expressionSQLGenerator) reflectSQL(b sb.SQLBuilder, val interface{}) } } +// nolint:gocyclo // not complex just long func (esg *expressionSQLGenerator) expressionSQL(b sb.SQLBuilder, expression exp.Expression) { switch e := expression.(type) { case exp.ColumnListExpression: @@ -630,7 +630,6 @@ func (esg *expressionSQLGenerator) compoundExpressionSQL(b sb.SQLBuilder, compou } else { compound.RHS().AppendSQL(b) } - } func (esg *expressionSQLGenerator) expressionMapSQL(b sb.SQLBuilder, ex exp.Ex) { diff --git a/sqlgen/expression_sql_generator_test.go b/sqlgen/expression_sql_generator_test.go index e8db8b15..6e42ba51 100644 --- a/sqlgen/expression_sql_generator_test.go +++ b/sqlgen/expression_sql_generator_test.go @@ -380,7 +380,6 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_ColumnList() { } func (esgs *expressionSQLGeneratorSuite) TestGenerate_ExpressionList() { - andEl := exp.NewExpressionList( exp.AndType, exp.NewIdentifierExpression("", "", "a").Eq("b"), @@ -667,7 +666,6 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_RangeExpression() { } func (esgs *expressionSQLGeneratorSuite) TestGenerate_OrderedExpression() { - asc := exp.NewIdentifierExpression("", "", "a").Asc() ascNf := exp.NewIdentifierExpression("", "", "a").Asc().NullsFirst() ascNl := exp.NewIdentifierExpression("", "", "a").Asc().NullsLast() @@ -708,7 +706,6 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_UpdateExpression() { } func (esgs *expressionSQLGeneratorSuite) TestGenerate_SQLFunctionExpression() { - min := exp.NewSQLFunctionExpression("MIN", exp.NewIdentifierExpression("", "", "a")) coalesce := exp.NewSQLFunctionExpression("COALESCE", exp.NewIdentifierExpression("", "", "a"), "a") esgs.assertCases( diff --git a/sqlgen/insert_sql_generator.go b/sqlgen/insert_sql_generator.go index ec919c5e..26664fba 100644 --- a/sqlgen/insert_sql_generator.go +++ b/sqlgen/insert_sql_generator.go @@ -72,7 +72,6 @@ func (isg *insertSQLGenerator) Generate( b.SetError(errNotSupportedFragment("INSERT", f)) } } - } // Adds the correct fragment to being an INSERT statement @@ -104,9 +103,7 @@ func (isg *insertSQLGenerator) InsertSQL(b sb.SQLBuilder, ic exp.InsertClauses) isg.insertFromSQL(b, ic.From()) default: isg.defaultValuesSQL(b) - } - isg.onConflictSQL(b, ic.OnConflict()) } diff --git a/sqlgen/insert_sql_generator_test.go b/sqlgen/insert_sql_generator_test.go index bc912a9a..9a99f632 100644 --- a/sqlgen/insert_sql_generator_test.go +++ b/sqlgen/insert_sql_generator_test.go @@ -364,7 +364,6 @@ func (igs *insertSQLGeneratorSuite) TestGenerate_onConflict() { insertTestCase{clause: icDuw, err: expectedErr}, insertTestCase{clause: icDuw, err: expectedErr, isPrepared: true}, ) - } func (igs *insertSQLGeneratorSuite) TestGenerate_withCommonTables() { @@ -429,7 +428,6 @@ func (igs *insertSQLGeneratorSuite) TestGenerate_withCommonTables() { insertTestCase{clause: icCte2, err: expectedErr}, insertTestCase{clause: icCte2, err: expectedErr, isPrepared: true}, ) - } func (igs *insertSQLGeneratorSuite) TestGenerate_withReturning() { diff --git a/sqlgen/select_sql_generator_test.go b/sqlgen/select_sql_generator_test.go index 6e0c73ca..a33e810b 100644 --- a/sqlgen/select_sql_generator_test.go +++ b/sqlgen/select_sql_generator_test.go @@ -240,7 +240,6 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withJoin() { selectTestCase{clause: sc.JoinsAppend(badJoin), err: expectedJoinCondError}, selectTestCase{clause: sc.JoinsAppend(badJoin), err: expectedJoinCondError, isPrepared: true}, ) - } func (ssgs *selectSQLGeneratorSuite) TestGenerate_withWhere() { @@ -470,7 +469,6 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withOffset() { } func (ssgs *selectSQLGeneratorSuite) TestGenerate_withCommonTables() { - tse := newTestAppendableExpression("select * from foo", emptyArgs, nil, nil) sc := exp.NewSelectClauses().SetFrom(exp.NewColumnListExpression("test_cte")) @@ -485,7 +483,6 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withCommonTables() { selectTestCase{clause: scCte2, sql: `WITH RECURSIVE test_cte AS (select * from foo) SELECT * FROM "test_cte"`}, selectTestCase{clause: scCte2, sql: `WITH RECURSIVE test_cte AS (select * from foo) SELECT * FROM "test_cte"`, isPrepared: true}, ) - } func (ssgs *selectSQLGeneratorSuite) TestGenerate_withCompounds() { diff --git a/sqlgen/sql_dialect_options.go b/sqlgen/sql_dialect_options.go index 2850fa6f..c571a8ca 100644 --- a/sqlgen/sql_dialect_options.go +++ b/sqlgen/sql_dialect_options.go @@ -122,7 +122,7 @@ type ( SkipLockedFragment []byte // The SQL AS fragment when aliasing an Expression(DEFAULT=[]byte(" AS ")) AsFragment []byte - /// The SQL LATERAL fragment used for LATERAL joins + // The SQL LATERAL fragment used for LATERAL joins LateralFragment []byte // The quote rune to use when quoting identifiers(DEFAULT='"') QuoteRune rune @@ -326,7 +326,7 @@ const ( WindowSQLFragment ) -// nolint:gocyclo +// nolint:gocyclo // simple type to string conversion func (sf SQLFragmentType) String() string { switch sf { case CommonTableSQLFragment: diff --git a/sqlgen/update_sql_generator.go b/sqlgen/update_sql_generator.go index e7f7b254..b41d8e53 100644 --- a/sqlgen/update_sql_generator.go +++ b/sqlgen/update_sql_generator.go @@ -93,7 +93,6 @@ func (usg *updateSQLGenerator) UpdateBeginSQL(b sb.SQLBuilder) { func (usg *updateSQLGenerator) UpdateExpressionsSQL(b sb.SQLBuilder, updates ...exp.UpdateExpression) { b.Write(usg.dialectOptions.SetFragment) usg.UpdateExpressionSQL(b, updates...) - } func (usg *updateSQLGenerator) updateTableSQL(b sb.SQLBuilder, uc exp.UpdateClauses) { diff --git a/sqlgen/update_sql_generator_test.go b/sqlgen/update_sql_generator_test.go index 5b6527dd..7d62f666 100644 --- a/sqlgen/update_sql_generator_test.go +++ b/sqlgen/update_sql_generator_test.go @@ -68,7 +68,6 @@ func (usgs *updateSQLGeneratorSuite) TestGenerate_empty() { updateTestCase{clause: uc, err: errNoSourceForUpdate.Error()}, updateTestCase{clause: uc, err: errNoSourceForUpdate.Error(), isPrepared: true}, ) - } func (usgs *updateSQLGeneratorSuite) TestGenerate_withBadUpdateValues() { @@ -138,7 +137,6 @@ func (usgs *updateSQLGeneratorSuite) TestGenerate_withFrom() { } func (usgs *updateSQLGeneratorSuite) TestGenerate_withUpdateExpression() { - opts := DefaultDialectOptions() // make sure the fragments are used opts.SetFragment = []byte(" set ") diff --git a/truncate_dataset_test.go b/truncate_dataset_test.go index ad2ebc24..e2963442 100644 --- a/truncate_dataset_test.go +++ b/truncate_dataset_test.go @@ -278,7 +278,6 @@ func (tds *truncateDatasetSuite) TestExecutor() { } func (tds *truncateDatasetSuite) TestSetError() { - err1 := errors.New("error #1") err2 := errors.New("error #2") err3 := errors.New("error #3") diff --git a/update_dataset_example_test.go b/update_dataset_example_test.go index 27628e9a..725492cd 100644 --- a/update_dataset_example_test.go +++ b/update_dataset_example_test.go @@ -1,4 +1,4 @@ -// nolint:lll +// nolint:lll // sql statements are long package goqu_test import ( diff --git a/update_dataset_test.go b/update_dataset_test.go index 3f111b1d..518307b1 100644 --- a/update_dataset_test.go +++ b/update_dataset_test.go @@ -450,7 +450,6 @@ func (uds *updateDatasetSuite) TestExecutor() { } func (uds *updateDatasetSuite) TestSetError() { - err1 := errors.New("error #1") err2 := errors.New("error #2") err3 := errors.New("error #3")