mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 15:15:37 +01:00
New structure
This commit is contained in:
18
src/applications/common/repositories/base.py
Normal file
18
src/applications/common/repositories/base.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import abc
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from core.mongo import mongo_manager
|
||||
|
||||
|
||||
class BaseRepository(abc.ABC):
|
||||
COLLECTION_NAME: str
|
||||
|
||||
@classmethod
|
||||
@asynccontextmanager
|
||||
async def connect(cls):
|
||||
async with mongo_manager.connect() as client:
|
||||
db = client.get_default_database()
|
||||
collection = db[cls.COLLECTION_NAME]
|
||||
|
||||
yield collection
|
||||
Reference in New Issue
Block a user