Handle DELETE /databases/:name - drop a database.
(
Path(name): Path<String>,
Extension(state): Extension<Arc<RESTServer>>,
)
| 236 | |
| 237 | /// Handle DELETE /databases/:name - drop a database. |
| 238 | pub async fn drop_database( |
| 239 | Path(name): Path<String>, |
| 240 | Extension(state): Extension<Arc<RESTServer>>, |
| 241 | ) -> impl IntoResponse { |
| 242 | let mut s = state.inner.lock().unwrap(); |
| 243 | |
| 244 | if s.no_permission_databases.contains(&name) { |
| 245 | let err = ErrorResponse::new( |
| 246 | Some("database".to_string()), |
| 247 | Some(name.clone()), |
| 248 | Some("No Permission".to_string()), |
| 249 | Some(403), |
| 250 | ); |
| 251 | return (StatusCode::FORBIDDEN, Json(err)).into_response(); |
| 252 | } |
| 253 | |
| 254 | if s.databases.remove(&name).is_some() { |
| 255 | // Also remove all tables in this database |
| 256 | let prefix = format!("{name}."); |
| 257 | s.tables.retain(|key, _| !key.starts_with(&prefix)); |
| 258 | s.no_permission_tables |
| 259 | .retain(|key| !key.starts_with(&prefix)); |
| 260 | (StatusCode::OK, Json(serde_json::json!(""))).into_response() |
| 261 | } else { |
| 262 | let err = ErrorResponse::new( |
| 263 | Some("database".to_string()), |
| 264 | Some(name.clone()), |
| 265 | Some("Not Found".to_string()), |
| 266 | Some(404), |
| 267 | ); |
| 268 | (StatusCode::NOT_FOUND, Json(err)).into_response() |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /// Handle GET /databases/:db/tables - list all tables in a database. |
| 273 | pub async fn list_tables( |
no test coverage detected