package main import ( "context" "github.com/jackc/pgx/v5/pgxpool" ) type HostRow struct { ID int64 Hostname string Protocol string HtmlTitle string IframeAllowed bool BestIconS3Key string RandomOrder float32 } // fetchHostsPage gets a page of hosts with titles, ordered by random_order for shuffled bundles. func fetchHostsPage(ctx context.Context, pool *pgxpool.Pool, lastRandom float32, limit int) ([]HostRow, error) { rows, err := pool.Query(ctx, ` SELECT id, hostname, protocol, html_title, COALESCE(iframe_allowed, true), COALESCE(best_icon_s3_key, ''), random_order FROM hosts WHERE html_title IS NOT NULL AND random_order > $1 ORDER BY random_order LIMIT $2 `, lastRandom, limit) if err != nil { return nil, err } defer rows.Close() var hosts []HostRow for rows.Next() { var h HostRow if err := rows.Scan(&h.ID, &h.Hostname, &h.Protocol, &h.HtmlTitle, &h.IframeAllowed, &h.BestIconS3Key, &h.RandomOrder); err != nil { return nil, err } hosts = append(hosts, h) } return hosts, rows.Err() }