Skip to content

Commit

Permalink
Refactor drop_database and drop_table functions to use the correct en…
Browse files Browse the repository at this point in the history
…gine variable
  • Loading branch information
RichieHakim committed Apr 1, 2024
1 parent 42e6d41 commit 11f7a02
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bnpm/sql_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ def drop_database(
Additional keyword arguments to be passed to sqlalchemy.create_engine
"""
engine = sqlalchemy.create_engine(url, **kwargs_connection)
if "mysql" in str(connection.engine):
if "mysql" in str(engine):
query = f"DROP DATABASE {database}"
elif "postgresql" in str(connection.engine):
elif "postgresql" in str(engine):
query = f"DROP DATABASE {database}"
elif "sqlite" in str(connection.engine):
elif "sqlite" in str(engine):
raise ValueError("SQLite does not support this operation")
else:
raise ValueError("Connection type not recognized")
Expand Down Expand Up @@ -421,16 +421,16 @@ def drop_table(
"""
engine = sqlalchemy.create_engine(url, **kwargs_connection)
if isinstance(connection, sqlalchemy.engine.base.Connection):
if "mysql" in str(connection.engine):
if "mysql" in str(engine):
if database is None:
raise ValueError("database must be specified for MySQL")
query = f"DROP TABLE {database}.{table}"
elif "postgresql" in str(connection.engine):
elif "postgresql" in str(engine):
if database is None:
query = f"DROP TABLE {table}"
else:
query = f"DROP TABLE {database}.{table}"
elif "sqlite" in str(connection.engine):
elif "sqlite" in str(engine):
if database is not None:
raise ValueError("database must be None for SQLite")
query = f"DROP TABLE {table}"
Expand Down

0 comments on commit 11f7a02

Please sign in to comment.