MCPcopy Create free account
hub / github.com/Autoparallel/learner / open

Method open

crates/learner/src/database/mod.rs:125–151  ·  view source on GitHub ↗

Opens an existing database or creates a new one at the specified path. This method performs complete database initialization: 1. Creates parent directories if they don't exist 2. Initializes the SQLite database file 3. Applies schema migrations 4. Sets up full-text search indexes for paper metadata 5. Configures default storage paths if not already set # Arguments `path` - Path where the databa

(path: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

123 /// # }
124 /// ```
125 pub async fn open(path: impl AsRef<Path>) -> Result<Self> {
126 // Create parent directories if needed
127 if let Some(parent) = path.as_ref().parent() {
128 std::fs::create_dir_all(parent)?;
129 }
130
131 let conn = Connection::open(path.as_ref()).await?;
132
133 // Initialize schema
134 conn
135 .call(|conn| {
136 Ok(conn.execute_batch(include_str!(concat!(
137 env!("CARGO_MANIFEST_DIR"),
138 "/migrations/init.sql"
139 )))?)
140 })
141 .await?;
142
143 let db = Self { conn };
144
145 // Check if storage path is set, if not, set default
146 if db.get_storage_path().await.is_err() {
147 db.set_storage_path(Self::default_storage_path()).await?;
148 }
149
150 Ok(db)
151 }
152
153 /// Gets the configured storage path for document files.
154 ///

Callers

nothing calls this directly

Calls 2

get_storage_pathMethod · 0.80
set_storage_pathMethod · 0.80

Tested by

no test coverage detected