Spaces:
Running
Running
File size: 775 Bytes
8bd3677 385ff96 8bd3677 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import motor.motor_asyncio
import logging
from config import MONGO_URI
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Database:
def __init__(self, uri: str):
self.client = motor.motor_asyncio.AsyncIOMotorClient(uri)
self.db = self.client["Akeno"]
self.antieval = self.db["antieval"]
self.warns = self.db["warns"]
async def connect(self):
try:
await self.client.admin.command("ping")
logger.info("Connected to the database.")
except Exception as e:
logger.error(f"Error connecting to the database: {e}")
async def close(self):
await self.client.close()
logger.info("Database connection closed.")
db = Database(MONGO_URI) |