16 lines
579 B
Python
16 lines
579 B
Python
from motor.motor_asyncio import AsyncIOMotorClient
|
|
|
|
from models.Character import Character
|
|
|
|
|
|
class CharacterRepo:
|
|
def __init__(self, client: AsyncIOMotorClient, db_name="bot_db"):
|
|
self.collection = client[db_name]["characters"]
|
|
|
|
async def add_character(self, character: Character) -> Character:
|
|
op = await self.collection.insert_one(character.model_dump())
|
|
character.id = op.inserted_id
|
|
return character
|
|
|
|
async def get_character(self, character_id: int) -> Character:
|
|
return await self.collection.find_one({"id": character_id}) |