Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit b184294

Browse files
committed
Add a close method for Snowflake, Databricks, Presto and BigQuery classes
1 parent a148428 commit b184294

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

data_diff/database.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ def _query(self, sql_code: str) -> list:
132132
"Send query to database and return result"
133133
...
134134

135+
@abstractmethod
136+
def close(self):
137+
"""Close a connection"""
138+
...
139+
135140

136141
class ThreadedDatabase(Database):
137142
"""Access the database through singleton threads.
@@ -213,6 +218,9 @@ def _query(self, sql_code: str) -> list:
213218
"Uses the standard SQL cursor interface"
214219
return _query_conn(self._conn, sql_code)
215220

221+
def close(self):
222+
self._conn.close()
223+
216224

217225
class MySQL(ThreadedDatabase):
218226
def __init__(self, host, port, database, user, password, *, thread_count):
@@ -333,6 +341,9 @@ def _query(self, sql_code: str):
333341
def to_string(self, s: str):
334342
return f"cast({s} as string)"
335343

344+
def close(self):
345+
self._client.close()
346+
336347

337348
class Snowflake(Database):
338349
def __init__(
@@ -377,6 +388,9 @@ def md5_to_int(self, s: str) -> str:
377388
def to_string(self, s: str):
378389
return f"cast({s} as string)"
379390

391+
def close(self):
392+
self._conn.close()
393+
380394

381395
class Databricks(Database):
382396
def __init__(
@@ -404,6 +418,9 @@ def md5_to_int(self, s: str) -> str:
404418
def to_string(self, s: str) -> str:
405419
return f"cast({s} as string)"
406420

421+
def close(self):
422+
self._conn.close()
423+
407424

408425
def connect_to_uri(db_uri: str, thread_count: Optional[int] = 1) -> Database:
409426
"""Connect to the given database uri

0 commit comments

Comments
 (0)