-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathsql.rs
More file actions
23 lines (20 loc) · 748 Bytes
/
sql.rs
File metadata and controls
23 lines (20 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use axum::body::Bytes;
use axum::extract;
use axum::http::header::HeaderMap;
use axum::response::IntoResponse;
use std::sync::Arc;
use crate::api::{encode_record_batches, encode_type_from_hdr};
use crate::error::ApiErrResp;
use crate::context::RoapiContext;
pub async fn post<H: RoapiContext>(
state: extract::Extension<Arc<H>>,
headers: HeaderMap,
body: Bytes,
) -> Result<impl IntoResponse, ApiErrResp> {
let ctx = state.0;
let response_format = H::get_response_format(&ctx).await;
let encode_type = encode_type_from_hdr(headers, response_format);
let sql = std::str::from_utf8(&body).map_err(ApiErrResp::read_query)?;
let batches = ctx.query_sql(sql).await?;
encode_record_batches(encode_type, &batches)
}