Smart curosr for Game Tables
This commit is contained in:
@@ -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
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user