Refactor project structure and update README; remove unused dependencies from requirements.txt and enhance database management in sql_commands.py.

This commit is contained in:
2026-05-31 12:56:55 +00:00
parent 5fdb37f7f8
commit 3e6410d112
4 changed files with 107 additions and 106 deletions
+13 -18
View File
@@ -7,7 +7,6 @@ import re
import time
from datetime import datetime, timedelta
import logging
import pandas as pd
# Configure logging
@@ -45,8 +44,9 @@ class DatabaseManager:
"user": os.getenv("SQLUSER", "root"),
"password": os.getenv("SQLPASS", ""),
"database": os.getenv("SQLDB", "testdb"),
"pool_reset_session": os.getenv("POOL_RESET_SESSION", "false").lower()
in ("true", "1", "yes"),
"pool_reset_session": self._parse_bool(
os.getenv("POOL_RESET_SESSION", "false")
),
}
self.pool = pooling.MySQLConnectionPool(
@@ -234,6 +234,10 @@ class DatabaseManager:
raise ValueError(f"Invalid SQL identifier: {identifier}")
return identifier
@staticmethod
def _parse_bool(value: str) -> bool:
return str(value).strip().lower() in {"true", "1", "yes", "y"}
def _parse_insert_columns(self, query: str) -> list[str]:
match = re.search(
r"INSERT\s+INTO\s+\S+\s*\(([^)]+)\)\s*VALUES",
@@ -365,22 +369,13 @@ class DatabaseManager:
connection.close()
def fetch_as_dataframe(self, query, params=None):
connection = None
cursor = None
results = self.fetch_all(query, params)
try:
connection = self.get_connection()
cursor = connection.cursor(dictionary=True, buffered=True)
cursor.execute(query, params or ())
if cursor.with_rows:
results = cursor.fetchall()
return pd.DataFrame(results) if results else pd.DataFrame()
logger.warning("No result set to fetch from.")
return pd.DataFrame()
finally:
if cursor:
cursor.close()
if connection:
connection.close()
import pandas as pd
except ImportError as err:
logger.error("Pandas is not installed; fetch_as_dataframe cannot return a DataFrame.")
raise
return pd.DataFrame(results)
def create_table_if_not_exists(self, table_name, schema):
table_name = self._sanitize_identifier(table_name)