Opens an existing database at `db_path`, applies performance pragmas, and runs any pending schema migrations. Returns `(Self, migrated)` where `migrated` is `true` if schema migrations were applied during open.
(db_path: &Path)
| 154 | /// Returns `(Self, migrated)` where `migrated` is `true` if schema |
| 155 | /// migrations were applied during open. |
| 156 | pub async fn open(db_path: &Path) -> Result<(Self, bool)> { |
| 157 | let db = |
| 158 | Builder::new_local(db_path) |
| 159 | .build() |
| 160 | .await |
| 161 | .map_err(|e| TraceDecayError::Database { |
| 162 | message: format!("failed to open database: {e}"), |
| 163 | operation: "open".to_string(), |
| 164 | })?; |
| 165 | |
| 166 | let conn = db.connect().map_err(|e| TraceDecayError::Database { |
| 167 | message: format!("failed to connect to database: {e}"), |
| 168 | operation: "open".to_string(), |
| 169 | })?; |
| 170 | |
| 171 | let file_size = std::fs::metadata(db_path).map_or(0, |m| m.len()); |
| 172 | Self::apply_pragmas(&conn, file_size).await?; |
| 173 | let migrated = migrations::migrate(&conn).await?; |
| 174 | |
| 175 | Ok((Self { conn, _db: db }, migrated)) |
| 176 | } |
| 177 | |
| 178 | /// Opens an existing database in read-only mode. |
| 179 | /// |