From bbee10ba2c453831a81f729a1c053e30934f5cda Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 30 Jun 2025 22:00:09 -0400 Subject: [PATCH] Add mvcc and index config to connection open api --- bindings/go/rs_src/lib.rs | 2 +- bindings/python/src/lib.rs | 2 +- cli/app.rs | 13 +++++++++---- core/lib.rs | 14 ++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bindings/go/rs_src/lib.rs b/bindings/go/rs_src/lib.rs index 9029a6966..5d396b4e3 100644 --- a/bindings/go/rs_src/lib.rs +++ b/bindings/go/rs_src/lib.rs @@ -20,7 +20,7 @@ pub unsafe extern "C" fn db_open(path: *const c_char) -> *mut c_void { } let path = unsafe { std::ffi::CStr::from_ptr(path) }; let path = path.to_str().unwrap(); - let Ok((io, conn)) = Connection::from_uri(path) else { + let Ok((io, conn)) = Connection::from_uri(path, false, false) else { panic!("Failed to open connection with path: {}", path); }; LimboConn::new(conn, io).to_ptr() diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index e25508ddf..8a57b6726 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -300,7 +300,7 @@ impl Drop for Connection { #[allow(clippy::arc_with_non_send_sync)] #[pyfunction] pub fn connect(path: &str) -> Result { - match turso_core::Connection::from_uri(path) { + match turso_core::Connection::from_uri(path, false, false) { Ok((io, conn)) => Ok(Connection { conn, io }), Err(e) => Err(PyErr::new::(format!( "Failed to create connection: {:?}", diff --git a/cli/app.rs b/cli/app.rs index 654d266cc..a42877bd4 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -116,16 +116,21 @@ impl Limbo { .database .as_ref() .map_or(":memory:".to_string(), |p| p.to_string_lossy().to_string()); - let (io, conn) = if db_file.contains(['?', '&', '#']) { - // likely a URI - Connection::from_uri(&db_file)? + let (io, conn) = if db_file.contains([':', '?', '&', '#']) { + Connection::from_uri(&db_file, opts.experimental_indexes, opts.experimental_mvcc)? } else { let flags = if opts.readonly { OpenFlags::ReadOnly } else { OpenFlags::default() }; - let (io, db) = Database::open_new(&db_file, opts.vfs.as_ref(), flags)?; + let (io, db) = Database::open_new( + &db_file, + opts.vfs.as_ref(), + flags, + opts.experimental_indexes, + opts.experimental_mvcc, + )?; let conn = db.connect()?; (io, conn) }; diff --git a/core/lib.rs b/core/lib.rs index 2f1328cb4..82e6ba506 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -343,6 +343,8 @@ impl Database { path: &str, vfs: Option, flags: OpenFlags, + indexes: bool, + mvcc: bool, ) -> Result<(Arc, Arc)> where S: AsRef + std::fmt::Display, @@ -370,7 +372,7 @@ impl Database { } }, }; - let db = Self::open_file_with_flags(io.clone(), path, flags, false, false)?; + let db = Self::open_file_with_flags(io.clone(), path, flags, indexes, mvcc)?; Ok((io, db)) } None => { @@ -378,7 +380,7 @@ impl Database { MEMORY_PATH => Arc::new(MemoryIO::new()), _ => Arc::new(PlatformIO::new()?), }; - let db = Self::open_file_with_flags(io.clone(), path, flags, false, false)?; + let db = Self::open_file_with_flags(io.clone(), path, flags, indexes, mvcc)?; Ok((io, db)) } } @@ -588,7 +590,11 @@ impl Connection { } #[cfg(feature = "fs")] - pub fn from_uri(uri: &str) -> Result<(Arc, Arc)> { + pub fn from_uri( + uri: &str, + use_indexes: bool, + mvcc: bool, + ) -> Result<(Arc, Arc)> { use crate::util::MEMORY_PATH; let opts = OpenOptions::parse(uri)?; let flags = opts.get_flags()?; @@ -598,7 +604,7 @@ impl Connection { let conn = db.connect()?; return Ok((io, conn)); } - let (io, db) = Database::open_new(&opts.path, opts.vfs.as_ref(), flags)?; + let (io, db) = Database::open_new(&opts.path, opts.vfs.as_ref(), flags, use_indexes, mvcc)?; if let Some(modeof) = opts.modeof { let perms = std::fs::metadata(modeof)?; std::fs::set_permissions(&opts.path, perms.permissions())?;