Skip to content

Commit

Permalink
refactor(sqlalchemy): remove unnecessary _AutoCloseCursor #2947
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul Pwanson authored and cpcloud committed Jan 19, 2022
1 parent 050ecf3 commit c868783
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions ibis/backends/base/sql/alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,6 @@
)


class _AutoCloseCursor:
"""
Wraps a SQLAlchemy ResultProxy and ensures that .close() is called on
garbage collection
"""

def __init__(self, original_cursor):
self.original_cursor = original_cursor

def __del__(self):
self.original_cursor.close()

def __enter__(self):
return self

def __exit__(self, type, value, tb):
self.original_cursor.close()

def fetchall(self):
return self.original_cursor.fetchall()


class BaseAlchemyBackend(BaseSQLBackend):
"""
Base backend class for backends that compile to SQL with SQLAlchemy.
Expand Down Expand Up @@ -151,8 +129,8 @@ def to_shapely(row, name):

def fetch_from_cursor(self, cursor, schema):
df = pd.DataFrame.from_records(
cursor.original_cursor.fetchall(),
columns=cursor.original_cursor.keys(),
cursor.fetchall(),
columns=cursor.keys(),
coerce_float=True,
)
df = schema.apply_to(df)
Expand Down Expand Up @@ -326,9 +304,6 @@ def current_database(self):
def list_schemas(self):
return self.list_databases()

def raw_sql(self, query: str, results=False):
return _AutoCloseCursor(super().raw_sql(query))

def _log(self, sql):
try:
query_str = str(sql)
Expand Down

0 comments on commit c868783

Please sign in to comment.