(url: &str)
| 26 | |
| 27 | impl SqliteStore { |
| 28 | pub async fn connect(url: &str) -> PersistenceResult<Self> { |
| 29 | let is_in_memory = url.contains(":memory:") || url.contains("mode=memory"); |
| 30 | let max_connections = if is_in_memory { 1 } else { 5 }; |
| 31 | |
| 32 | let options = SqliteConnectOptions::from_str(url) |
| 33 | .map_err(|e| map_db_error(&e))? |
| 34 | .create_if_missing(true); |
| 35 | |
| 36 | let mut pool_options = SqlitePoolOptions::new() |
| 37 | .max_connections(max_connections) |
| 38 | .min_connections(max_connections); |
| 39 | |
| 40 | if is_in_memory { |
| 41 | pool_options = pool_options.idle_timeout(None).max_lifetime(None); |
| 42 | } |
| 43 | |
| 44 | // Capture the on-disk path before `connect_with` consumes the options |
| 45 | // so we can restrict the permissions after the database is connected. |
| 46 | let db_path = (!is_in_memory).then(|| options.get_filename().to_path_buf()); |
| 47 | |
| 48 | let pool = pool_options |
| 49 | .connect_with(options) |
| 50 | .await |
| 51 | .map_err(|e| map_db_error(&e))?; |
| 52 | |
| 53 | // Tighten the permissions of the database file to owner-only access (0o600). |
| 54 | if let Some(path) = db_path { |
| 55 | restrict_db_file_permissions(&path)?; |
| 56 | } |
| 57 | |
| 58 | Ok(Self { pool }) |
| 59 | } |
| 60 | |
| 61 | pub async fn migrate(&self) -> PersistenceResult<()> { |
| 62 | SQLITE_MIGRATOR |
nothing calls this directly
no test coverage detected