Skip to content

Commit

Permalink
database:base - add __enter__ and __exit__ methods to FileDBBase
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Nov 8, 2023
1 parent 7975549 commit 80d21b6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions acacore/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlite3 import Connection
from sqlite3 import Cursor as SQLiteCursor
from sqlite3 import OperationalError
from types import TracebackType
from typing import Any
from typing import Generator
from typing import Generic
Expand Down Expand Up @@ -780,6 +781,12 @@ def __init__(
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.path})"

def __enter__(self) -> "FileDBBase":
return self

def __exit__(self, _exc_type: Type[BaseException], _exc_val: BaseException, _exc_tb: TracebackType) -> None:
self.close()

@property
def path(self) -> Optional[Path]:
for _, name, filename in self.execute("PRAGMA database_list"):
Expand Down

0 comments on commit 80d21b6

Please sign in to comment.