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.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"
|
||||
description = "SQL Database"
|
||||
name = "SQLDatabase"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"uri": {"display_name": "URI", "info": "URI to the database."},
|
||||
}
|
||||
inputs = [
|
||||
StrInput(name="uri", display_name="URI", info="URI to the database.", required=True),
|
||||
]
|
||||
|
||||
outputs = [
|
||||
Output(display_name="SQLDatabase", name="SQLDatabase", method="build_sqldatabase"),
|
||||
]
|
||||
|
||||
def clean_up_uri(self, uri: str) -> str:
|
||||
if uri.startswith("postgres://"):
|
||||
uri = uri.replace("postgres://", "postgresql://")
|
||||
return uri.strip()
|
||||
|
||||
def build(self, uri: str) -> SQLDatabase:
|
||||
uri = self.clean_up_uri(uri)
|
||||
def build_sqldatabase(self) -> SQLDatabase:
|
||||
uri = self.clean_up_uri(self.uri)
|
||||
# Create an engine using SQLAlchemy with StaticPool
|
||||
engine = create_engine(uri, poolclass=StaticPool)
|
||||
return SQLDatabase(engine)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue