Create database.py
Browse files- database.py +26 -0
database.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
from motor import motor_asyncio
|
3 |
+
from motor.core import AgnosticClient
|
4 |
+
|
5 |
+
LOGS = logging.getLogger(__name__)
|
6 |
+
|
7 |
+
from config import *
|
8 |
+
|
9 |
+
class Database:
|
10 |
+
def __init__(self, uri: str) -> None:
|
11 |
+
self.client: AgnosticClient = motor_asyncio.AsyncIOMotorClient(uri)
|
12 |
+
self.db = self.client["Akeno"]
|
13 |
+
self.users_detection = self.db["users_detection"]
|
14 |
+
|
15 |
+
async def connect(self):
|
16 |
+
try:
|
17 |
+
await self.client.admin.command("ping")
|
18 |
+
LOGS.info(f"Database Connection Established!")
|
19 |
+
except Exception as e:
|
20 |
+
LOGS.info(f"DatabaseErr: {e} ")
|
21 |
+
quit(1)
|
22 |
+
|
23 |
+
async def _close(self):
|
24 |
+
await self.client.close()
|
25 |
+
|
26 |
+
db = Database(MONGO_URI)
|