Spaces:
Runtime error
Runtime error
Update app.py
Browse files67 unmodified lines686970717172737475763 unmodified lines8081828183848530 unmodified lines11611711811912012112212312412512612712812967 unmodified lines@app.post("/api/connect")async def connect_to_database(connection: DatabaseConnection): try: print(f"Attempting to connect to database: {connection.database_type}") if connection.database_type == "postgres": if connection.database_type == "Postgres": print(f"PostgreSQL connection details - Host: {connection.server}, Port: {connection.port}, Database: {connection.databaseName}, User: {connection.username}") conn = psycopg2.connect( host=connection.server, port=connection.port,3 unmodified lines ) query_schemas = "SELECT schema_name FROM information_schema.schemata" query_tables = "SELECT table_name FROM information_schema.tables WHERE table_schema = %s" print(query_tables) elif connection.database_type == "mysql": print(f"inside mysql",connection.server,connection.port,connection.databaseName,connection.username,connection.password) conn = mysql.connector.connect(30 unmodified lines raise HTTPException(status_code=500, detail=str(e))
# Function to create a new database connection for MySQL (Example)def get_db_connection(): try: cnx = mysql.connector.connect(user=DB_USER, password=DB_PASSWORD, host=DB_HOST, database=DB_NAME) return cnx except mysql.connector.Error as err: logging.error(f"Database connection error: {err}") return None# Function to create a new database connection for MySQL (Example)def get_db_connection(): try: cnx = mysql.connector.connect(user=DB_USER, password=DB_PASSWORD, host=DB_HOST, database=DB_NAME)app.py+11-2