mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-07-25 17:54:31 +00:00
37 lines
1.0 KiB
Python
37 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 # Статус работы бота
|
|
|
|
|
|
# Работа с настройками
|
|
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)
|