(&mut self)
| 36 | } |
| 37 | |
| 38 | pub async fn reopen(&mut self) -> Result<(), DbErr> { |
| 39 | // Close existing db, if any |
| 40 | if let Some(db) = self.db.take() { |
| 41 | db.close().await?; // drop it |
| 42 | } |
| 43 | let mut opt = ConnectOptions::new(format!("sqlite://{}", self.path)); |
| 44 | opt.max_connections(1).sqlx_logging(false); |
| 45 | let db = SeaDatabase::connect(opt).await?; |
| 46 | self.db = Some(db); |
| 47 | Ok(()) |
| 48 | } |
| 49 | |
| 50 | pub fn db(&self) -> &DbConn { |
| 51 | self.db.as_ref().expect("DB closed") |