MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / open_local

Method open_local

src/global_db.rs:770–811  ·  view source on GitHub ↗
(db_path: &Path, read_only: bool)

Source from the content-addressed store, hash-verified

768 }
769
770 async fn open_local(db_path: &Path, read_only: bool) -> Option<Self> {
771 let storage_root = db_path
772 .parent()
773 .unwrap_or_else(|| Path::new("."))
774 .to_path_buf();
775 let builder = if read_only {
776 Builder::new_local(db_path).flags(OpenFlags::SQLITE_OPEN_READ_ONLY)
777 } else {
778 Builder::new_local(db_path)
779 };
780 let db = builder.build().await.ok()?;
781 let conn = db.connect().ok()?;
782
783 if let Some(mmap_size) = global_db_mmap_size_guard() {
784 conn.execute_batch(&format!("PRAGMA mmap_size = {mmap_size};"))
785 .await
786 .ok()?;
787 }
788
789 let pragmas = if read_only {
790 "PRAGMA busy_timeout = 5000;
791 PRAGMA foreign_keys = ON;"
792 .to_string()
793 } else {
794 let journal_mode = crate::db::platform_safe_journal_mode();
795 let synchronous = crate::db::platform_safe_synchronous_mode();
796 format!(
797 "PRAGMA journal_mode = {journal_mode};
798 PRAGMA busy_timeout = 5000;
799 PRAGMA synchronous = {synchronous};
800 PRAGMA foreign_keys = ON;"
801 )
802 };
803 conn.execute_batch(&pragmas).await.ok()?;
804
805 Some(Self {
806 conn,
807 storage_root,
808 db_path: db_path.to_path_buf(),
809 _db: db,
810 })
811 }
812
813 /// Opens (or creates) the global database at an explicit path. Returns
814 /// `None` if the directory cannot be created or the DB fails to open.

Callers

nothing calls this directly

Calls 5

buildMethod · 0.80
connectMethod · 0.45

Tested by

no test coverage detected