from datetime import datetime from typing import Optional from cpl_core.database import TableABC class Server(TableABC): def __init__(self, dc_id: int, created_at: datetime=None, modified_at: datetime=None, id=0): self._server_id = id self._discord_server_id = dc_id TableABC.__init__(self) self._created_at = created_at if created_at is not None else self._created_at self._modified_at = modified_at if modified_at is not None else self._modified_at @property def server_id(self) -> int: return self._server_id @property def discord_server_id(self) -> int: return self._discord_server_id @staticmethod def get_create_string() -> str: return str(f""" CREATE TABLE IF NOT EXISTS `Servers` ( `ServerId` BIGINT NOT NULL AUTO_INCREMENT, `DiscordServerId` BIGINT NOT NULL, `CreatedAt` DATETIME(6), `LastModifiedAt` DATETIME(6), PRIMARY KEY(`ServerId`) ); """) @staticmethod def get_select_all_string() -> str: return str(f""" SELECT * FROM `Servers`; """) @staticmethod def get_select_by_id_string(id: int) -> str: return str(f""" SELECT * FROM `Servers` WHERE `ServerId` = {id}; """) @staticmethod def get_select_by_discord_id_string(id: int) -> str: return str(f""" SELECT * FROM `Servers` WHERE `DiscordServerId` = {id}; """) @property def insert_string(self) -> str: return str(f""" INSERT INTO `Servers` ( `DiscordServerId`, `CreatedAt`, `LastModifiedAt` ) VALUES ( {self._discord_server_id}, '{self._created_at}', '{self._modified_at}' ); """) @property def udpate_string(self) -> str: return str(f""" UPDATE `Servers` SET `DiscordServerId` = {self._discord_server_id}, `LastModifiedAt` = '{self._modified_at}' WHERE `Id` = {self._id}; """) @property def delete_string(self) -> str: return str(f""" DELETE FROM `Servers` WHERE `Id` = {self._id}; """)