MCPcopy Create free account
hub / github.com/VJBots/VJ-File-Store / Database

Class Database

plugins/dbusers.py:8–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6from config import DB_NAME, DB_URI
7
8class Database:
9
10 def __init__(self, uri, database_name):
11 self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
12 self.db = self._client[database_name]
13 self.col = self.db.users
14
15 def new_user(self, id, name):
16 return dict(
17 id = id,
18 name = name,
19 )
20
21 async def add_user(self, id, name):
22 user = self.new_user(id, name)
23 await self.col.insert_one(user)
24
25 async def is_user_exist(self, id):
26 user = await self.col.find_one({'id':int(id)})
27 return bool(user)
28
29 async def total_users_count(self):
30 count = await self.col.count_documents({})
31 return count
32
33 async def get_all_users(self):
34 return self.col.find({})
35
36 async def delete_user(self, user_id):
37 await self.col.delete_many({'id': int(user_id)})
38
39
40db = Database(DB_URI, DB_NAME)

Callers 1

dbusers.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected