Some changes

This commit is contained in:
2024-02-29 16:51:40 +01:00
parent 5e7b32dc7a
commit be3776e1ce
5 changed files with 76 additions and 24 deletions

View File

@@ -76,19 +76,21 @@ class BaseEngine(ABC):
# noinspection PyShadowingBuiltins
@classmethod
def store_setting(cls, *, type: str = None, data: dict):
def store_setting(cls, *, identifier: str = None, type: str = None, data: dict):
if not identifier and type:
identifier = type
with SessionLocal() as db:
# check if setting exists
# noinspection PyTypeChecker
setting = db.execute(
select(Setting).filter(
Setting.provider == cls.name, Setting.type == type
Setting.provider == cls.name, Setting.type == identifier
)
).scalar()
if setting:
setting.data = data
else:
db.add(Setting(provider=cls.name, type=type, data=data))
db.add(Setting(provider=cls.name, type=identifier, data=data))
db.commit()
@classmethod