ref: SQL component (#8185)

* update sql

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Edwin Jose 2025-05-22 15:47:14 -04:00 committed by GitHub
commit ff37170693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -16,10 +16,13 @@ if TYPE_CHECKING:
class SQLComponent(ComponentWithCache):
"""A sql component."""
display_name = "SQL Query"
description = "Execute SQL Query"
display_name = "SQL Database"
description = (
"Executes SQL queries on any SQLAlchemy-compatible database and returns the result as a structured dataframe."
)
icon = "database"
name = "SQLComponent"
metadata = {"keywords": ["sql", "database", "query", "db", "fetch"]}
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
@ -54,7 +57,7 @@ class SQLComponent(ComponentWithCache):
]
outputs = [
Output(display_name="Query Results", name="sql_query_results", method="sql_query_results"),
Output(display_name="Result Table", name="run_sql_query", method="run_sql_query"),
]
def build_component(
@ -90,7 +93,7 @@ class SQLComponent(ComponentWithCache):
self.log(msg)
raise ValueError(msg) from e
def sql_query_results(self) -> DataFrame:
def run_sql_query(self) -> DataFrame:
result = self.__execute_query()
df_result = DataFrame(result)
self.status = df_result

View file

@ -89,11 +89,11 @@ class TestSQLComponent(ComponentTestBaseWithoutClient):
assert "Error:" in result.text
assert "Query: SELECT * FROM non_existent_table" in result.text
def test_sql_query_results(self, component_class: type[SQLComponent], default_kwargs):
def test_run_sql_query(self, component_class: type[SQLComponent], default_kwargs):
"""Test building a DataFrame from a SQL query."""
component = component_class(**default_kwargs)
result = component.sql_query_results()
result = component.run_sql_query()
assert isinstance(result, DataFrame)
assert len(result) == 1