Skip to content

Commit

Permalink
Replace interface{} with any
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 29, 2023
1 parent f9b49bb commit e01ca03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions dbutil/connlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func addErrorLine(query string, err error) error {
return err
}

func (le *LoggingExecable) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (le *LoggingExecable) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
start := time.Now()
query = le.db.mutateQuery(query)
res, err := le.UnderlyingExecable.ExecContext(ctx, query, args...)
Expand All @@ -72,7 +72,7 @@ func (le *LoggingExecable) ExecContext(ctx context.Context, query string, args .
return res, err
}

func (le *LoggingExecable) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) {
func (le *LoggingExecable) QueryContext(ctx context.Context, query string, args ...any) (Rows, error) {
start := time.Now()
query = le.db.mutateQuery(query)
rows, err := le.UnderlyingExecable.QueryContext(ctx, query, args...)
Expand All @@ -88,23 +88,23 @@ func (le *LoggingExecable) QueryContext(ctx context.Context, query string, args
}, err
}

func (le *LoggingExecable) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
func (le *LoggingExecable) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row {
start := time.Now()
query = le.db.mutateQuery(query)
row := le.UnderlyingExecable.QueryRowContext(ctx, query, args...)
le.db.Log.QueryTiming(ctx, "QueryRow", query, args, -1, time.Since(start), nil)
return row
}

func (le *LoggingExecable) Exec(query string, args ...interface{}) (sql.Result, error) {
func (le *LoggingExecable) Exec(query string, args ...any) (sql.Result, error) {
return le.ExecContext(context.Background(), query, args...)
}

func (le *LoggingExecable) Query(query string, args ...interface{}) (Rows, error) {
func (le *LoggingExecable) Query(query string, args ...any) (Rows, error) {
return le.QueryContext(context.Background(), query, args...)
}

func (le *LoggingExecable) QueryRow(query string, args ...interface{}) *sql.Row {
func (le *LoggingExecable) QueryRow(query string, args ...any) *sql.Row {
return le.QueryRowContext(context.Background(), query, args...)
}

Expand Down Expand Up @@ -175,7 +175,7 @@ type LoggingRows struct {
ctx context.Context
db *Database
query string
args []interface{}
args []any
rs Rows
start time.Time
nrows int
Expand Down
26 changes: 13 additions & 13 deletions dbutil/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Rows interface {
}

type Scannable interface {
Scan(...interface{}) error
Scan(...any) error
}

// Expected implementations of Scannable
Expand All @@ -68,29 +68,29 @@ var (
)

type UnderlyingContextExecable 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
}

type ContextExecable interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (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) (Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type UnderlyingExecable interface {
UnderlyingContextExecable
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
Exec(query string, args ...any) (sql.Result, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryRow(query string, args ...any) *sql.Row
}

type Execable interface {
ContextExecable
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
Exec(query string, args ...any) (sql.Result, error)
Query(query string, args ...any) (Rows, error)
QueryRow(query string, args ...any) *sql.Row
}

type Transaction interface {
Expand Down
12 changes: 6 additions & 6 deletions dbutil/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
)

type DatabaseLogger interface {
QueryTiming(ctx context.Context, method, query string, args []interface{}, nrows int, duration time.Duration, err error)
QueryTiming(ctx context.Context, method, query string, args []any, nrows int, duration time.Duration, err error)
WarnUnsupportedVersion(current, compat, latest int)
PrepareUpgrade(current, compat, latest int)
DoUpgrade(from, to int, message string, txn bool)
// Deprecated: legacy warning method, return errors instead
Warn(msg string, args ...interface{})
Warn(msg string, args ...any)
}

type noopLogger struct{}
Expand All @@ -25,9 +25,9 @@ var NoopLogger DatabaseLogger = &noopLogger{}
func (n noopLogger) WarnUnsupportedVersion(_, _, _ int) {}
func (n noopLogger) PrepareUpgrade(_, _, _ int) {}
func (n noopLogger) DoUpgrade(_, _ int, _ string, _ bool) {}
func (n noopLogger) Warn(msg string, args ...interface{}) {}
func (n noopLogger) Warn(msg string, args ...any) {}

func (n noopLogger) QueryTiming(_ context.Context, _, _ string, _ []interface{}, _ int, _ time.Duration, _ error) {
func (n noopLogger) QueryTiming(_ context.Context, _, _ string, _ []any, _ int, _ time.Duration, _ error) {
}

type zeroLogger struct {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (z zeroLogger) DoUpgrade(from, to int, message string, txn bool) {

var whitespaceRegex = regexp.MustCompile(`\s+`)

func (z zeroLogger) QueryTiming(ctx context.Context, method, query string, args []interface{}, nrows int, duration time.Duration, err error) {
func (z zeroLogger) QueryTiming(ctx context.Context, method, query string, args []any, nrows int, duration time.Duration, err error) {
log := zerolog.Ctx(ctx)
if log.GetLevel() == zerolog.Disabled || log == zerolog.DefaultContextLogger {
log = z.l
Expand Down Expand Up @@ -124,6 +124,6 @@ func (z zeroLogger) QueryTiming(ctx context.Context, method, query string, args
}
}

func (z zeroLogger) Warn(msg string, args ...interface{}) {
func (z zeroLogger) Warn(msg string, args ...any) {
z.l.Warn().Msgf(msg, args...) // zerolog-allow-msgf
}

0 comments on commit e01ca03

Please sign in to comment.