Skip to content

Commit e51c49d

Browse files
committed
Implement Connection.isolation_level
1 parent 750ffe0 commit e51c49d

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ Unimplemented.
123123

124124
### autocommit
125125

126-
Unimplemented.
126+
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).
127127

128128
### in_transaction
129129

130130
Returns `True` if there's an active transaction with uncommitted changes; otherwise returns `False`.
131131

132132
### isolation_level
133133

134-
Unimplemented.
134+
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.
135135

136136
### row_factory
137137

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ fn is_remote_path(path: &str) -> bool {
1919
}
2020

2121
#[pyfunction]
22-
#[pyo3(signature = (database, isolation_level="DEFERRED", check_same_thread=true, uri=false, sync_url=None, auth_token=""))]
22+
#[pyo3(signature = (database, isolation_level="DEFERRED".to_string(), check_same_thread=true, uri=false, sync_url=None, auth_token=""))]
2323
fn connect(
2424
database: String,
25-
isolation_level: Option<&str>,
25+
isolation_level: Option<String>,
2626
check_same_thread: bool,
2727
uri: bool,
2828
sync_url: Option<String>,
@@ -56,6 +56,7 @@ fn connect(
5656
db,
5757
conn,
5858
rt,
59+
isolation_level,
5960
autocommit,
6061
})
6162
}
@@ -65,6 +66,7 @@ pub struct Connection {
6566
db: libsql_core::Database,
6667
conn: Arc<libsql_core::Connection>,
6768
rt: tokio::runtime::Runtime,
69+
isolation_level: Option<String>,
6870
autocommit: bool,
6971
}
7072

@@ -139,6 +141,11 @@ impl Connection {
139141
Ok(cursor)
140142
}
141143

144+
#[getter]
145+
fn isolation_level(self_: PyRef<'_, Self>) -> Option<String> {
146+
self_.isolation_level.clone()
147+
}
148+
142149
#[getter]
143150
fn in_transaction(self_: PyRef<'_, Self>) -> PyResult<bool> {
144151
Ok(!self_.conn.is_autocommit())

tests/test_suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_commit_and_rollback(provider):
116116
@pytest.mark.parametrize("provider", ["libsql", "sqlite"])
117117
def test_autocommit(provider):
118118
conn = connect(provider, ":memory:", None)
119+
assert conn.isolation_level == None
119120
assert conn.in_transaction == False
120121
cur = conn.cursor()
121122
assert conn.in_transaction == False

0 commit comments

Comments
 (0)