mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 00:54:19 +01:00
Use connection::from_uri method in Python bindings
This commit is contained in:
@@ -300,29 +300,13 @@ impl Drop for Connection {
|
|||||||
#[allow(clippy::arc_with_non_send_sync)]
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
pub fn connect(path: &str) -> Result<Connection> {
|
pub fn connect(path: &str) -> Result<Connection> {
|
||||||
#[inline(always)]
|
match turso_core::Connection::from_uri(path) {
|
||||||
fn open_or(
|
Ok((io, conn)) => Ok(Connection { conn, io }),
|
||||||
io: Arc<dyn turso_core::IO>,
|
Err(e) => Err(PyErr::new::<ProgrammingError, _>(format!(
|
||||||
path: &str,
|
"Failed to create connection: {:?}",
|
||||||
) -> std::result::Result<Arc<turso_core::Database>, PyErr> {
|
e
|
||||||
turso_core::Database::open_file(io, path, false, false).map_err(|e| {
|
))
|
||||||
PyErr::new::<DatabaseError, _>(format!("Failed to open database: {:?}", e))
|
.into()),
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
match path {
|
|
||||||
":memory:" => {
|
|
||||||
let io: Arc<dyn turso_core::IO> = Arc::new(turso_core::MemoryIO::new());
|
|
||||||
let db = open_or(io.clone(), path)?;
|
|
||||||
let conn: Arc<turso_core::Connection> = db.connect().unwrap();
|
|
||||||
Ok(Connection { conn, io })
|
|
||||||
}
|
|
||||||
path => {
|
|
||||||
let io: Arc<dyn turso_core::IO> = Arc::new(turso_core::PlatformIO::new()?);
|
|
||||||
let db = open_or(io.clone(), path)?;
|
|
||||||
let conn: Arc<turso_core::Connection> = db.connect().unwrap();
|
|
||||||
Ok(Connection { conn, io })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user