38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
# - *- 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)
|