ThalamOS
a powerful Flask web application designed to enhance your storage management.
Loading...
Searching...
No Matches
ollama_manager.SQLQuery Class Reference

Public Member Functions

 __init__ (self, str sql_database)
 
 run (self, List[str] queries)
 
 __str__ (self)
 

Public Attributes

 engine = create_engine(f"sqlite:///{os.path.abspath(sql_database)}")
 

Detailed Description

A component to execute SQL queries on the SQLite database.

Attributes:
    connection (sqlite3.Connection): The connection to the SQLite database.

Methods:
    run(queries: List[str]) -> dict: Executes the provided SQL queries and returns the results.

Definition at line 88 of file ollama_manager.py.

Constructor & Destructor Documentation

◆ __init__()

ollama_manager.SQLQuery.__init__ ( self,
str sql_database )

Definition at line 99 of file ollama_manager.py.

99 def __init__(self, sql_database: str):
100 self.engine = create_engine(f"sqlite:///{os.path.abspath(sql_database)}")
101

Member Function Documentation

◆ __str__()

ollama_manager.SQLQuery.__str__ ( self)

Definition at line 124 of file ollama_manager.py.

124 def __str__(self):
125 return "<SQLQuery Object>"
126
127

◆ run()

ollama_manager.SQLQuery.run ( self,
List[str] queries )
Executes the provided SQL queries on the SQLite database and returns the results.
Args:
    queries (List[str]): A list of SQL query strings to be executed.
Returns:
    dict: A dictionary containing the results of the executed queries and the original queries.

Definition at line 103 of file ollama_manager.py.

103 def run(self, queries: List[str]):
104 """
105 Executes the provided SQL queries on the SQLite database and returns the results.
106 Args:
107 queries (List[str]): A list of SQL query strings to be executed.
108 Returns:
109 dict: A dictionary containing the results of the executed queries and the original queries.
110 """
111 results = []
112 for query in queries:
113 try:
114 # pandas kann direkt mit der SQLAlchemy-Engine arbeiten
115 df = pd.read_sql(query, self.engine)
116 result = df.to_json(orient="records")
117 results.append(result)
118 except Exception as e:
119 logger.error(f"Error executing SQL query: {e}")
120 return {"results": ["error"], "queries": queries}
121
122 return {"results": results, "queries": queries}
123

Member Data Documentation

◆ engine

ollama_manager.SQLQuery.engine = create_engine(f"sqlite:///{os.path.abspath(sql_database)}")

Definition at line 100 of file ollama_manager.py.


The documentation for this class was generated from the following file: