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