Skip to content

Commit

Permalink
fix most issues brought up by vet
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Cheong committed Nov 3, 2023
1 parent a8a8e78 commit 9a3e284
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 46 deletions.
10 changes: 5 additions & 5 deletions bind.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlx
package squealx

import (
"bytes"
Expand All @@ -22,10 +22,10 @@ const (
)

var defaultBinds = map[int][]string{
DOLLAR: []string{"postgres", "pgx", "pgx/v4", "pgx/v5", "pq-timeouts", "cloudsqlpostgres", "ql", "nrpostgres", "cockroach"},
QUESTION: []string{"mysql", "sqlite3", "nrmysql", "nrsqlite3"},
NAMED: []string{"oci8", "ora", "goracle", "godror"},
AT: []string{"sqlserver"},
DOLLAR: {"postgres", "pgx", "pgx/v4", "pgx/v5", "pq-timeouts", "cloudsqlpostgres", "ql", "nrpostgres", "cockroach"},
QUESTION: {"mysql", "sqlite3", "nrmysql", "nrsqlite3"},
NAMED: {"oci8", "ora", "goracle", "godror"},
AT: {"sqlserver"},
}

var binds sync.Map
Expand Down
2 changes: 1 addition & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlx
package squealx

import (
"math/rand"
Expand Down
5 changes: 2 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package sqlx provides general purpose extensions to database/sql.
// package squealx provides general purpose extensions to database/sql.
//
// It is intended to seamlessly wrap database/sql and provide convenience
// methods which are useful in the development of database driven applications.
Expand All @@ -8,5 +8,4 @@
// Additions include scanning into structs, named query support, rebinding
// queries for different drivers, convenient shorthands for common error handling
// and more.
//
package sqlx
package squealx
4 changes: 2 additions & 2 deletions named.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlx
package squealx

// Named Query Support
//
Expand Down Expand Up @@ -174,7 +174,7 @@ func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{
arglist := make([]interface{}, 0, len(names))

// grab the indirected value of arg
v := reflect.ValueOf(arg)
var v reflect.Value
for v = reflect.ValueOf(arg); v.Kind() == reflect.Ptr; {
v = v.Elem()
}
Expand Down
3 changes: 2 additions & 1 deletion named_context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build go1.8
// +build go1.8

package sqlx
package squealx

import (
"context"
Expand Down
7 changes: 4 additions & 3 deletions named_context_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build go1.8
// +build go1.8

package sqlx
package squealx

import (
"context"
Expand All @@ -18,12 +19,12 @@ func TestNamedContextQueries(t *testing.T) {
ctx := context.Background()

// Check that invalid preparations fail
ns, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
_, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}

ns, err = db.PrepareNamedContext(ctx, "invalid sql")
_, err = db.PrepareNamedContext(ctx, "invalid sql")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}
Expand Down
30 changes: 15 additions & 15 deletions named_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sqlx
package squealx

import (
"database/sql"
Expand Down Expand Up @@ -139,12 +139,12 @@ func TestNamedQueries(t *testing.T) {
var err error

// Check that invalid preparations fail
ns, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
_, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}

ns, err = db.PrepareNamed("invalid sql")
_, err = db.PrepareNamed("invalid sql")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}
Expand Down Expand Up @@ -435,8 +435,8 @@ func TestFixBounds(t *testing.T) {
loop: 2,
},
{
name: `query with "join" generated table`,
query: `
name: `query with "join" generated table`,
query: `
SELECT
t_1.code_values, t_2.name, t_2.age, t_2.first, t_2.last
FROM public.table_1 t_1
Expand All @@ -456,11 +456,11 @@ func TestFixBounds(t *testing.T) {
ON
t_1.code_values = t_2.code
`,
loop: 2,
loop: 2,
},
{
name: `insert with select generated table`,
query: `
name: `insert with select generated table`,
query: `
INSERT INTO public.table_1 t_1
SELECT * FROM
(VALUES (:v_code, :v_name, 18, :v_first, 'const_value_1')) --- comment
Expand All @@ -472,11 +472,11 @@ func TestFixBounds(t *testing.T) {
(VALUES (:v_code, :v_name, 18, :v_first, 'const_value_1'),(:v_code, :v_name, 18, :v_first, 'const_value_1')) --- comment
t_2 (code, name, age, first, last);
`,
loop: 2,
loop: 2,
},
{
name: `insert with select generated table with new lines`,
query: `
name: `insert with select generated table with new lines`,
query: `
INSERT INTO public.table_1 t_1
SELECT * FROM
(VALUES (
Expand Down Expand Up @@ -506,11 +506,11 @@ func TestFixBounds(t *testing.T) {
)) --- comment
t_2 (code, name, age, first, last);
`,
loop: 2,
loop: 2,
},
{
name: `insert with select generated table with new lines mysql syntax`,
query: `
name: `insert with select generated table with new lines mysql syntax`,
query: `
INSERT INTO public.table_1 t_1
SELECT * FROM
(VALUES (
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestFixBounds(t *testing.T) {
)) --- comment
t_2 (code, name, age, first, last);
`,
loop: 2,
loop: 2,
},
}

Expand Down
6 changes: 3 additions & 3 deletions sqlx.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package sqlx
package squealx

import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"

Expand Down Expand Up @@ -160,7 +159,8 @@ func mapperFor(i interface{}) *reflectx.Mapper {
}

var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()

// var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()

// Row is a reimplementation of sql.Row in order to gain access to the underlying
// sql.Rows.Columns() data, necessary for StructScan.
Expand Down
7 changes: 4 additions & 3 deletions sqlx_context.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//go:build go1.8
// +build go1.8

package sqlx
package squealx

import (
"context"
"database/sql"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
)
Expand Down Expand Up @@ -99,7 +100,7 @@ func LoadFileContext(ctx context.Context, e ExecerContext, path string) (*sql.Re
if err != nil {
return nil, err
}
contents, err := ioutil.ReadFile(realpath)
contents, err := os.ReadFile(realpath)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Set any of these variables to 'skip' to skip them. Note that for MySQL,
// the string '?parseTime=True' will be appended to the DSN if it's not there
// already.
package sqlx
package squealx

import (
"context"
Expand Down Expand Up @@ -1486,10 +1486,10 @@ func TestConn(t *testing.T) {

RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) {
conn, err := db.Connx(ctx)
defer conn.Close()
if err != nil {
t.Fatal(err)
}
defer conn.Close()

_, err = conn.ExecContext(ctx, conn.Rebind(`INSERT INTO tt_conn (id, value) VALUES (?, ?), (?, ?)`), 1, "a", 2, "b")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Set any of these variables to 'skip' to skip them. Note that for MySQL,
// the string '?parseTime=True' will be appended to the DSN if it's not there
// already.
package sqlx
package squealx

import (
"database/sql"
Expand Down Expand Up @@ -40,7 +40,8 @@ var TestMysql = true
var sldb *DB
var pgdb *DB
var mysqldb *DB
var active = []*DB{}

// var active = []*DB{}

func init() {
ConnectAll()
Expand Down
9 changes: 4 additions & 5 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"database/sql/driver"
"encoding/json"
"errors"

"io/ioutil"
"io"
)

// GzippedText is a []byte which transparently gzips data being submitted to
Expand Down Expand Up @@ -36,14 +35,14 @@ func (g *GzippedText) Scan(src interface{}) error {
case []byte:
source = src
default:
return errors.New("Incompatible type for GzippedText")
return errors.New("incompatible type for GzippedText")
}
reader, err := gzip.NewReader(bytes.NewReader(source))
if err != nil {
return err
}
defer reader.Close()
b, err := ioutil.ReadAll(reader)
b, err := io.ReadAll(reader)
if err != nil {
return err
}
Expand Down Expand Up @@ -102,7 +101,7 @@ func (j *JSONText) Scan(src interface{}) error {
case nil:
*j = emptyJSON
default:
return errors.New("Incompatible type for JSONText")
return errors.New("incompatible type for JSONText")
}
*j = append((*j)[0:0], source...)
return nil
Expand Down
2 changes: 1 addition & 1 deletion types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestJSONText(t *testing.T) {
}

j = JSONText(`{"foo": 1, invalid, false}`)
v, err = j.Value()
_, err = j.Value()
if err == nil {
t.Errorf("Was expecting invalid json to fail!")
}
Expand Down

0 comments on commit 9a3e284

Please sign in to comment.