summaryrefslogtreecommitdiff
path: root/poll.go
diff options
context:
space:
mode:
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