Skip to content

Conversation

risyou
Copy link
Contributor

@risyou risyou commented Apr 25, 2025

add keep-connection option for create TEMP object

Ref: #23

@ktanaka101 ktanaka101 self-requested a review April 26, 2025 09:36
Copy link
Owner

@ktanaka101 ktanaka101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—code looks good overall! 👍
Could you add a small regression test for keep_connection before we merge?

Something like:

def test_temp_table_persists_with_keep_connection():
    with tempfile.TemporaryDirectory() as tmpdir:
        cfg = Config(db_path=tmp_path / "test.db", keep_connection=True)
        db = DuckDBDatabase(cfg)

        db.execute_query("CREATE TEMP TABLE t AS SELECT 1 AS v")
        assert db.execute_query("SELECT v FROM t") == [(1,)]

def test_temp_table_does_not_persist_without_keep_connection():
    with tempfile.TemporaryDirectory() as tmpdir:
        cfg = Config(db_path=tmp_path / "test.db", keep_connection=False)
        db = DuckDBDatabase(cfg)

        db.execute_query("CREATE TEMP TABLE t AS SELECT 1 AS v")
        with pytest.raises(duckdb.Error):
            db.execute_query("SELECT v FROM t")

(No need for full fixtures—just something that covers both code paths.)

@@ -34,13 +34,35 @@ def __init__(self, config: Config):
duckdb.connect(config.db_path).close()

self.db_path = config.db_path
self._connection = None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._connection = None
self._connection: duckdb.DuckDBPyConnection | None = None

@ktanaka101
Copy link
Owner

Merged as some time has passed. If you have additional feedback, please open an issue.

@ktanaka101 ktanaka101 merged commit e49c354 into ktanaka101:main May 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants