Add smart cursor stuff
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
from sqlite3 import Connection, Cursor
|
||||
from database import SmartCursor
|
||||
|
||||
|
||||
class KeyTable:
|
||||
key: str
|
||||
game_table_id: number
|
||||
@@ -50,32 +54,41 @@ class KeyTable:
|
||||
self.updated = True
|
||||
|
||||
|
||||
def get_key_for_table(game_table_id, cursor):
|
||||
cursor.execute(
|
||||
"""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id = ?""",
|
||||
(game_table_id,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
class KeyService:
|
||||
|
||||
if row == None:
|
||||
return None
|
||||
connection: Connection
|
||||
|
||||
return KeyTable(row[0], row[1])
|
||||
def __init__(self, connection: Connection):
|
||||
self.connection = connection
|
||||
|
||||
def get_key_for_table(self, game_table_id, cursor=None) -> KeyTable:
|
||||
with SmartCursor(cursor, self.connection) as smartCursor:
|
||||
smartCursor.execute(
|
||||
"""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id = ?""",
|
||||
(game_table_id,),
|
||||
)
|
||||
row = smartCursor.fetchone()
|
||||
|
||||
def get_reserved_keys(cursor):
|
||||
curosr.execute("""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id IS NOT NULL""")
|
||||
rows = cursor.fetchall()
|
||||
return [KeyTable(row[0], row[1]) for row in rows]
|
||||
if row == None:
|
||||
return None
|
||||
|
||||
return KeyTable(row[0], row[1])
|
||||
|
||||
def get_free_keys(cursor):
|
||||
cursor.execute("""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id IS NULL""")
|
||||
rows = cursor.fetchall()
|
||||
return [KeyTable(row[0], row[1]) for row in rows]
|
||||
def get_reserved_keys(self, cursor=None) -> KeyTable:
|
||||
with SmartCursor(cursor, self.connection) as smartCursor:
|
||||
smartCurosr.execute("""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id IS NOT NULL""")
|
||||
rows = smartCursor.fetchall()
|
||||
|
||||
return [KeyTable(row[0], row[1]) for row in rows]
|
||||
|
||||
def get_free_keys(self, cursor=None) -> KeyTable:
|
||||
with SmartCursor(cursor, connection) as smartCursor:
|
||||
smartCursor.execute("""SELECT key, game_table_id
|
||||
FROM game_keys
|
||||
WHERE game_table_id IS NULL""")
|
||||
rows = smartCursor.fetchall()
|
||||
return [KeyTable(row[0], row[1]) for row in rows]
|
||||
|
||||
Reference in New Issue
Block a user