aboutsummaryrefslogtreecommitdiff
path: root/api/randid.py
blob: 6c1ca9d1ffd7ef657c7d07489c6112d2cb009f1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from db import cursor
import uuid

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