mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 17:54:20 +01:00
ext/python: Gracefully close connection by closing it at Drop
This commit is contained in:
@@ -193,9 +193,9 @@ impl Cursor {
|
||||
}
|
||||
|
||||
pub fn close(&self) -> PyResult<()> {
|
||||
Err(PyErr::new::<NotSupportedError, _>(
|
||||
"close() is not supported in this version",
|
||||
))
|
||||
self.conn.close()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[pyo3(signature = (sql, parameters=None))]
|
||||
@@ -244,8 +244,12 @@ impl Connection {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn close(&self) {
|
||||
drop(self.conn.clone());
|
||||
pub fn close(&self) -> PyResult<()> {
|
||||
self.conn.close().map_err(|e| {
|
||||
PyErr::new::<OperationalError, _>(format!("Failed to close connection: {:?}", e))
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn commit(&self) -> PyResult<()> {
|
||||
@@ -281,6 +285,14 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Connection {
|
||||
fn drop(&mut self) {
|
||||
self.conn
|
||||
.close()
|
||||
.expect("Failed to drop (close) connection");
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
#[pyfunction]
|
||||
pub fn connect(path: &str) -> Result<Connection> {
|
||||
|
||||
Reference in New Issue
Block a user