A-0.3 - Basismodul #36
115
src/gismo_data/model/client.py
Normal file
115
src/gismo_data/model/client.py
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from cpl_core.database import TableABC
|
||||||
|
|
||||||
|
from gismo_data.model.server import Server
|
||||||
|
|
||||||
|
|
||||||
|
class Client(TableABC):
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
dc_id: int,
|
||||||
|
smc: int,
|
||||||
|
rmc: int,
|
||||||
|
dmc: int,
|
||||||
|
rcc: int,
|
||||||
|
muc: int,
|
||||||
|
server: Server,
|
||||||
|
created_at: datetime = None,
|
||||||
|
modified_at: datetime = None,
|
||||||
|
id=0
|
||||||
|
):
|
||||||
|
self._client_id = id
|
||||||
|
self._discord_client_id = dc_id
|
||||||
|
self._sent_message_count = smc
|
||||||
|
self._received_message_count = rmc
|
||||||
|
self._deleted_message_count = dmc
|
||||||
|
self._received_command_count = rcc
|
||||||
|
self._moved_users_count = muc
|
||||||
|
self._server: Server = server
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_create_string() -> str:
|
||||||
|
return str(f"""
|
||||||
|
CREATE TABLE IF NOT EXISTS `Clients` (
|
||||||
|
`ClientId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||||
|
`DiscordClientId` BIGINT NOT NULL,
|
||||||
|
`SentMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`ReceivedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`DeletedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`ReceivedCommandsCount` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`MovedUsersCount` BIGINT NOT NULL DEFAULT 0,
|
||||||
|
`ServerId` BIGINT,
|
||||||
|
`CreatedAt` DATETIME(6),
|
||||||
|
`LastModifiedAt` DATETIME(6),
|
||||||
|
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||||
|
PRIMARY KEY(`UserId`)
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_select_all_string() -> str:
|
||||||
|
return str(f"""
|
||||||
|
SELECT * FROM `Clients`;
|
||||||
|
""")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_select_by_id_string(id: int) -> str:
|
||||||
|
return str(f"""
|
||||||
|
SELECT * FROM `Clients`
|
||||||
|
WHERE `ClientId` = {id};
|
||||||
|
""")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_select_by_discord_id_string(id: int) -> str:
|
||||||
|
return str(f"""
|
||||||
|
SELECT * FROM `Clients`
|
||||||
|
WHERE `DiscordClientId` = {id};
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def insert_string(self) -> str:
|
||||||
|
return str(f"""
|
||||||
|
INSERT INTO `Clients` (
|
||||||
|
`SentMessageCount`,
|
||||||
|
`ReceivedMessageCount`,
|
||||||
|
`DeletedMessageCount`,
|
||||||
|
`ReceivedCommandsCount`,
|
||||||
|
`MovedUsersCount`,
|
||||||
|
`ServerId`,
|
||||||
|
`CreatedAt`,
|
||||||
|
`LastModifiedAt`
|
||||||
|
) VALUES (
|
||||||
|
{self._sent_message_count},
|
||||||
|
{self._received_message_count},
|
||||||
|
{self._deleted_message_count},
|
||||||
|
{self._received_message_count},
|
||||||
|
{self._moved_users_count},
|
||||||
|
{self._server.id},
|
||||||
|
'{self._created_at}',
|
||||||
|
'{self._modified_at}'
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def udpate_string(self) -> str:
|
||||||
|
return str(f"""
|
||||||
|
UPDATE `Clients`
|
||||||
|
SET `SentMessageCount` = {self._sent_message_count},
|
||||||
|
`ReceivedMessageCount` = {self._received_message_count},
|
||||||
|
`DeletedMessageCount` = {self._deleted_message_count},
|
||||||
|
`ReceivedCommandsCount` = {self._received_command_count},
|
||||||
|
`MovedUsersCount` = {self._moved_users_count},
|
||||||
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
|
WHERE `Id` = {self._client_id};
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def delete_string(self) -> str:
|
||||||
|
return str(f"""
|
||||||
|
DELETE FROM `Clients`
|
||||||
|
WHERE `Id` = {self._client_id};
|
||||||
|
""")
|
Reference in New Issue
Block a user