diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 84d94030d..e25508ddf 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -300,29 +300,13 @@ impl Drop for Connection { #[allow(clippy::arc_with_non_send_sync)] #[pyfunction] pub fn connect(path: &str) -> Result { - #[inline(always)] - fn open_or( - io: Arc, - path: &str, - ) -> std::result::Result, PyErr> { - turso_core::Database::open_file(io, path, false, false).map_err(|e| { - PyErr::new::(format!("Failed to open database: {:?}", e)) - }) - } - - match path { - ":memory:" => { - let io: Arc = Arc::new(turso_core::MemoryIO::new()); - let db = open_or(io.clone(), path)?; - let conn: Arc = db.connect().unwrap(); - Ok(Connection { conn, io }) - } - path => { - let io: Arc = Arc::new(turso_core::PlatformIO::new()?); - let db = open_or(io.clone(), path)?; - let conn: Arc = db.connect().unwrap(); - Ok(Connection { conn, io }) - } + match turso_core::Connection::from_uri(path) { + Ok((io, conn)) => Ok(Connection { conn, io }), + Err(e) => Err(PyErr::new::(format!( + "Failed to create connection: {:?}", + e + )) + .into()), } }