summaryrefslogtreecommitdiff
path: root/poll.go
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-07-25 13:06:21 +0100
committerJoe Robinson <joe@mumsnet.com>2014-07-25 13:06:21 +0100
commit0d7a802091a40a7304a0c3d1113c0cafd6556365 (patch)
tree7a6595244229a2f5ff4132b6721c0c957930f232 /poll.go
parenta471e978989fecb533bcf8666772a8a425215346 (diff)
Added function to list recent polls
Diffstat (limited to 'poll.go')
-rw-r--r--poll.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/poll.go b/poll.go
index 0952cd7..8a204f1 100644
--- a/poll.go
+++ b/poll.go
@@ -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