create user database

This commit is contained in:
levina 2022-02-05 10:28:59 +07:00 committed by GitHub
parent fed2849f0f
commit 3193ca6b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,28 @@
from typing import Dict, List, Union
from driver.database.dblocal import db
usersdb = db.users
async def is_served_user(user_id: int) -> bool:
user = await usersdb.find_one({"user_id": user_id})
if not user:
return False
return True
async def get_served_users() -> list:
users = usersdb.find({"user_id": {"$gt": 0}})
if not users:
return []
users_list = []
for user in await users.to_list(length=1000000000):
users_list.append(user)
return users_list
async def add_served_user(user_id: int):
is_served = await is_served_user(user_id)
if is_served:
return
return await usersdb.insert_one({"user_id": user_id})