From b8e340f66108a023deaf83d94fdf23da7390aef6 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 2 Dec 2021 17:35:03 +0100 Subject: [PATCH] Added known user model --- src/gismo_data/model/known_user.py | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/gismo_data/model/known_user.py diff --git a/src/gismo_data/model/known_user.py b/src/gismo_data/model/known_user.py new file mode 100644 index 0000000..8f0f38e --- /dev/null +++ b/src/gismo_data/model/known_user.py @@ -0,0 +1,80 @@ +from datetime import datetime +from typing import Optional +from cpl_core.database import TableABC + +from gismo_data.model.server import Server + + +class KnownUser(TableABC): + + def __init__(self, dc_id: int, created_at: datetime = None, modified_at: datetime = None, id=0): + self._known_user_id = id + self._discord_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 known_user_id(self) -> int: + return self._known_user_id + + @property + def discord_id(self) -> int: + return self._discord_id + + @staticmethod + def get_create_string() -> str: + return str(f""" + CREATE TABLE IF NOT EXISTS `KnownUsers` ( + `KnownUserId` BIGINT NOT NULL AUTO_INCREMENT, + `DiscordId` BIGINT NOT NULL, + `ServerId` BIGINT, + `CreatedAt` DATETIME(6), + `LastModifiedAt` DATETIME(6), + PRIMARY KEY(`KnownUserId`) + ); + """) + + @staticmethod + def get_select_all_string() -> str: + return str(f""" + SELECT * FROM `KnownUsers`; + """) + + @staticmethod + def get_select_by_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `KnownUsers` + WHERE `KnownUserId` = {id}; + """) + + @staticmethod + def get_select_by_discord_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `KnownUsers` + WHERE `DiscordId` = {id}; + """) + + @property + def insert_string(self) -> str: + return str(f""" + INSERT INTO `KnownUsers` ( + `DiscordId`, `CreatedAt`, `LastModifiedAt` + ) VALUES ( + {self._discord_id}, + '{self._created_at}', + '{self._modified_at}' + ); + """) + + @property + def udpate_string(self) -> str: + return '' + + @property + def delete_string(self) -> str: + return str(f""" + DELETE FROM `KnownUsers` + WHERE `Id` = {self._known_user_id}; + """)