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

 connection = sqlite3.connect(f"file:{sql_database}?mode=ro", uri=True)
 

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.connection = sqlite3.connect(f"file:{sql_database}?mode=ro", uri=True)
101

Member Function Documentation

◆ __str__()

ollama_manager.SQLQuery.__str__ ( self)

Definition at line 125 of file ollama_manager.py.

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

◆ run()

ollama_manager.SQLQuery.run ( self,
List[str] queries )
Executes the provided SQL queries and returns the results. Tests if the SQL queries are valid before execution.

Args:
    queries (List[str]): A list of SQL queries 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 and returns the results. Tests if the SQL queries are valid before execution.
106
107 Args:
108 queries (List[str]): A list of SQL queries to be executed.
109
110 Returns:
111 dict: A dictionary containing the results of the executed queries and the original queries.
112 """
113 results = []
114 for query in queries:
115 try:
116 print(f"query: {query}")
117 result = pd.read_sql(query, self.connection).to_json(orient="records")
118 results.append(result)
119 except ValueError as e:
120 logger.error(f"Error parsing SQL query: {e}")
121 return {"results": ["error"], "queries": queries}
122
123 return {"results": results, "queries": queries}
124

Member Data Documentation

◆ connection

ollama_manager.SQLQuery.connection = sqlite3.connect(f"file:{sql_database}?mode=ro", uri=True)

Definition at line 100 of file ollama_manager.py.


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