Line data Source code
1 : use std::sync::Arc;
2 :
3 : use axum::body::Body;
4 : use axum::extract::State;
5 : use axum::response::Response;
6 : use http::StatusCode;
7 : use http::header::CONTENT_TYPE;
8 : use serde::Deserialize;
9 :
10 : use crate::catalog::{SchemaDumpError, get_database_schema};
11 : use crate::compute::ComputeNode;
12 : use crate::http::JsonResponse;
13 : use crate::http::extract::Query;
14 :
15 0 : #[derive(Debug, Clone, Deserialize)]
16 : pub(in crate::http) struct DatabaseSchemaParams {
17 : database: String,
18 : }
19 :
20 : /// Get a schema dump of the requested database.
21 0 : pub(in crate::http) async fn get_schema_dump(
22 0 : params: Query<DatabaseSchemaParams>,
23 0 : State(compute): State<Arc<ComputeNode>>,
24 0 : ) -> Response {
25 0 : match get_database_schema(&compute, ¶ms.database).await {
26 0 : Ok(schema) => Response::builder()
27 0 : .status(StatusCode::OK)
28 0 : .header(CONTENT_TYPE.as_str(), "application/json")
29 0 : .body(Body::from_stream(schema))
30 0 : .unwrap(),
31 : Err(SchemaDumpError::DatabaseDoesNotExist) => {
32 0 : JsonResponse::error(StatusCode::NOT_FOUND, SchemaDumpError::DatabaseDoesNotExist)
33 : }
34 0 : Err(e) => JsonResponse::error(StatusCode::INTERNAL_SERVER_ERROR, e),
35 : }
36 0 : }
|