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:
parent
4f9e2705d8
commit
ff37170693
2 changed files with 9 additions and 6 deletions
|
|
@ -16,10 +16,13 @@ if TYPE_CHECKING:
|
||||||
class SQLComponent(ComponentWithCache):
|
class SQLComponent(ComponentWithCache):
|
||||||
"""A sql component."""
|
"""A sql component."""
|
||||||
|
|
||||||
display_name = "SQL Query"
|
display_name = "SQL Database"
|
||||||
description = "Execute SQL Query"
|
description = (
|
||||||
|
"Executes SQL queries on any SQLAlchemy-compatible database and returns the result as a structured dataframe."
|
||||||
|
)
|
||||||
icon = "database"
|
icon = "database"
|
||||||
name = "SQLComponent"
|
name = "SQLComponent"
|
||||||
|
metadata = {"keywords": ["sql", "database", "query", "db", "fetch"]}
|
||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
def __init__(self, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
@ -54,7 +57,7 @@ class SQLComponent(ComponentWithCache):
|
||||||
]
|
]
|
||||||
|
|
||||||
outputs = [
|
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(
|
def build_component(
|
||||||
|
|
@ -90,7 +93,7 @@ class SQLComponent(ComponentWithCache):
|
||||||
self.log(msg)
|
self.log(msg)
|
||||||
raise ValueError(msg) from e
|
raise ValueError(msg) from e
|
||||||
|
|
||||||
def sql_query_results(self) -> DataFrame:
|
def run_sql_query(self) -> DataFrame:
|
||||||
result = self.__execute_query()
|
result = self.__execute_query()
|
||||||
df_result = DataFrame(result)
|
df_result = DataFrame(result)
|
||||||
self.status = df_result
|
self.status = df_result
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ class TestSQLComponent(ComponentTestBaseWithoutClient):
|
||||||
assert "Error:" in result.text
|
assert "Error:" in result.text
|
||||||
assert "Query: SELECT * FROM non_existent_table" 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."""
|
"""Test building a DataFrame from a SQL query."""
|
||||||
component = component_class(**default_kwargs)
|
component = component_class(**default_kwargs)
|
||||||
|
|
||||||
result = component.sql_query_results()
|
result = component.run_sql_query()
|
||||||
|
|
||||||
assert isinstance(result, DataFrame)
|
assert isinstance(result, DataFrame)
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue