beanie/migrations/database.py
raw| 1 | from pymongo import AsyncMongoClient |
| 2 | |
| 3 | |
| 4 | class DBHandler: |
| 5 | @classmethod |
| 6 | def set_db(cls, uri, db_name): |
| 7 | cls.client = AsyncMongoClient(uri) |
| 8 | cls.database = cls.client[db_name] |
| 9 | |
| 10 | @classmethod |
| 11 | def get_cli(cls): |
| 12 | return cls.client if hasattr(cls, "client") else None |
| 13 | |
| 14 | @classmethod |
| 15 | def get_db(cls): |
| 16 | return cls.database if hasattr(cls, "database") else None |