TelegramDB

class telegramdb.TelegramDB(telegram_client: Client | TelegramClient, chat_id: int | str | None = None, debug: bool = False, logger: Logger | None = None)

Bases: object

Main object which initialises the telegram database session.

Parameters:
  • telegram_client (pyrogram.Client | telethon.TelegramClient) – Telegram client which will be used to save database queries on telegram.

  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • debug (bool, Optional) – Database queries will be debugged if it is set to True.

  • logger (logging.Logger, Optional) – Logger which will be used for debugging.

Example

from telegramdb import TelegramDB
from pyrogram import Client

client = Client(
    "my_account",
    api_id=12345,
    api_hash="0123456789abcdef0123456789abcdef"
)
chat_id = 777000
SESSION = TelegramDB(client, chat_id)
commit(datapack: DataPack)

Use this method to save the data on telegram database.

Parameters:

datapack (DataPack) – Subclass of the DataPack of the data to be saved on telegram.

Returns:

None

delete(datapack: DataPack)

Use this method to delete data from telegram database.

Parameters:

datapack (DataPack) – Object of the DataPack of the data to be retrieved from telegram database.

Returns:

bool

get(datapack: DataPack)

Use this method to get the data from telegram database.

Parameters:

datapack (DataPack) – Object of the DataPack of the data to be retrieved from telegram database.

Returns:

bool

get_all()

Use this method to get all data from telegram database.

Returns:

A list containing elements of object DataPack

prepare_datapack(datapack_class: DataPack)

Use this method to initialise the DataPack with primary key member.

Parameters:

datapack_class (DataPack) – DataPack to be initialised with the primary key.

Returns:

None