Skip to content

Commit

Permalink
Update...
Browse files Browse the repository at this point in the history
  • Loading branch information
MRK-YT authored Jun 11, 2021
1 parent 375526d commit 5d2f234
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bot/database/database.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import os
import motor.motor_asyncio # pylint: disable=import-error
from bot import DB_URI

DB_NAME = os.environ.get("DB_NAME", "Adv_Auto_Filter")
class Singleton(type):
__instances__ = {}

class Database:
def __call__(cls, *args, **kwargs):
if cls not in cls.__instances__:
cls.__instances__[cls] = super(Singleton, cls).__call__(*args, **kwargs)

return cls.__instances__[cls]


class Database(metaclass=Singleton):

def __init__(self):
self._client = motor.motor_asyncio.AsyncIOMotorClient(DB_URI)
self.db = self._client[DB_NAME]
self.db = self._client["Adv_Auto_Filter"]
self.col = self.db["Main"]
self.acol = self.db["Active_Chats"]
self.fcol = self.db["Filter_Collection"]
Expand Down Expand Up @@ -495,3 +502,4 @@ async def tf_count(self, group_id: int):
"""
return await self.fcol.count_documents({"group_id": group_id})


0 comments on commit 5d2f234

Please sign in to comment.