package core import ( "database/sql" "fmt" ) func VotesList(db *sql.DB, poll_id int) ([]Vote, error) { votes := []Vote{} rows, err := db.Query("SELECT poll_id,member_id,value FROM polls WHERE poll_id=?", poll_id) if err != nil { return votes, fmt.Errorf("Unable to get votes for poll %d: %w", poll_id, err) } defer rows.Close() for rows.Next() { v := Vote{} err = rows.Scan(&v.PollId, &v.MemberId, &v.Value) if err != nil { return votes, fmt.Errorf("Unable to scan vote for poll %d: %w", poll_id, err) } } return votes, nil }