Files
byre/internal/store/query.go
T

31 lines
605 B
Go
Raw Normal View History

package store
import (
"context"
"database/sql"
)
type querier interface {
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
func queryIDs(ctx context.Context, q querier, query string, args ...any) ([]string, error) {
rows, err := q.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
ids := []string{}
for rows.Next() {
id := ""
err = rows.Scan(&id)
if err != nil {
return nil, err
}
ids = append(ids, id)
}
return ids, rows.Err()
}