updates :)

This commit is contained in:
2026-06-20 17:07:48 +03:30
parent 24155ad6bf
commit 64886b2b10
17 changed files with 896 additions and 262 deletions
+3 -13
View File
@@ -9,7 +9,7 @@ from db.connection import get_db
FlowConfigRow = dict[str, Any]
_FIELDS = [
"name", "is_active",
"name",
"search_texts_json", "search_box_selector", "search_box_selector_type",
"search_submit_selector", "search_submit_selector_type",
"search_results_selector", "search_results_selector_type",
@@ -54,18 +54,16 @@ class FlowConfigRepository:
)).fetchone()
return _deserialise(dict(row)) if row else None
async def get_active(self) -> FlowConfigRow | None:
async def get_first(self) -> FlowConfigRow | None:
async with get_db() as db:
row = await (await db.execute(
"SELECT * FROM flow_configs WHERE is_active=1 ORDER BY id DESC LIMIT 1"
"SELECT * FROM flow_configs ORDER BY id ASC LIMIT 1"
)).fetchone()
return _deserialise(dict(row)) if row else None
async def create(self, data: dict[str, Any]) -> int:
data = _serialise(data)
async with get_db() as db:
if data.get("is_active"):
await db.execute("UPDATE flow_configs SET is_active=0")
placeholders = ", ".join("?" for _ in _FIELDS)
cols = ", ".join(_FIELDS)
values = [data.get(f) for f in _FIELDS]
@@ -78,8 +76,6 @@ class FlowConfigRepository:
async def update(self, cfg_id: int, data: dict[str, Any]) -> None:
data = _serialise(data)
async with get_db() as db:
if data.get("is_active"):
await db.execute("UPDATE flow_configs SET is_active=0")
set_clause = ", ".join(f"{f}=?" for f in _FIELDS)
values = [data.get(f) for f in _FIELDS] + [cfg_id]
await db.execute(
@@ -87,12 +83,6 @@ class FlowConfigRepository:
)
await db.commit()
async def activate(self, cfg_id: int) -> None:
async with get_db() as db:
await db.execute("UPDATE flow_configs SET is_active=0")
await db.execute("UPDATE flow_configs SET is_active=1 WHERE id=?", (cfg_id,))
await db.commit()
async def delete(self, cfg_id: int) -> None:
async with get_db() as db:
await db.execute("DELETE FROM flow_configs WHERE id=?", (cfg_id,))