Skip to content

Commit 1f55645

Browse files
committed
Fix more lint issues
1 parent 0172b11 commit 1f55645

16 files changed

+128
-89
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ linters:
55
disable-all: true
66
enable:
77
- govet
8+
- golint
89
- errcheck
910
- staticcheck
1011
- unused

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<h2 align="center">sqlz</h2>
2-
<p align="center">sqlz is an SQL query builder for Go.</p>
2+
<p align="center">flexible SQL query builder for Go.</p>
33
<p align="center">
44
<a href="https://godoc.org/github.com/ido50/sqlz"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"></a>
55
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a>
66
<a href="https://goreportcard.com/report/ido50/sqlz"><img src="https://goreportcard.com/badge/github.com/ido50/sqlz"></a>
7+
<a href="https://github.com/ido50/sqlz/actions"><img src="https://github.com/ido50/sqlz/workflows/build/badge.svg"></a>
78
</p>
89

910
---

delete.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (stmt *DeleteStmt) Exec() (res sql.Result, err error) {
9999
asSQL, bindings := stmt.ToSQL(true)
100100

101101
res, err = stmt.execer.Exec(asSQL, bindings...)
102-
stmt.HandlerError(err)
102+
stmt.HandleError(err)
103103

104104
return res, err
105105
}
@@ -113,7 +113,7 @@ func (stmt *DeleteStmt) ExecContext(ctx context.Context) (
113113
asSQL, bindings := stmt.ToSQL(true)
114114

115115
res, err = stmt.execer.ExecContext(ctx, asSQL, bindings...)
116-
stmt.HandlerError(err)
116+
stmt.HandleError(err)
117117

118118
return res, err
119119
}
@@ -127,7 +127,7 @@ func (stmt *DeleteStmt) GetRow(into interface{}) error {
127127
asSQL, bindings := stmt.ToSQL(true)
128128

129129
err := sqlx.Get(stmt.execer, into, asSQL, bindings...)
130-
stmt.HandlerError(err)
130+
stmt.HandleError(err)
131131

132132
return err
133133
}
@@ -144,7 +144,7 @@ func (stmt *DeleteStmt) GetRowContext(
144144
asSQL, bindings := stmt.ToSQL(true)
145145

146146
err := sqlx.GetContext(ctx, stmt.execer, into, asSQL, bindings...)
147-
stmt.HandlerError(err)
147+
stmt.HandleError(err)
148148

149149
return err
150150
}
@@ -156,7 +156,7 @@ func (stmt *DeleteStmt) GetAll(into interface{}) error {
156156
asSQL, bindings := stmt.ToSQL(true)
157157

158158
err := sqlx.Select(stmt.execer, into, asSQL, bindings...)
159-
stmt.HandlerError(err)
159+
stmt.HandleError(err)
160160

161161
return err
162162
}
@@ -168,7 +168,7 @@ func (stmt *DeleteStmt) GetAllContext(ctx context.Context, into interface{}) err
168168
asSQL, bindings := stmt.ToSQL(true)
169169

170170
err := sqlx.SelectContext(ctx, stmt.execer, into, asSQL, bindings...)
171-
stmt.HandlerError(err)
171+
stmt.HandleError(err)
172172

173173
return err
174174
}

delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ import (
77
func TestDelete(t *testing.T) {
88
runTests(t, func(dbz *DB) []test {
99
return []test{
10-
test{
10+
{
1111
"delete all table",
1212
dbz.DeleteFrom("table"),
1313
"DELETE FROM table",
1414
[]interface{}{},
1515
},
1616

17-
test{
17+
{
1818
"delete all rows matching condition",
1919
dbz.DeleteFrom("table").Where(Or(Eq("id", 1), And(Eq("name", "some-name"), Gt("integer", 3)))),
2020
"DELETE FROM table WHERE id = ? OR (name = ? AND integer > ?)",
2121
[]interface{}{1, "some-name", 3},
2222
},
2323

24-
test{
24+
{
2525
"delete with returning clause",
2626
dbz.DeleteFrom("table").Where(Eq("id", 2)).Returning("name"),
2727
"DELETE FROM table WHERE id = ? RETURNING name",
2828
[]interface{}{2},
2929
},
3030

31-
test{
31+
{
3232
"delete using join",
3333
dbz.DeleteFrom("table").Using("other", "another").Where(Eq("other.fk_id", Indirect("table.id")), Eq("another.fk_id", Indirect("table.id"))),
3434
"DELETE FROM table USING other, another WHERE other.fk_id = table.id AND another.fk_id = table.id",

insert.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ func (stmt *InsertStmt) ValueMultiple(vals [][]interface{}) *InsertStmt {
7474
return stmt
7575
}
7676

77-
// Select sets a SELECT statements that will supply the rows
78-
// to be inserted.
77+
// FromSelect sets a SELECT statements that will supply the rows to be inserted.
7978
func (stmt *InsertStmt) FromSelect(selStmt *SelectStmt) *InsertStmt {
8079
stmt.SelectStmt = selStmt
8180
return stmt
@@ -195,7 +194,7 @@ func (stmt *InsertStmt) ToSQL(rebind bool) (asSQL string, bindings []interface{}
195194
func (stmt *InsertStmt) Exec() (res sql.Result, err error) {
196195
asSQL, bindings := stmt.ToSQL(true)
197196
res, err = stmt.execer.Exec(asSQL, bindings...)
198-
stmt.Statement.HandlerError(err)
197+
stmt.Statement.HandleError(err)
199198

200199
return res, err
201200
}
@@ -206,7 +205,7 @@ func (stmt *InsertStmt) ExecContext(ctx context.Context) (res sql.Result, err er
206205
asSQL, bindings := stmt.ToSQL(true)
207206

208207
res, err = stmt.execer.ExecContext(ctx, asSQL, bindings...)
209-
stmt.Statement.HandlerError(err)
208+
stmt.Statement.HandleError(err)
210209

211210
return res, err
212211
}
@@ -253,8 +252,11 @@ func (stmt *InsertStmt) GetAllContext(ctx context.Context, into interface{}) err
253252
type ConflictAction string
254253

255254
const (
255+
// DoNothing represents a "DO NOTHING" conflict action
256256
DoNothing ConflictAction = "nothing"
257-
DoUpdate ConflictAction = "update"
257+
258+
// DoUpdate represents a "DO UPDATE" conflict action
259+
DoUpdate ConflictAction = "update"
258260
)
259261

260262
// ConflictClause represents an ON CONFLICT clause in an INSERT statement

insert_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ import "testing"
55
func TestInsert(t *testing.T) {
66
runTests(t, func(dbz *DB) []test {
77
return []test{
8-
test{
8+
{
99
"simple insert",
1010
dbz.InsertInto("table").Columns("id", "name", "date").Values(1, "My Name", 96969696),
1111
"INSERT INTO table (id, name, date) VALUES (?, ?, ?)",
1212
[]interface{}{1, "My Name", 96969696},
1313
},
1414

15-
test{
15+
{
1616
"insert with value map",
1717
dbz.InsertInto("table").ValueMap(map[string]interface{}{"id": 1, "name": "My Name"}),
1818
"INSERT INTO table (id, name) VALUES (?, ?)",
1919
[]interface{}{1, "My Name"},
2020
},
2121

22-
test{
22+
{
2323
"insert with returning clause",
2424
dbz.InsertInto("table").Columns("one", "two").Values(1, 2).Returning("id"),
2525
"INSERT INTO table (one, two) VALUES (?, ?) RETURNING id",
2626
[]interface{}{1, 2},
2727
},
2828

29-
test{
29+
{
3030
"insert with on conflict do nothing clause",
3131
dbz.InsertInto("table").Columns("one", "two").Values(1, 2).OnConflictDoNothing(),
3232
"INSERT INTO table (one, two) VALUES (?, ?) ON CONFLICT DO NOTHING",
3333
[]interface{}{1, 2},
3434
},
3535

36-
test{
36+
{
3737
"insert rows from a select query",
3838
dbz.InsertInto("table").Columns("one", "two").FromSelect(
3939
dbz.Select("*").From("table2"),
@@ -42,7 +42,7 @@ func TestInsert(t *testing.T) {
4242
[]interface{}{},
4343
},
4444

45-
test{
45+
{
4646
"insert with on conflict do update",
4747
dbz.InsertInto("table").Columns("name").Values("My Name").
4848
OnConflict(
@@ -57,7 +57,7 @@ func TestInsert(t *testing.T) {
5757
[]interface{}{"My Name", 55151515, "Some Address", "My Name Again"},
5858
},
5959

60-
test{
60+
{
6161
"insert with on conflict do update conditional set",
6262
dbz.InsertInto("table").Columns("name").Values("My Name").
6363
OnConflict(
@@ -71,20 +71,20 @@ func TestInsert(t *testing.T) {
7171
[]interface{}{"My Name", 55151515, 1},
7272
},
7373

74-
test{
74+
{
7575
"insert or ignore",
7676
dbz.InsertInto("table").OrIgnore().Columns("id", "name", "date").Values(1, "My Name", 96969696),
7777
"INSERT OR IGNORE INTO table (id, name, date) VALUES (?, ?, ?)",
7878
[]interface{}{1, "My Name", 96969696},
7979
},
80-
test{
80+
{
8181
"insert or replace",
8282
dbz.InsertInto("table").OrReplace().Columns("id", "name", "date").Values(1, "My Name", 96969696),
8383
"INSERT OR REPLACE INTO table (id, name, date) VALUES (?, ?, ?)",
8484
[]interface{}{1, "My Name", 96969696},
8585
},
8686

87-
test{
87+
{
8888
"insert with multiple values",
8989
dbz.InsertInto("table").Columns("id", "name").
9090
ValueMultiple([][]interface{}{{1, "My Name"}, {2, "John"}, {3, "Golang"}}),

jsonb.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ import (
44
"strings"
55
)
66

7+
// JSONBObject represents a PostgreSQL JSONB object.
78
type JSONBObject struct {
9+
// Bindings is the list of bindings for the object.
810
Bindings []interface{}
911
}
1012

13+
// JSONBBuilder represents usage of PostgreSQL's jsonb_build_array or
14+
// jsonb_build_object functions.
1115
type JSONBBuilder struct {
12-
Array bool
16+
// Array indicates whether an array is being built, or an object
17+
Array bool
18+
// Bindings is the list of bindings for the function call
1319
Bindings []interface{}
1420
}
1521

22+
// BuildJSONBObject creates a call to jsonb_build_object.
1623
func BuildJSONBObject(in map[string]interface{}) (out JSONBBuilder) {
1724
for _, key := range sortKeys(in) {
1825
val := in[key]
@@ -22,13 +29,16 @@ func BuildJSONBObject(in map[string]interface{}) (out JSONBBuilder) {
2229
return out
2330
}
2431

32+
// BuildJSONBArray creates a call to jsonb_build_array.
2533
func BuildJSONBArray(in ...interface{}) (out JSONBBuilder) {
2634
out.Array = true
2735
out.Bindings = append(out.Bindings, in...)
2836

2937
return out
3038
}
3139

40+
// Parse processes the JSONB object creator, returning SQL code that calls
41+
// the appropriate function.
3242
func (b JSONBBuilder) Parse() (asSQL string, bindings []interface{}) {
3343
asSQL = "jsonb_build_"
3444
if b.Array {

jsonb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "testing"
55
func TestJSONBBuilder(t *testing.T) {
66
runTests(t, func(dbz *DB) []test {
77
return []test{
8-
test{
8+
{
99
"create a complex JSONB object",
1010
dbz.
1111
InsertInto("table").

0 commit comments

Comments
 (0)