fix: SQLDatabase has no attribute set_event_manager (#4192)
This commit is contained in:
parent
10e1352ac4
commit
dd4a9f908c
1 changed files with 15 additions and 8 deletions
|
|
@ -2,26 +2,33 @@ from langchain_community.utilities.sql_database import SQLDatabase
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
|
|
||||||
from langflow.custom import CustomComponent
|
from langflow.custom import Component
|
||||||
|
from langflow.io import (
|
||||||
|
Output,
|
||||||
|
StrInput,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SQLDatabaseComponent(CustomComponent):
|
class SQLDatabaseComponent(Component):
|
||||||
display_name = "SQLDatabase"
|
display_name = "SQLDatabase"
|
||||||
description = "SQL Database"
|
description = "SQL Database"
|
||||||
name = "SQLDatabase"
|
name = "SQLDatabase"
|
||||||
|
|
||||||
def build_config(self):
|
inputs = [
|
||||||
return {
|
StrInput(name="uri", display_name="URI", info="URI to the database.", required=True),
|
||||||
"uri": {"display_name": "URI", "info": "URI to the database."},
|
]
|
||||||
}
|
|
||||||
|
outputs = [
|
||||||
|
Output(display_name="SQLDatabase", name="SQLDatabase", method="build_sqldatabase"),
|
||||||
|
]
|
||||||
|
|
||||||
def clean_up_uri(self, uri: str) -> str:
|
def clean_up_uri(self, uri: str) -> str:
|
||||||
if uri.startswith("postgres://"):
|
if uri.startswith("postgres://"):
|
||||||
uri = uri.replace("postgres://", "postgresql://")
|
uri = uri.replace("postgres://", "postgresql://")
|
||||||
return uri.strip()
|
return uri.strip()
|
||||||
|
|
||||||
def build(self, uri: str) -> SQLDatabase:
|
def build_sqldatabase(self) -> SQLDatabase:
|
||||||
uri = self.clean_up_uri(uri)
|
uri = self.clean_up_uri(self.uri)
|
||||||
# Create an engine using SQLAlchemy with StaticPool
|
# Create an engine using SQLAlchemy with StaticPool
|
||||||
engine = create_engine(uri, poolclass=StaticPool)
|
engine = create_engine(uri, poolclass=StaticPool)
|
||||||
return SQLDatabase(engine)
|
return SQLDatabase(engine)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue