Smart curosr for Game Tables

This commit is contained in:
iamBadgers
2026-04-04 19:40:55 -07:00
parent d549f7d83d
commit 917870128d
4 changed files with 52 additions and 45 deletions

View File

@@ -1,3 +1,7 @@
from sqlite3 import Connection, Cursor
from database import SmartCursor
class GameTable:
_game_table_id: int
_game_table_name: str
@@ -112,33 +116,42 @@ class GameTable:
self._docker_id = docker_id
def read_by_id(game_table_id, cursor):
rows = cursor.execute(
"""SELECT game_table_id, game_table_name, game_table_link, active, docker_id
FROM game_tables
WHERE game_table_id = ?""",
(game_table_id,),
).fetchone()
class GameService:
connection: Connection
if len(rows) == 0:
return None
def __init__(self, connection: Connection):
self.connection = connection
return GameTable(rows[0], rows[1], rows[2], rows[3], rows[4], True, True)
def read_by_id(self, game_table_id, cursor=None):
with SmartCursor(cursor, self.connection) as smartCursor:
rows = smartCursor.execute(
"""SELECT game_table_id, game_table_name, game_table_link, active, docker_id
FROM game_tables
WHERE game_table_id = ?""",
(game_table_id,),
).fetchone()
if len(rows) == 0:
return None
def read_all(cursor):
rows = cursor.execute(
"SELECT game_table_id, game_table_name, game_table_link, active, docker_id FROM game_tables"
).fetchall()
return [
GameTable(row[0], row[1], row[2], row[3], row[4], True, True) for row in rows
]
return GameTable(rows[0], rows[1], rows[2], rows[3], rows[4], True, True)
def read_all(self, cursor=None):
with SmartCursor(cursor, self.connection) as smartCursor:
rows = smartCursor.execute(
"SELECT game_table_id, game_table_name, game_table_link, active, docker_id FROM game_tables"
).fetchall()
return [
GameTable(row[0], row[1], row[2], row[3], row[4], True, True)
for row in rows
]
def read_active(cursor):
rows = cursor.execute(
"SELECT game_table_id, game_table_name, game_table_link, active, docker_id FROM game_tables WHERE active != 0"
).fetchall()
return [
GameTable(row[0], row[1], row[2], row[3], row[4], True, True) for row in rows
]
def read_active(self, cursor=None):
with SmartCursor(cursor, self.connection) as smartCursor:
rows = smartCursor.execute(
"SELECT game_table_id, game_table_name, game_table_link, active, docker_id FROM game_tables WHERE active != 0"
).fetchall()
return [
GameTable(row[0], row[1], row[2], row[3], row[4], True, True)
for row in rows
]