diff --git a/api/web_routes.py b/api/web_routes.py index 43697a7..d622473 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -204,7 +204,11 @@ async def get_series_sources(dependencies: dict): 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} diff --git a/core/database.py b/core/database.py index a39dd62..304b606 100644 --- a/core/database.py +++ b/core/database.py @@ -79,6 +79,15 @@ class NFOGuardDatabase: self._local.connection.row_factory = sqlite3.Row 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 def get_connection(self): """Context manager for database connections""" @@ -141,7 +150,7 @@ class NFOGuardDatabase: dateadded TIMESTAMP, source VARCHAR(100), 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]: """Get database statistics""" 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 cursor.execute("SELECT COUNT(*) FROM series") - series_count = cursor.fetchone()[0] + series_count = self._get_first_value(cursor.fetchone()) # Episode stats 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") - episodes_with_video = cursor.fetchone()[0] + episodes_with_video = self._get_first_value(cursor.fetchone()) # Movie stats 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") - movies_with_video = cursor.fetchone()[0] + movies_with_video = self._get_first_value(cursor.fetchone()) # Processing history cursor.execute("SELECT COUNT(*) FROM processing_history") - history_count = cursor.fetchone()[0] + history_count = self._get_first_value(cursor.fetchone()) return { "series_count": series_count,