diff options
author | Joe Robinson <joe@mumsnet.com> | 2014-07-25 13:06:21 +0100 |
---|---|---|
committer | Joe Robinson <joe@mumsnet.com> | 2014-07-25 13:06:21 +0100 |
commit | 0d7a802091a40a7304a0c3d1113c0cafd6556365 (patch) | |
tree | 7a6595244229a2f5ff4132b6721c0c957930f232 /poll.go | |
parent | a471e978989fecb533bcf8666772a8a425215346 (diff) |
Added function to list recent polls
Diffstat (limited to 'poll.go')
-rw-r--r-- | poll.go | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -145,3 +145,25 @@ func hasUserVotedInPoll(db *sqlite3.Conn, poll Poll, user User) bool { //Not sure why we'd get here, but we probably don't want to record a vote if we did return true } + +func getRecentPolls(db *sqlite3.Conn) ([]Poll, error) { + + sql := "SELECT * FROM polls LIMIT 5" + s, err := db.Query(sql) + row := make(sqlite3.RowMap) + var polls = make([]Poll, 5) + i := 0 + + for ; err == nil ; err = s.Next() { + var rowid int64 + s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row + + poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int64)} + polls[i] = poll + i++ + } + + //If we get here there are no matching polls, return an error + return polls, err + +}
\ No newline at end of file |