Skip to content
Open
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
4 changes: 4 additions & 0 deletions code/sonalyze/db/timescaledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type databaseConnection struct {
lock sync.Mutex
}

// NOTE! That the Rows object must be closed after use.
func (cdb *databaseConnection) Query(cx context.Context, q string, arg ...any) (pgx.Rows, error) {
cdb.lock.Lock()
defer cdb.lock.Unlock()
Expand All @@ -116,6 +117,7 @@ func (cdb *databaseConnection) Query(cx context.Context, q string, arg ...any) (
func (cdb *databaseConnection) QueryRowAndScan(cx context.Context, q string, args []any, slots []any) error {
cdb.lock.Lock()
defer cdb.lock.Unlock()
// The single row does not need to be closed explicitly.
return cdb.connection.QueryRow(cx, q, args...).Scan(slots...)
}

Expand All @@ -135,6 +137,7 @@ func (cdb *databaseConnection) EnumerateClusters() ([]string, error) {
if err != nil {
return nil, err
}
defer rows.Close()
rawClusters, err := pgx.CollectRows(rows, pgx.RowTo[string])
if err != nil {
return nil, err
Expand Down Expand Up @@ -1094,6 +1097,7 @@ func querySlice[T any](
if err != nil {
return
}
defer rows.Close()
dataRows := make([]*T, 0)
_, err = pgx.ForEachRow(rows, q.boxes, func() error {
dataRows = append(dataRows, unbox())
Expand Down
Loading