aboutsummaryrefslogtreecommitdiff
path: root/api/randid.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-12 18:56:52 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-12 18:56:52 +0100
commit5f391aadbcc818ab7fa13312fb2ee04ed02983c6 (patch)
tree59a50473839a26370b6d1a51cb430adb49b26536 /api/randid.py
parentb8f3a658253bb5991a3d034733b685cc7d543704 (diff)
base /api/game/new
Diffstat (limited to 'api/randid.py')
-rw-r--r--api/randid.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/api/randid.py b/api/randid.py
index b9292b6..645d0a0 100644
--- a/api/randid.py
+++ b/api/randid.py
@@ -1,11 +1,17 @@
from main import cursor
import uuid
-def new_uuid():
+tables = {
+ "users": "user_id",
+ "games": "game_id"
+ }
+
+def new_uuid(table_name):
temp_uuid = str(uuid.uuid4())
- # check if user_id is already taken
- if cursor.execute("select user_id from users where user_id = ?", [temp_uuid]).fetchone():
- return new_uuid()
+ column_name = tables[table_name]
+ # check if id is already taken
+ if cursor.execute(f"select {column_name} from {table_name} where {column_name} = ?", [temp_uuid]).fetchone():
+ return new_uuid(table_name)
else:
return temp_uuid