Skip to content

Commit 0b446e2

Browse files
committed
Add context management capability to DBEngines
1 parent ae8fe90 commit 0b446e2

File tree

4 files changed

+666
-637
lines changed

4 files changed

+666
-637
lines changed

python/sedonadb/python/sedonadb/testing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ class DBEngine:
6363
of that name.
6464
"""
6565

66+
def close(self):
67+
"""Close the connection - base implementation does nothing"""
68+
pass
69+
70+
def __enter__(self):
71+
return self
72+
73+
def __exit__(self, exc_type, exc_val, exc_tb):
74+
self.close()
75+
return False
76+
6677
@classmethod
6778
def name(cls) -> str:
6879
"""This engine's name
@@ -399,6 +410,11 @@ def __init__(self, uri=None):
399410
uri = "postgresql://localhost:5432/postgres?user=postgres&password=password"
400411
self.con = adbc_driver_postgresql.dbapi.connect(uri)
401412

413+
def close(self):
414+
"""Close the connection"""
415+
if self.con:
416+
self.con.close()
417+
402418
@classmethod
403419
def name(cls):
404420
return "postgis"

0 commit comments

Comments
 (0)