Skip to content

Commit ca35964

Browse files
committed
Update Lint stage in workflow, fix lint issues
The Lint stage has been failing consistently due to a deprecated version of golangci-lint-action.
1 parent 1114558 commit ca35964

File tree

8 files changed

+101
-89
lines changed

8 files changed

+101
-89
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/setup-go@v2
1818
id: go
1919
with:
20-
go-version: ^1.14
20+
go-version: ^1.15
2121

2222
- name: Check out code into the Go module directory
2323
uses: actions/checkout@v2
@@ -32,6 +32,7 @@ jobs:
3232
run: go test -v .
3333

3434
- name: Lint
35-
uses: golangci/golangci-lint-action@v1.2.1
35+
uses: golangci/golangci-lint-action@v3
3636
with:
37-
version: v1.28
37+
version: latest
38+
only-new-issues: true

.golangci.yml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,43 @@ run:
44
linters:
55
disable-all: true
66
enable:
7-
- govet
8-
- golint
9-
- errcheck
10-
- staticcheck
11-
- unused
12-
- gosimple
13-
- structcheck
14-
- varcheck
15-
- ineffassign
16-
- deadcode
17-
- typecheck
18-
- rowserrcheck
19-
- stylecheck
20-
- interfacer
21-
- unconvert
7+
- asciicheck
228
- dupl
9+
- errorlint
10+
- errcheck
11+
- exhaustive
12+
- exportloopref
13+
- funlen
14+
- gocognit
2315
- goconst
16+
- gocritic
2417
- gocyclo
25-
- gocognit
26-
- asciicheck
27-
- goimports
18+
- goerr113
2819
- goheader
29-
- maligned
30-
- misspell
20+
- goimports
21+
- gomnd
22+
- goprintffuncname
23+
- gosec
24+
- gosimple
25+
- govet
26+
- ineffassign
3127
- lll
32-
- unparam
28+
- misspell
3329
- nakedret
30+
- nestif
31+
- nolintlint
3432
- prealloc
35-
- scopelint
36-
- gocritic
37-
- funlen
33+
- rowserrcheck
34+
- sqlclosecheck
35+
- staticcheck
36+
- stylecheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused
41+
- wastedassign
3842
- whitespace
3943
- wsl
40-
- goprintffuncname
41-
- gomnd
42-
- goerr113
43-
- nestif
44-
- exportloopref
45-
- exhaustive
46-
- sqlclosecheck
47-
- nolintlint
4844
linters-settings:
4945
funlen:
5046
lines: 150

doc.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@
2222
// sqlz provides a comfortable API for running queries in a transaction, and
2323
// will automatically commit or rollback the transaction as necessary.
2424
//
25-
// import (
26-
// "fmt"
27-
// "database/sql"
28-
// "github.com/ido50/sqlz"
29-
// _ "sql driver of choice"
30-
// )
31-
//
32-
// func main() {
33-
// db, err := sql.Open(driver, "dsn")
34-
// if err != nil {
35-
// panic(err)
36-
// }
37-
//
38-
// // find one row in the database and load it
39-
// // into a struct variable
40-
// var row someStruct
41-
// err = sqlz.New(db, driver). // if using sqlx: sqlz.Newx(dbx)
42-
// Select("*").
43-
// From("some-table").
44-
// Where(sqlz.Eq("id", 1)).
45-
// GetRow(&row)
46-
// if err != nil {
47-
// panic(err)
48-
// }
49-
//
50-
// fmt.Printf("%+v\n", row)
25+
// import (
26+
// "fmt"
27+
// "database/sql"
28+
// "github.com/ido50/sqlz"
29+
// _ "sql driver of choice"
30+
// )
31+
//
32+
// func main() {
33+
// db, err := sql.Open(driver, "dsn")
34+
// if err != nil {
35+
// panic(err)
5136
// }
37+
//
38+
// // find one row in the database and load it
39+
// // into a struct variable
40+
// var row someStruct
41+
// err = sqlz.New(db, driver). // if using sqlx: sqlz.Newx(dbx)
42+
// Select("*").
43+
// From("some-table").
44+
// Where(sqlz.Eq("id", 1)).
45+
// GetRow(&row)
46+
// if err != nil {
47+
// panic(err)
48+
// }
49+
//
50+
// fmt.Printf("%+v\n", row)
51+
// }
5252
package sqlz

