This repository has been archived on 2022-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
sh_gismo/src/gismo_data/model/user.py

81 lines
1.9 KiB
Python

from typing import Optional
from cpl_core.database import TableABC
from gismo_data.model.server import Server
class User(TableABC):
def __init__(self, dc_id: int, xp: int, server: Optional[Server], id=0):
self._user_id = id
self._discord_id = dc_id
self._xp = xp
self._server = server
@property
def user_id(self) -> int:
return self._user_id
@property
def discord_id(self) -> int:
return self._discord_id
@property
def xp(self) -> int:
return self._xp
@xp.setter
def xp(self, value: int):
self._xp = value
@property
def server(self) -> Optional[Server]:
return self._server
@staticmethod
def get_create_string() -> str:
return str(f"""
CREATE TABLE IF NOT EXISTS `Users` (
`UserId` INT(30) NOT NULL AUTO_INCREMENT,
`DiscordId` INT(30) NOT NULL,
`XP` INT(30) NOT NULL DEFAULT 0,
`ServerId` INT(30),
FOREIGN KEY (`UserId`) REFERENCES Server(`ServerId`),
PRIMARY KEY(`UserId`)
);
""")
@staticmethod
def get_select_all_string() -> str:
return str(f"""
SELECT * FROM `Users`;
""")
@staticmethod
def get_select_by_id_string(id: int) -> str:
return str(f"""
SELECT * FROM `Users`
WHERE `UserId` = {id};
""")
@staticmethod
def get_select_by_discord_id_string(id: int) -> str:
return str(f"""
SELECT * FROM `Users`
WHERE `DiscordId` = {id};
""")
@property
def insert_string(self) -> str:
return str(f"""
""")
@property
def udpate_string(self) -> str:
return str(f"""
""")
@property
def delete_string(self) -> str:
return str(f"""
""")