Skip to content

Commit 09d4581

Browse files
committed
shorter db.QueryValueOr
1 parent a52473e commit 09d4581

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

db/query.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ func QueryValue[T any](ctx context.Context, query string, args ...any) (value T,
4747

4848
// QueryValueOr queries a single value of type T
4949
// or returns the passed defaultValue in case of sql.ErrNoRows.
50-
func QueryValueOr[T any](ctx context.Context, defaultValue T, query string, args ...any) (T, error) {
51-
var value T
52-
err := Conn(ctx).QueryRow(query, args...).Scan(&value)
50+
func QueryValueOr[T any](ctx context.Context, defaultValue T, query string, args ...any) (value T, err error) {
51+
err = Conn(ctx).QueryRow(query, args...).Scan(&value)
5352
if err != nil {
5453
if errors.Is(err, sql.ErrNoRows) {
5554
return defaultValue, nil

0 commit comments

Comments
 (0)