Skip to content

Commit

Permalink
added get & set user profile, added admin field in user db
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonp committed Jul 9, 2014
1 parent 166d006 commit d086e60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Binary file modified botspade.db
Binary file not shown.
5 changes: 3 additions & 2 deletions botspade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
@db = SQLite3::Database.new "botspade.db"

# Initial Tables - points / checkin / viewers / games / bets
#
# We will generate a custom user table so we have a relational ID for other tables.
@db.execute "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, points INT, first_seen BIGINT, last_seen BIGINT, profile TEXT)"
@db.execute "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, points INT, first_seen BIGINT, last_seen BIGINT, profile TEXT, admin INT)"
@db.execute "CREATE UNIQUE INDEX IF NOT EXISTS username ON users (username)"

# migration assist - will remove eventually
# @db.execute "ALTER TABLE users ADD COLUMN profile TEXT;"
# @db.execute "ALTER TABLE users ADD COLUMN admin INT;"

# Each checkin will have its own row, With related ID from users table and timestamp of when.
@db.execute "CREATE TABLE IF NOT EXISTS checkins (id INTEGER PRIMARY KEY, user_id INT, timestamp BIGINT)"
Expand Down
12 changes: 12 additions & 0 deletions botspade_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def db_checkins_get(user_id)
def db_checkins_save(user_id, points)
@db.execute( "UPDATE users SET points = ? WHERE id = ?", [points, user_id] )
end

# Get & Set user profile info
#

def db_set_profile(user_id, profile)
@db.execute( "UPDATE users SET profile = ? WHERE id = ?", [profile, user_id] )
end

def db_get_profile(user_id)
profile = @db.execute( "SELECT profile FROM users WHERE id = ?", [user_id] )
return profile
end

def db_checkins(limit)
checkins = @db.execute( "SELECT u.username, COUNT(1) as count FROM checkins AS c JOIN users AS u ON u.id = c.user_id GROUP BY user_id ORDER BY count DESC LIMIT ?", [limit] )
Expand Down

0 comments on commit d086e60

Please sign in to comment.