File: database.py

package info (click to toggle)
python-beanie 1.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,544 kB
  • sloc: python: 14,413; makefile: 7; sh: 6
file content (16 lines) | stat: -rw-r--r-- 413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import motor.motor_asyncio


class DBHandler:
    @classmethod
    def set_db(cls, uri, db_name):
        cls.client = motor.motor_asyncio.AsyncIOMotorClient(uri)
        cls.database = cls.client[db_name]

    @classmethod
    def get_cli(cls):
        return cls.client if hasattr(cls, "client") else None

    @classmethod
    def get_db(cls):
        return cls.database if hasattr(cls, "database") else None