@@ -132,6 +132,11 @@ def _query(self, sql_code: str) -> list:
132
132
"Send query to database and return result"
133
133
...
134
134
135
+ @abstractmethod
136
+ def close (self ):
137
+ """Close a connection"""
138
+ ...
139
+
135
140
136
141
class ThreadedDatabase (Database ):
137
142
"""Access the database through singleton threads.
@@ -213,6 +218,9 @@ def _query(self, sql_code: str) -> list:
213
218
"Uses the standard SQL cursor interface"
214
219
return _query_conn (self ._conn , sql_code )
215
220
221
+ def close (self ):
222
+ self ._conn .close ()
223
+
216
224
217
225
class MySQL (ThreadedDatabase ):
218
226
def __init__ (self , host , port , database , user , password , * , thread_count ):
@@ -333,6 +341,9 @@ def _query(self, sql_code: str):
333
341
def to_string (self , s : str ):
334
342
return f"cast({ s } as string)"
335
343
344
+ def close (self ):
345
+ self ._client .close ()
346
+
336
347
337
348
class Snowflake (Database ):
338
349
def __init__ (
@@ -377,6 +388,9 @@ def md5_to_int(self, s: str) -> str:
377
388
def to_string (self , s : str ):
378
389
return f"cast({ s } as string)"
379
390
391
+ def close (self ):
392
+ self ._conn .close ()
393
+
380
394
381
395
class Databricks (Database ):
382
396
def __init__ (
@@ -404,6 +418,9 @@ def md5_to_int(self, s: str) -> str:
404
418
def to_string (self , s : str ) -> str :
405
419
return f"cast({ s } as string)"
406
420
421
+ def close (self ):
422
+ self ._conn .close ()
423
+
407
424
408
425
def connect_to_uri (db_uri : str , thread_count : Optional [int ] = 1 ) -> Database :
409
426
"""Connect to the given database uri
0 commit comments