()
| 29 | |
| 30 | impl Database { |
| 31 | pub async fn new() -> Result<Self, DatabaseError> { |
| 32 | let db_path = Self::get_database_path()?; |
| 33 | |
| 34 | if let Some(parent) = db_path.parent() { |
| 35 | std::fs::create_dir_all(parent) |
| 36 | .map_err(|e| DatabaseError::ConnectionError(e.to_string()))?; |
| 37 | } |
| 38 | |
| 39 | let db_url = format!("sqlite:{}?mode=rwc", db_path.display()); |
| 40 | |
| 41 | info!("Connecting to database at {}", db_path.display()); |
| 42 | |
| 43 | let pool = SqlitePoolOptions::new() |
| 44 | .max_connections(5) |
| 45 | .connect(&db_url) |
| 46 | .await |
| 47 | .map_err(|e| DatabaseError::ConnectionError(e.to_string()))?; |
| 48 | |
| 49 | let db = Self { pool }; |
| 50 | db.run_migrations().await?; |
| 51 | |
| 52 | Ok(db) |
| 53 | } |
| 54 | |
| 55 | pub async fn in_memory() -> Result<Self, DatabaseError> { |
| 56 | let pool = SqlitePoolOptions::new() |
nothing calls this directly
no test coverage detected