Skip to content

Commit a939488

Browse files
committed
Add __fspath__ method to SimpleSQLite class: #86
Signed-off-by: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
1 parent 5439b5d commit a939488

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

simplesqlite/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ def __enter__(self): # type: ignore
198198
def __exit__(self, exc_type, exc_value, traceback) -> None: # type: ignore
199199
self.close()
200200

201+
def __fspath__(self) -> str:
202+
if not self.database_path:
203+
raise ValueError("database is not connected")
204+
205+
if self.database_path == MEMORY_DB_NAME:
206+
raise ValueError("database is in-memory")
207+
208+
return self.database_path
209+
201210
def is_connected(self) -> bool:
202211
"""
203212
:return: |True| if the connection to a database is valid.

0 commit comments

Comments
 (0)