Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbintf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

type DB interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
Conn(ctx context.Context) (*sql.Conn, error)
BeginTx(ctx context.Context, txOptions *sql.TxOptions) (*sql.Tx, error)
}
Expand Down
9 changes: 2 additions & 7 deletions sqlparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io/fs"
"regexp"
"slices"
"sort"
"strings"
)
Expand Down Expand Up @@ -637,13 +638,7 @@ func ParseFilesystems(fslst []fs.FS, includeTags []string) (filenames []string,

func matchesIncludeTags(required []string, got []string) bool {
for _, r := range required {
found := false
for _, g := range got {
if g == r {
found = true
break
}
}
found := slices.Contains(got, r)
if !found {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions sqltest/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
type StdoutLogger struct {
}

func (s StdoutLogger) Printf(format string, v ...interface{}) {
func (s StdoutLogger) Printf(format string, v ...any) {
fmt.Printf(format, v...)
}

func (s StdoutLogger) Println(v ...interface{}) {
func (s StdoutLogger) Println(v ...any) {
fmt.Println(v...)
}

Expand Down Expand Up @@ -102,8 +102,8 @@ func (f *Fixture) RunMigrations() {
if err != nil {
panic(err)
}
parts := strings.Split(string(migrationSql), "\ngo\n")
for _, p := range parts {
parts := strings.SplitSeq(string(migrationSql), "\ngo\n")
for p := range parts {
_, err = f.DB.Exec(p)
if err != nil {
fmt.Println(p)
Expand All @@ -117,8 +117,8 @@ func (f *Fixture) RunMigrationFile(filename string) {
if err != nil {
panic(err)
}
parts := strings.Split(string(migrationSql), "\ngo\n")
for _, p := range parts {
parts := strings.SplitSeq(string(migrationSql), "\ngo\n")
for p := range parts {
_, err = f.DB.Exec(p)
if err != nil {
fmt.Println(p)
Expand Down
6 changes: 3 additions & 3 deletions sqltest/intf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

type CtxExecer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

type CtxQuerier interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
30 changes: 15 additions & 15 deletions sqltest/querydump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"github.com/alecthomas/repr"
)

type MapRow map[string]interface{}
type MapRow map[string]any
type MapRows []MapRow

type Row []interface{}
type Row []any
type Rows []Row

func runQuery(dbi interface{}, qry string, args ...interface{}) *sql.Rows {
func runQuery(dbi any, qry string, args ...any) *sql.Rows {

switch q := dbi.(type) {
case CtxQuerier:
rows, err := q.QueryContext(context.Background(), qry, args...)
if err != nil {
panic(fmt.Sprintf("runQuery, query: %s \n\n arguments:%+v \n\n error: %s", qry, args, err))
panic(fmt.Sprintf("runQuery, query: %s \n\n arguments:%+v \n\n error: %s", qry, args, err))
}
return rows
default:
Expand All @@ -44,15 +44,15 @@ func RowIteratorToSlice(rows *sql.Rows) (columns []string, result Rows) {
panic(fmt.Sprintf("RowIteratorToSlice: while getting columns types: %s", err))
}
n := len(columns)
rowValues := make([]interface{}, n, n)
pointers := make([]interface{}, n, n)
for i := 0; i < len(columns); i++ {
rowValues := make([]any, n, n)
pointers := make([]any, n, n)
for i := range columns {
pointers[i] = &rowValues[i]
}
for rows.Next() {
err = rows.Scan(pointers...)
if err != nil {
panic(fmt.Sprintf("RowIteratorToSlice: while scanning: %s", err))
panic(fmt.Sprintf("RowIteratorToSlice: while scanning: %s", err))
}

var row Row
Expand Down Expand Up @@ -96,7 +96,7 @@ func DumpRows(rows *sql.Rows) {
if len(parsedRows) > 0 {
for _, row := range parsedRows {
for i, value := range row {
var val interface{}
var val any
switch v := value.(type) {
case string:
val = repr.String(v)
Expand All @@ -113,11 +113,11 @@ func DumpRows(rows *sql.Rows) {
}

// Returns the result of a query as a loosely typed structure, for use with test code
func QueryMaps(dbi CtxQuerier, qry string, args ...interface{}) MapRows {
func QueryMaps(dbi CtxQuerier, qry string, args ...any) MapRows {
return RowsMap(RowIteratorToSlice(runQuery(dbi, qry, args...)))
}

func Query(dbi CtxQuerier, qry string, args ...interface{}) Rows {
func Query(dbi CtxQuerier, qry string, args ...any) Rows {
_, rows := RowIteratorToSlice(runQuery(dbi, qry, args...))
// do not use nil but a zero-length slice (for backwards compatability as of this writing, wasn't a conscious decision
// at the time it was done)
Expand All @@ -127,29 +127,29 @@ func Query(dbi CtxQuerier, qry string, args ...interface{}) Rows {
return rows
}

func QueryInt(dbi CtxQuerier, qry string, args ...interface{}) (result int) {
func QueryInt(dbi CtxQuerier, qry string, args ...any) (result int) {
if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil {
panic(fmt.Sprintf("QueryInt, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err))
}
return
}

func QueryString(dbi CtxQuerier, qry string, args ...interface{}) (result string) {
func QueryString(dbi CtxQuerier, qry string, args ...any) (result string) {
if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil {
panic(fmt.Sprintf("QueryString, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err))
}
return
}

func QueryTime(dbi CtxQuerier, qry string, args ...interface{}) (result time.Time) {
func QueryTime(dbi CtxQuerier, qry string, args ...any) (result time.Time) {
if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil {
panic(fmt.Sprintf("QueryTime, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err))
}
return
}

// Dump result of query to output
func QueryDump(dbi interface{}, qry string, args ...interface{}) {
func QueryDump(dbi any, qry string, args ...any) {
fmt.Println("============================")
fmt.Println(qry)
fmt.Println("============================")
Expand Down