Opens the provided database and runs any necessary migrations. If a database is already open, this will return an error.
(&self, context: &Context, passphrase: String)
| 248 | /// Opens the provided database and runs any necessary migrations. |
| 249 | /// If a database is already open, this will return an error. |
| 250 | pub async fn open(&self, context: &Context, passphrase: String) -> Result<()> { |
| 251 | if self.is_open().await { |
| 252 | error!( |
| 253 | context, |
| 254 | "Cannot open, database \"{:?}\" already opened.", self.dbfile, |
| 255 | ); |
| 256 | bail!("SQL database is already opened."); |
| 257 | } |
| 258 | |
| 259 | let passphrase_nonempty = !passphrase.is_empty(); |
| 260 | self.try_open(context, &self.dbfile, passphrase).await?; |
| 261 | info!(context, "Opened database {:?}.", self.dbfile); |
| 262 | *self.is_encrypted.write().await = Some(passphrase_nonempty); |
| 263 | |
| 264 | // setup debug logging if there is an entry containing its id |
| 265 | if let Some(xdc_id) = self |
| 266 | .get_raw_config_u32(Config::DebugLogging.as_ref()) |
| 267 | .await? |
| 268 | { |
| 269 | set_debug_logging_xdc(context, Some(MsgId::new(xdc_id))).await?; |
| 270 | } |
| 271 | Ok(()) |
| 272 | } |
| 273 | |
| 274 | /// Changes the passphrase of encrypted database. |
| 275 | /// |