Improved database connection
This commit is contained in:
@@ -29,7 +29,7 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
|
||||
def get_server_by_id(self, id: int) -> Server:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(id)}')
|
||||
result = self._context.select(Server.get_select_by_id_string(id))
|
||||
result = self._context.select(Server.get_select_by_id_string(id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
id=result[0]
|
||||
@@ -49,15 +49,18 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
result = result[0]
|
||||
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
def add_server(self, server: Server) -> int:
|
||||
def add_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.insert_string}')
|
||||
self._context.cursor.execute(server.insert_string)
|
||||
return int(self._context.select("SELECT LAST_INSERT_ID();")[0])
|
||||
|
||||
def update_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.udpate_string}')
|
||||
|
@@ -23,6 +23,7 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_all_string()}')
|
||||
results = self._context.select(User.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user with id {result[0]}')
|
||||
users.append(User(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -44,7 +45,7 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
|
||||
def get_user_by_discord_id(self, discord_id: int) -> User:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_string(discord_id))
|
||||
result = self._context.select(User.get_select_by_discord_id_string(discord_id))[0]
|
||||
return User(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -58,17 +59,20 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
result = result[0]
|
||||
|
||||
return User(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
def add_user(self, user: User) -> int:
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.insert_strin}')
|
||||
def add_user(self, user: User):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.insert_string}')
|
||||
self._context.cursor.execute(user.insert_string)
|
||||
return int(self._context.select("SELECT LAST_INSERT_ID();")[0])
|
||||
|
||||
def update_user(self, user: User):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.udpate_string}')
|
||||
|
Reference in New Issue
Block a user