Skip to content

Commit

Permalink
fix: update utils for parsing db with multiple rows
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Mar 15, 2024
1 parent 5d79fe5 commit 824447b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
4 changes: 0 additions & 4 deletions api/adapter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ func get(c *fiber.Ctx) error {
panic(err)
}

if results == nil {
results = []AdapterModel{}
}

return c.JSON(results)
}

Expand Down
4 changes: 0 additions & 4 deletions api/aggregator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ func get(c *fiber.Ctx) error {
panic(err)
}

if results == nil {
results = []AggregatorResultModel{}
}

return c.JSON(results)
}

Expand Down
4 changes: 2 additions & 2 deletions api/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func QueryRows[T any](c *fiber.Ctx, query string, args map[string]any) ([]T, err
}

results, err = pgx.CollectRows(rows, pgx.RowToStructByName[T])
if errors.Is(err, pgx.ErrNoRows) {
return results, nil
if errors.Is(err, pgx.ErrNoRows) || (results == nil && err == nil) {
return []T{}, nil
}
return results, err
}
Expand Down

0 comments on commit 824447b

Please sign in to comment.