Delete sqlite_functions.py
Browse files- sqlite_functions.py +0 -35
sqlite_functions.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
from typing import List
|
| 2 |
-
from haystack import component
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import sqlite3
|
| 5 |
-
|
| 6 |
-
@component
|
| 7 |
-
class SQLiteQuery:
|
| 8 |
-
|
| 9 |
-
def __init__(self, sql_database: str):
|
| 10 |
-
self.connection = sqlite3.connect(sql_database, check_same_thread=False)
|
| 11 |
-
|
| 12 |
-
@component.output_types(results=List[str], queries=List[str])
|
| 13 |
-
def run(self, queries: List[str]):
|
| 14 |
-
print("ATTEMPTING TO RUN QUERY")
|
| 15 |
-
results = []
|
| 16 |
-
for query in queries:
|
| 17 |
-
result = pd.read_sql(query, self.connection)
|
| 18 |
-
results.append(f"{result}")
|
| 19 |
-
"self.connection.close()"
|
| 20 |
-
return {"results": results, "queries": queries}
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
sql_query = SQLiteQuery('data_source.db')
|
| 24 |
-
|
| 25 |
-
def sqlite_query_func(queries: List[str]):
|
| 26 |
-
try:
|
| 27 |
-
result = sql_query.run(queries)
|
| 28 |
-
return {"reply": result["results"][0]}
|
| 29 |
-
|
| 30 |
-
except Exception as e:
|
| 31 |
-
reply = f"""There was an error running the SQL Query = {queries}
|
| 32 |
-
The error is {e},
|
| 33 |
-
You should probably try again.
|
| 34 |
-
"""
|
| 35 |
-
return {"reply": reply}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|