Completed db rewrite
This commit is contained in:
parent
54d7d14ef9
commit
cf4b8e0119
19 changed files with 481 additions and 276 deletions
23
core/votes.go
Normal file
23
core/votes.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue