Skip to content

Commit

Permalink
use *new(T) instead of var zero T
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Jan 22, 2024
1 parent a80b579 commit 56db59a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions db/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func QueryRows(ctx context.Context, query string, args ...any) sqldb.RowsScanner
func QueryValue[T any](ctx context.Context, query string, args ...any) (value T, err error) {
err = Conn(ctx).QueryRow(query, args...).Scan(&value)
if err != nil {
var zero T
return zero, err
return *new(T), err
}
return value, nil
}
Expand All @@ -53,8 +52,7 @@ func QueryValueOr[T any](ctx context.Context, defaultValue T, query string, args
if errors.Is(err, sql.ErrNoRows) {
return defaultValue, nil
}
var zero T
return zero, err
return *new(T), err
}
return value, err
}
Expand Down

0 comments on commit 56db59a

Please sign in to comment.