select.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ func ForKeyShare() *LockClause {
377377
// ToSQL generates the SELECT statement's SQL and returns a list of
378378
// bindings. It is used internally by GetRow and GetAll, but is
379379
// exported if you wish to use it directly.
380-
// nolint: gocognit, gocyclo
381-
func (stmt *SelectStmt) ToSQL(rebind bool) (asSQL string, bindings []interface{}) {
380+
func (stmt *SelectStmt) ToSQL(rebind bool) (asSQL string, bindings []interface{}) { //nolint: gocognit, gocyclo
382381
var clauses = []string{"SELECT"}
383382

384383
if stmt.IsDistinct {

select_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func TestSelect(t *testing.T) {
5454
{
5555
"select with array comparisons",
5656
dbz.Select("*").From("table").Where(EqAny("array_col", 3), GtAll("other_array_col", 1), NeAny("yet_another_col", Indirect("NOW()")),
57-
Any(Indirect("column"),[]int{1,2,3})),
57+
Any(Indirect("column"), []int{1, 2, 3})),
5858
"SELECT * FROM table WHERE ? = ANY(array_col) AND ? > ALL(other_array_col) AND NOW() <> ANY(yet_another_col) AND column = ANY(?)",
59-
[]interface{}{3, 1 ,"'{1,2,3}'"},
59+
[]interface{}{3, 1, "'{1,2,3}'"},
6060
},
6161

6262
{

set.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@ func (tx *Tx) SetTimeout(d time.Duration) (res sql.Result, err error) {
5656
}
5757

5858
// Local sets the configuration parameter locally in a transaction.
59-
// The effect of SET LOCAL will last only till the end of the
59+
//
60+
// The effect of SET LOCAL will last only till the end of the
61+
//
6062
// current transaction, whether committed or not.
6163
func (cmd *SetCmd) Local() *SetCmd {
6264
cmd.level = "LOCAL"
6365
return cmd
6466
}
6567

6668
// Session sets the configuration parameter to the entire session.
67-
// The effect of SET SESSION will last only till the end of the
69+
//
70+
// The effect of SET SESSION will last only till the end of the
71+
//
6872
// current session. if issued within a transaction that is later aborted,
6973
// the effects of the SET command disappear when the transaction is rolled
7074
// back. Once the surrounding transaction is committed, the effects will persist

sqlz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (db *DB) TransactionalContext(
9292

9393
err = f(&Tx{Tx: tx, ErrHandlers: db.ErrHandlers})
9494
if err != nil {
95-
tx.Rollback() // nolint: errcheck
95+
tx.Rollback() //nolint: errcheck
9696
return err
9797
}
9898

update.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,14 @@ func (stmt *UpdateStmt) ToSQL(rebind bool) (asSQL string, bindings []interface{}
152152
if stmt.SelectStmt != nil && stmt.SelectStmtAlias != "" {
153153
selectSQL, selectBindings := stmt.SelectStmt.ToSQL(false)
154154
selectSQL = "(" + selectSQL + ") AS " + stmt.SelectStmtAlias + " "
155+
155156
clauses = append(clauses, "FROM ")
156157
clauses = append(clauses, selectSQL)
157158
bindings = append(bindings, selectBindings...)
158159
} else if len(stmt.MultipleValues.Values) > 0 {
159-
// add the FROM
160-
clauses = append(clauses, "FROM")
161-
var multipleValues []string
162-
for _, multipleVals := range stmt.MultipleValues.Values {
163-
placeholders, bindingsToAdd := parseInsertValues(multipleVals)
164-
bindings = append(bindings, bindingsToAdd...)
165-
multipleValues = append(multipleValues, "("+strings.Join(placeholders, ", ")+")")
166-
}
167-
168-
clauses = append(clauses, fmt.Sprintf("(VALUES %s) AS %s(%s)",
169-
strings.Join(multipleValues, ", "),
170-
stmt.MultipleValues.As,
171-
strings.Join(stmt.MultipleValues.Columns, ", "),
172-
))
173-
174-
if len(stmt.MultipleValues.Where) > 0 {
175-
whereClause, whereBindings := parseConditions(stmt.MultipleValues.Where)
176-
bindings = append(bindings, whereBindings...)
177-
clauses = append(clauses, fmt.Sprintf("WHERE %s", whereClause))
178-
}
179-
160+
addClauses, addBindings := stmt.addUpdateFrom()
161+
clauses = append(clauses, addClauses...)
162+
bindings = append(bindings, addBindings...)
180163
}
181164

182165
if len(stmt.Conditions) > 0 {
@@ -202,6 +185,35 @@ func (stmt *UpdateStmt) ToSQL(rebind bool) (asSQL string, bindings []interface{}
202185
return asSQL, bindings
203186
}
204187

188+
func (stmt *UpdateStmt) addUpdateFrom() (
189+
clauses []string,
190+
bindings []interface{},
191+
) {
192+
clauses = append(clauses, "FROM")
193+
194+
multipleValues := make([]string, len(stmt.MultipleValues.Values))
195+
196+
for i, multipleVals := range stmt.MultipleValues.Values {
197+
placeholders, bindingsToAdd := parseInsertValues(multipleVals)
198+
bindings = append(bindings, bindingsToAdd...)
199+
multipleValues[i] = "(" + strings.Join(placeholders, ", ") + ")"
200+
}
201+
202+
clauses = append(clauses, fmt.Sprintf("(VALUES %s) AS %s(%s)",
203+
strings.Join(multipleValues, ", "),
204+
stmt.MultipleValues.As,
205+
strings.Join(stmt.MultipleValues.Columns, ", "),
206+
))
207+
208+
if len(stmt.MultipleValues.Where) > 0 {
209+
whereClause, whereBindings := parseConditions(stmt.MultipleValues.Where)
210+
bindings = append(bindings, whereBindings...)
211+
clauses = append(clauses, fmt.Sprintf("WHERE %s", whereClause))
212+
}
213+
214+
return clauses, bindings
215+
}
216+
205217
// Exec executes the UPDATE statement, returning the standard
206218
// sql.Result struct and an error if the query failed.
207219
func (stmt *UpdateStmt) Exec() (res sql.Result, err error) {

0 commit comments

Comments
 (0)