refactor: move sector phase persistence to heaven repository
This commit is contained in:
@@ -7,6 +7,35 @@ from typing import Any
|
|||||||
|
|
||||||
|
|
||||||
class HeavenRepositoryMixin:
|
class HeavenRepositoryMixin:
|
||||||
|
def list_sector_phase_overrides(self) -> dict[str, str]:
|
||||||
|
with self.connect() as connection:
|
||||||
|
rows = connection.execute(
|
||||||
|
"SELECT name, element FROM sector_phase_overrides ORDER BY updated_at DESC, name"
|
||||||
|
).fetchall()
|
||||||
|
return {row["name"]: row["element"] for row in rows}
|
||||||
|
|
||||||
|
def save_sector_phase_override(self, name: str, element: str) -> None:
|
||||||
|
now = datetime.now().astimezone().isoformat(timespec="seconds")
|
||||||
|
with self.connect() as connection:
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO sector_phase_overrides (name, element, updated_at)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
ON CONFLICT(name) DO UPDATE SET
|
||||||
|
element = excluded.element,
|
||||||
|
updated_at = excluded.updated_at
|
||||||
|
""",
|
||||||
|
(name, element, now),
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete_sector_phase_override(self, name: str) -> bool:
|
||||||
|
with self.connect() as connection:
|
||||||
|
cursor = connection.execute(
|
||||||
|
"DELETE FROM sector_phase_overrides WHERE name = ?",
|
||||||
|
(name,),
|
||||||
|
)
|
||||||
|
return cursor.rowcount > 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _heaven_reading_dict(row: sqlite3.Row | None) -> dict[str, Any] | None:
|
def _heaven_reading_dict(row: sqlite3.Row | None) -> dict[str, Any] | None:
|
||||||
if not row:
|
if not row:
|
||||||
|
|||||||
@@ -384,8 +384,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "database.py",
|
"path": "database.py",
|
||||||
"bytes": 33284,
|
"bytes": 32073,
|
||||||
"lines": 746
|
"lines": 716
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-31
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -665,36 +665,6 @@ class ReviewDatabase(
|
|||||||
)
|
)
|
||||||
MigrationRunner().apply(connection, MIGRATIONS)
|
MigrationRunner().apply(connection, MIGRATIONS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_sector_phase_overrides(self) -> dict[str, str]:
|
|
||||||
with self.connect() as connection:
|
|
||||||
rows = connection.execute(
|
|
||||||
"SELECT name, element FROM sector_phase_overrides ORDER BY updated_at DESC, name"
|
|
||||||
).fetchall()
|
|
||||||
return {row["name"]: row["element"] for row in rows}
|
|
||||||
|
|
||||||
def save_sector_phase_override(self, name: str, element: str) -> None:
|
|
||||||
now = datetime.now().astimezone().isoformat(timespec="seconds")
|
|
||||||
with self.connect() as connection:
|
|
||||||
connection.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO sector_phase_overrides (name, element, updated_at)
|
|
||||||
VALUES (?, ?, ?)
|
|
||||||
ON CONFLICT(name) DO UPDATE SET
|
|
||||||
element = excluded.element,
|
|
||||||
updated_at = excluded.updated_at
|
|
||||||
""",
|
|
||||||
(name, element, now),
|
|
||||||
)
|
|
||||||
|
|
||||||
def delete_sector_phase_override(self, name: str) -> bool:
|
|
||||||
with self.connect() as connection:
|
|
||||||
cursor = connection.execute(
|
|
||||||
"DELETE FROM sector_phase_overrides WHERE name = ?",
|
|
||||||
(name,),
|
|
||||||
)
|
|
||||||
return cursor.rowcount > 0
|
|
||||||
def list_wencai_saved_queries(
|
def list_wencai_saved_queries(
|
||||||
self, user_id: int, limit: int = 30
|
self, user_id: int, limit: int = 30
|
||||||
) -> list[dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ HEAVEN_SERVICE_METHODS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HEAVEN_REPOSITORY_METHODS = {
|
HEAVEN_REPOSITORY_METHODS = {
|
||||||
|
"list_sector_phase_overrides",
|
||||||
|
"save_sector_phase_override",
|
||||||
|
"delete_sector_phase_override",
|
||||||
"_heaven_reading_dict",
|
"_heaven_reading_dict",
|
||||||
"save_heaven_reading",
|
"save_heaven_reading",
|
||||||
"list_heaven_readings",
|
"list_heaven_readings",
|
||||||
|
|||||||
Reference in New Issue
Block a user