From f24c37a266d28b3f7cff4518babb45eda1929869 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 8 Sep 2017 09:35:48 +0000 Subject: [PATCH] Update db structure --- PlusOne.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/PlusOne.py b/PlusOne.py index 3d8fe3f..bbfbf1e 100644 --- a/PlusOne.py +++ b/PlusOne.py @@ -8,10 +8,13 @@ import sys class PointDB(yaboli.Database): @yaboli.Database.operation def initialize(conn): - print("INITIALIZING") cur = conn.cursor() - cur.execute(("CREATE TABLE IF NOT EXISTS Points " - "(nick TEXT, points INTEGER)")) + cur.execute(( + "CREATE TABLE IF NOT EXISTS Points (" + "nick TEXT UNIQUE NOT NULL," + "points INTEGER" + ")" + )) conn.commit() @yaboli.Database.operation @@ -19,14 +22,8 @@ class PointDB(yaboli.Database): nick = mention_reduced(nick) cur = conn.cursor() - cur.execute("SELECT * FROM Points WHERE nick=?", (nick,)) - if cur.fetchone(): - print(f"@{nick}: already in db, updating...") - cur.execute("UPDATE Points SET points=points+1 WHERE nick=?", (nick,)) - else: - print(f"@{nick}: not in db, adding...") - cur.execute("INSERT INTO Points (nick, points) VALUES (?, 1)", (nick,)) - + cur.execute("INSERT OR IGNORE INTO Points (nick, points) VALUES (?, 0)", (nick,)) + cur.execute("UPDATE Points SET points=points+1 WHERE nick=?", (nick,)) conn.commit() @yaboli.Database.operation