| 7 | from config import CDB_NAME, CLONE_DB_URI |
| 8 | |
| 9 | class Database: |
| 10 | |
| 11 | def __init__(self, uri, database_name): |
| 12 | self._client = motor.motor_asyncio.AsyncIOMotorClient(uri) |
| 13 | self.db = self._client[database_name] |
| 14 | |
| 15 | async def add_user(self, bot_id, user_id): |
| 16 | user = {'user_id': int(user_id)} |
| 17 | await self.db[str(bot_id)].insert_one(user) |
| 18 | |
| 19 | async def is_user_exist(self, bot_id, id): |
| 20 | user = await self.db[str(bot_id)].find_one({'user_id': int(id)}) |
| 21 | return bool(user) |
| 22 | |
| 23 | async def total_users_count(self, bot_id): |
| 24 | count = await self.db[str(bot_id)].count_documents({}) |
| 25 | return count |
| 26 | |
| 27 | async def get_all_users(self, bot_id): |
| 28 | return self.db[str(bot_id)].find({}) |
| 29 | |
| 30 | async def delete_user(self, bot_id, user_id): |
| 31 | await self.db[str(bot_id)].delete_many({'user_id': int(user_id)}) |
| 32 | |
| 33 | |
| 34 | clonedb = Database(CLONE_DB_URI, CDB_NAME) |