betodealmeida / shillelagh

Making it easy to query APIs via SQL
MIT License
374 stars 50 forks source link

Add import_dbapi() to mimic dbapi() to prevent SADeprecationWarning #452

Closed RyanJulyan closed 1 month ago

RyanJulyan commented 2 months ago

Summary

prevent SADeprecationWarning: Add import_dbapi() to mimic dbapi() to prevent SADeprecationWarning

Testing instructions

What steps can be taken to manually verify the changes?

Install latest SQLAlchemy pip install sqlalchemy run the following code:

from sqlalchemy import create_engine, text

# Create the engine
engine = create_engine(
    "shillelagh://",
    adapters=["csvfile"]
)

# Connect to the engine
connection = engine.connect()

# Correct file path
csv_file_path = "C:/Users/<user_name>/adaptor_test/test.csv"
query = text(f"SELECT * FROM '{csv_file_path}'")

try:
    # Execute the query and fetch results
    result = connection.execute(query)

    # Print the results
    for row in result:
        print(row)
except Exception as e:
    print(f"Error: {e}")

and observe warning:

SADeprecationWarning: The dbapi() classmethod on dialect classes has been renamed to import_dbapi().  Implement an import_dbapi() classmethod directly on class <class 'shillelagh.backends.apsw.dialects.base.APSWDialect'> to remove this warning; the old .dbapi() classmethod may be maintained for backwards compatibility.
  engine = create_engine(

apply fix in PR and the warning is gone.

betodealmeida commented 1 month ago

Thanks, @RyanJulyan!