diff --git a/docs/api.md b/docs/api.md index 7937c5c..c760ca1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -123,7 +123,7 @@ Unimplemented. ### autocommit -Unimplemented. +The driver only supports the legacy `isolation_level`-based transaction mode control and does not implement the `autocommit` property yet (see issue [#30](https://github.com/libsql/libsql-experimental-python/issues/30) for details). ### in_transaction @@ -131,7 +131,7 @@ Returns `True` if there's an active transaction with uncommitted changes; otherw ### isolation_level -Unimplemented. +Transaction handling mode configuration. If `isolation_level` is set to `"DEFERRED"`, `"IMMEDIATE"`, or `"EXCLUSIVE"`, transactions begin implicitly, but need to be committed manually. If `isolation_level` is set to `None`, then database is in auto-commit mode, executing each statement in its own transaction. ### row_factory diff --git a/src/lib.rs b/src/lib.rs index 6dcf5c5..4c4729a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,10 +19,10 @@ fn is_remote_path(path: &str) -> bool { } #[pyfunction] -#[pyo3(signature = (database, isolation_level="DEFERRED", check_same_thread=true, uri=false, sync_url=None, auth_token=""))] +#[pyo3(signature = (database, isolation_level="DEFERRED".to_string(), check_same_thread=true, uri=false, sync_url=None, auth_token=""))] fn connect( database: String, - isolation_level: Option<&str>, + isolation_level: Option, check_same_thread: bool, uri: bool, sync_url: Option, @@ -56,6 +56,7 @@ fn connect( db, conn, rt, + isolation_level, autocommit, }) } @@ -65,6 +66,7 @@ pub struct Connection { db: libsql_core::Database, conn: Arc, rt: tokio::runtime::Runtime, + isolation_level: Option, autocommit: bool, } @@ -139,6 +141,11 @@ impl Connection { Ok(cursor) } + #[getter] + fn isolation_level(self_: PyRef<'_, Self>) -> Option { + self_.isolation_level.clone() + } + #[getter] fn in_transaction(self_: PyRef<'_, Self>) -> PyResult { Ok(!self_.conn.is_autocommit()) diff --git a/tests/test_suite.py b/tests/test_suite.py index 415352d..64f0cae 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -116,6 +116,7 @@ def test_commit_and_rollback(provider): @pytest.mark.parametrize("provider", ["libsql", "sqlite"]) def test_autocommit(provider): conn = connect(provider, ":memory:", None) + assert conn.isolation_level == None assert conn.in_transaction == False cur = conn.cursor() assert conn.in_transaction == False