This repository has been archived on 2024-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
PyrogramBotBase/modules/database.py

27 lines
807 B
Python
Raw Normal View History

2023-08-14 16:16:30 +03:00
"""Module that provides all database collections"""
2023-08-03 22:29:47 +03:00
2023-08-18 00:04:38 +03:00
from typing import Any, Mapping
from async_pymongo import AsyncClient, AsyncCollection, AsyncDatabase
2023-08-14 16:16:30 +03:00
from libbot.sync import config_get
2023-08-03 22:29:47 +03:00
2023-08-18 00:04:38 +03:00
db_config: Mapping[str, Any] = config_get("database")
2023-08-03 22:29:47 +03:00
if db_config["user"] is not None and db_config["password"] is not None:
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
db_config["user"],
db_config["password"],
db_config["host"],
db_config["port"],
db_config["name"],
)
else:
con_string = "mongodb://{0}:{1}/{2}".format(
db_config["host"], db_config["port"], db_config["name"]
)
2023-08-14 16:16:30 +03:00
db_client = AsyncClient(con_string)
2023-08-18 00:04:38 +03:00
db: AsyncDatabase = db_client.get_database(name=db_config["name"])
2023-08-03 22:29:47 +03:00
2023-08-18 00:04:38 +03:00
col_users: AsyncCollection = db.get_collection("users")