Sinaptik-AI / pandas-ai

Chat with your database (SQL, CSV, pandas, polars, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
https://pandas-ai.com
Other
12.51k stars 1.21k forks source link

Add support for oracledb driver #1293

Open desertproject opened 1 month ago

desertproject commented 1 month ago

🚀 The feature

Add support for the oracledb driver in the OracleConnector. Allow users to choose between cx_oracle and oracledb as options.

Motivation, pitch

cx_Oracle advises new projects to use oracledb instead.

Alternatives

Patch connectors/sql.py to

--- /dev/null
+++ .venv/lib/python3.11/site-packages/pandasai/connectors/sql.py   2024-07-25 17:09:00.902774420 -0300
@@ -673,7 +673,8 @@
             config (ConnectorConfig): The configuration for the Oracle connector.
         """
         config["dialect"] = "oracle"
-        config["driver"] = "cx_oracle"
+        if config.get("driver") is None:
+            config["driver"] = "cx_oracle"

         if isinstance(config, dict):
             oracle_env_vars = {
@@ -711,4 +712,7 @@

     @property
     def cs_table_name(self):
-        return f'"{self.config.table}"'
+        if self.config.driver == "cx_oracle":
+            return f'"{self.config.table}"'
+        else:
+            return self.config.table

Specify the driver as oracledb

oracle_connector = OracleConnector(
    config={
        "driver": "oracledb",
        ...

Additional context

Support for oracledb is available only in SQLAlchemy versions 2.0 and later, so this dependency needs to be updated as well.

Since sqlalchemy-databricks 0.2.0 requires SQLAlchemy<2, consider addressing #1292 first.

cjbj commented 1 month ago