This commit is contained in:
+5
-1
@@ -204,7 +204,11 @@ async def get_series_sources(dependencies: dict):
|
|||||||
ORDER BY source
|
ORDER BY source
|
||||||
""")
|
""")
|
||||||
|
|
||||||
sources = [row[0] for row in cursor.fetchall()]
|
rows = cursor.fetchall()
|
||||||
|
if db.db_type == "postgresql":
|
||||||
|
sources = [list(row.values())[0] for row in rows]
|
||||||
|
else:
|
||||||
|
sources = [row[0] for row in rows]
|
||||||
return {"sources": sources}
|
return {"sources": sources}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+21
-8
@@ -79,6 +79,15 @@ class NFOGuardDatabase:
|
|||||||
self._local.connection.row_factory = sqlite3.Row
|
self._local.connection.row_factory = sqlite3.Row
|
||||||
return self._local.connection
|
return self._local.connection
|
||||||
|
|
||||||
|
def _get_first_value(self, row):
|
||||||
|
"""Get first value from row, handling both dict and tuple types"""
|
||||||
|
if self.db_type == "postgresql":
|
||||||
|
# RealDictCursor returns dict-like objects
|
||||||
|
return list(row.values())[0] if row else None
|
||||||
|
else:
|
||||||
|
# SQLite returns tuples
|
||||||
|
return row[0] if row else None
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
"""Context manager for database connections"""
|
"""Context manager for database connections"""
|
||||||
@@ -141,7 +150,7 @@ class NFOGuardDatabase:
|
|||||||
dateadded TIMESTAMP,
|
dateadded TIMESTAMP,
|
||||||
source VARCHAR(100),
|
source VARCHAR(100),
|
||||||
last_updated TIMESTAMP NOT NULL,
|
last_updated TIMESTAMP NOT NULL,
|
||||||
has_video_file INTEGER DEFAULT 0
|
has_video_file BOOLEAN DEFAULT FALSE
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@@ -427,29 +436,33 @@ class NFOGuardDatabase:
|
|||||||
def get_stats(self) -> Dict[str, Any]:
|
def get_stats(self) -> Dict[str, Any]:
|
||||||
"""Get database statistics"""
|
"""Get database statistics"""
|
||||||
with self.get_connection() as conn:
|
with self.get_connection() as conn:
|
||||||
cursor = conn.cursor()
|
# Use regular cursor for simple COUNT queries (not RealDictCursor)
|
||||||
|
if self.db_type == "postgresql":
|
||||||
|
cursor = conn.cursor() # Regular cursor for PostgreSQL
|
||||||
|
else:
|
||||||
|
cursor = conn.cursor() # SQLite cursor
|
||||||
|
|
||||||
# Series stats
|
# Series stats
|
||||||
cursor.execute("SELECT COUNT(*) FROM series")
|
cursor.execute("SELECT COUNT(*) FROM series")
|
||||||
series_count = cursor.fetchone()[0]
|
series_count = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
# Episode stats
|
# Episode stats
|
||||||
cursor.execute("SELECT COUNT(*) FROM episodes")
|
cursor.execute("SELECT COUNT(*) FROM episodes")
|
||||||
episodes_total = cursor.fetchone()[0]
|
episodes_total = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
cursor.execute("SELECT COUNT(*) FROM episodes WHERE has_video_file = TRUE")
|
cursor.execute("SELECT COUNT(*) FROM episodes WHERE has_video_file = TRUE")
|
||||||
episodes_with_video = cursor.fetchone()[0]
|
episodes_with_video = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
# Movie stats
|
# Movie stats
|
||||||
cursor.execute("SELECT COUNT(*) FROM movies")
|
cursor.execute("SELECT COUNT(*) FROM movies")
|
||||||
movies_total = cursor.fetchone()[0]
|
movies_total = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
cursor.execute("SELECT COUNT(*) FROM movies WHERE has_video_file = TRUE")
|
cursor.execute("SELECT COUNT(*) FROM movies WHERE has_video_file = TRUE")
|
||||||
movies_with_video = cursor.fetchone()[0]
|
movies_with_video = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
# Processing history
|
# Processing history
|
||||||
cursor.execute("SELECT COUNT(*) FROM processing_history")
|
cursor.execute("SELECT COUNT(*) FROM processing_history")
|
||||||
history_count = cursor.fetchone()[0]
|
history_count = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"series_count": series_count,
|
"series_count": series_count,
|
||||||
|
|||||||
Reference in New Issue
Block a user