init
This commit is contained in:
16
repos/char_repo.py
Normal file
16
repos/char_repo.py
Normal file
@@ -0,0 +1,16 @@
|
||||
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})
|
||||
Reference in New Issue
Block a user