aboutsummaryrefslogtreecommitdiff
path: root/api/randid.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
commit28f104de9ae9abe4b42abafbf3865ede5687996c (patch)
tree65e651f09d8fbf81380384692e45803cb4f9d61c /api/randid.py
parent7b4859059b3bbabf4139ccdf3270a82c094f5d8e (diff)
dprint yapf python formatting
Diffstat (limited to 'api/randid.py')
-rw-r--r--api/randid.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/api/randid.py b/api/randid.py
index 0683c75..c837c2f 100644
--- a/api/randid.py
+++ b/api/randid.py
@@ -1,18 +1,18 @@
from db import cursor
import uuid
-tables = {
- "users": "user_id",
- "games": "game_id"
- }
+tables = {"users": "user_id", "games": "game_id"}
+
# generate a new uuid and check for collisions (unlikely but still)
def new_uuid(table_name):
- temp_uuid = str(uuid.uuid4())
- 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
-
+ temp_uuid = str(uuid.uuid4())
+ 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