parsertenders/tgbot/database/db_settings.py
2024-11-03 21:16:44 +07:00

38 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# - *- coding: utf- 8 - *-
import sqlite3
from pydantic import BaseModel
from tgbot.data.config import PATH_DATABASE
from tgbot.database.db_helper import dict_factory, update_format
# Модель таблицы
class SettingsModel(BaseModel):
status_work: str
status_sched_tenders: str
# Работа с настройками
class Settingsx:
storage_name = "storage_settings"
# Получение записи
@staticmethod
def get() -> SettingsModel:
with sqlite3.connect(PATH_DATABASE) as con:
con.row_factory = dict_factory
sql = f"SELECT * FROM {Settingsx.storage_name}"
return SettingsModel(**con.execute(sql).fetchone())
# Редактирование записи
@staticmethod
def update(**kwargs):
with sqlite3.connect(PATH_DATABASE) as con:
con.row_factory = dict_factory
sql = f"UPDATE {Settingsx.storage_name} SET"
sql, parameters = update_format(sql, kwargs)
con.execute(sql, parameters)