Skip to content

models/telegram_db.py

models.telegram_db

TelegramDB

TelegramDB

Bases: DBBase

TelegramDB Collection

Source code in models/telegram_db.py
class TelegramDB(DBBase):
    ''' TelegramDB Collection '''

    def __init__(self) -> None:
        super().__init__('telegram')

    def index(self) -> None:
        ''' To make collection's index

        Indexs:
            - `uid`, `uid`

        '''
        self.create_index([('uid', 1), ])

    def add(self, data: dict[str, Any]) -> None:
        ''' save data

        Args:
            data (dict): The data to insert / update.

        The data's struct

        Struct:
            - `_id`: telegram id.
            - `added`: Added time in datatime.
            - `first_name`: First name.
            - `id`: telegram id.
            - `is_bot`: `bool`.
            - `language_code`: Language in ISO 639.
            - `uid`: Mapping to our user id.
            - `username`: User name.

        TODO:
            Need refactor in pydantic.

        '''
        self.find_one_and_update(
            {'_id': data['id']},
            {'$set': data},
            upsert=True,
            return_document=ReturnDocument.AFTER,
        )

add

add(data: dict[str, Any]) -> None

save data

Parameters:

Name Type Description Default
data dict

The data to insert / update.

required

The data's struct

Struct
  • _id: telegram id.
  • added: Added time in datatime.
  • first_name: First name.
  • id: telegram id.
  • is_bot: bool.
  • language_code: Language in ISO 639.
  • uid: Mapping to our user id.
  • username: User name.
TODO

Need refactor in pydantic.

Source code in models/telegram_db.py
def add(self, data: dict[str, Any]) -> None:
    ''' save data

    Args:
        data (dict): The data to insert / update.

    The data's struct

    Struct:
        - `_id`: telegram id.
        - `added`: Added time in datatime.
        - `first_name`: First name.
        - `id`: telegram id.
        - `is_bot`: `bool`.
        - `language_code`: Language in ISO 639.
        - `uid`: Mapping to our user id.
        - `username`: User name.

    TODO:
        Need refactor in pydantic.

    '''
    self.find_one_and_update(
        {'_id': data['id']},
        {'$set': data},
        upsert=True,
        return_document=ReturnDocument.AFTER,
    )

index

index() -> None

To make collection's index

Indexs
  • uid, uid
Source code in models/telegram_db.py
def index(self) -> None:
    ''' To make collection's index

    Indexs:
        - `uid`, `uid`

    '''
    self.create_index([('uid', 1), ])