Add ability to save and edit queries, still need to add ability to edit queries

This commit is contained in:
Peter Stockings
2024-11-08 23:09:19 +11:00
parent 90cb1c1451
commit 23def088bb
4 changed files with 175 additions and 10 deletions

View File

@@ -107,5 +107,31 @@ class SQLExplorer:
error = str(e)
return (results, columns, error)
def save_query(self, title, query):
error = None
if not title:
return "Must provide title"
try:
self.execute("""
INSERT INTO saved_query (title, query)
VALUES (%s, %s)""",[title, query], commit=True)
except Exception as e:
error = str(e)
return error
def list_saved_queries(self):
queries = self.execute("SELECT id, title, query FROM saved_query")
return queries
def get_saved_query(self, query_id):
result = self.execute("SELECT title, query FROM saved_query where id=%s", [query_id], one=True)
return (result['title'], result['query'])
def delete_saved_query(self, query_id):
self.execute("DELETE FROM saved_query where id=%s", [query_id], commit=True)