diff options
| author | A Farzat <a@farzat.xyz> | 2025-08-21 09:41:56 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-08-21 09:41:56 +0300 |
| commit | 69bcc9822c82ee6d726c98deafbdd0a20527a55a (patch) | |
| tree | e51ee23b3da922e1baf7bd57f5c724e928c70d86 /components/database.py | |
| parent | b141aa29f28c4e4281415b97dac8fe548b128f9b (diff) | |
| download | csca5028-69bcc9822c82ee6d726c98deafbdd0a20527a55a.tar.gz csca5028-69bcc9822c82ee6d726c98deafbdd0a20527a55a.zip | |
Move components to root directory
Some components might be shared with other applications such as the data
analyser later on.
Diffstat (limited to 'components/database.py')
| -rw-r--r-- | components/database.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/components/database.py b/components/database.py new file mode 100644 index 0000000..72f63e6 --- /dev/null +++ b/components/database.py @@ -0,0 +1,16 @@ +import atexit +from typing import Any, Dict +from pymongo import MongoClient +from pymongo.database import Database +from pymongo.collection import Collection +from components.subscriptions.typing import SubsDict +from components.users.typing import UserDict + +client: MongoClient[Any] = MongoClient("mongodb://localhost", tz_aware=True) +database: Database[Any] = client.get_database("youtube") +subscriptions: Collection[SubsDict] = database.get_collection("subscriptions") +users: Collection[UserDict] = database.get_collection("users") + +@atexit.register +def _cleanup() -> None: + client.close() |
