forked from roapi/roapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
692 additions
and
718 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use std::sync::Arc; | ||
|
||
use crate::api::{encode_record_batches, encode_type_from_req, HandlerContext}; | ||
use axum::body::Body; | ||
use axum::body::Bytes; | ||
use axum::extract; | ||
use axum::http::header::HeaderMap; | ||
use axum::http::Response; | ||
|
||
use crate::api::{encode_record_batches, encode_type_from_hdr, HandlerContext}; | ||
use crate::error::ApiErrResp; | ||
|
||
pub async fn post( | ||
data: web::Data<HandlerContext>, | ||
req: HttpRequest, | ||
query: web::Bytes, | ||
) -> Result<HttpResponse, ApiErrResp> { | ||
let encode_type = encode_type_from_req(req)?; | ||
|
||
let graphq = std::str::from_utf8(&query).map_err(ApiErrResp::read_query)?; | ||
let batches = data.cq.query_graphql(graphq).await?; | ||
|
||
state: extract::Extension<Arc<HandlerContext>>, | ||
headers: HeaderMap, | ||
body: Bytes, | ||
) -> Result<Response<Body>, ApiErrResp> { | ||
let ctx = state.0; | ||
let encode_type = encode_type_from_hdr(headers)?; | ||
let graphq = std::str::from_utf8(&body).map_err(ApiErrResp::read_query)?; | ||
let batches = ctx.cq.query_graphql(graphq).await?; | ||
encode_record_batches(encode_type, &batches) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,23 @@ | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use serde_derive::Deserialize; | ||
use axum::body::Body; | ||
use axum::extract; | ||
use axum::http::header::HeaderMap; | ||
use axum::http::Response; | ||
|
||
use crate::api::{encode_record_batches, encode_type_from_req, HandlerContext}; | ||
use crate::api::HandlerContext; | ||
use crate::api::{encode_record_batches, encode_type_from_hdr}; | ||
use crate::error::ApiErrResp; | ||
|
||
#[derive(Deserialize)] | ||
pub struct RestTablePath { | ||
table_name: String, | ||
} | ||
|
||
pub async fn get_table( | ||
data: web::Data<HandlerContext>, | ||
path: web::Path<RestTablePath>, | ||
req: HttpRequest, | ||
query: web::Query<HashMap<String, String>>, | ||
) -> Result<HttpResponse, ApiErrResp> { | ||
let encode_type = encode_type_from_req(req)?; | ||
|
||
let batches = data | ||
.cq | ||
.query_rest_table(&path.table_name, &query.into_inner()) | ||
.await?; | ||
|
||
state: extract::Extension<Arc<HandlerContext>>, | ||
headers: HeaderMap, | ||
extract::Path(table_name): extract::Path<String>, | ||
extract::Query(params): extract::Query<HashMap<String, String>>, | ||
) -> Result<Response<Body>, ApiErrResp> { | ||
let ctx = &state.0; | ||
let encode_type = encode_type_from_hdr(headers)?; | ||
let batches = ctx.cq.query_rest_table(&table_name, ¶ms).await?; | ||
encode_record_batches(encode_type, &batches) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,14 @@ | ||
use actix_http::body::MessageBody; | ||
use actix_service::ServiceFactory; | ||
use actix_web::dev::{ServiceRequest, ServiceResponse}; | ||
use actix_web::{web, App, Error}; | ||
|
||
use crate::api; | ||
|
||
pub fn register_app_routes<T, B>(app: App<T, B>) -> App<T, B> | ||
where | ||
B: MessageBody, | ||
T: ServiceFactory< | ||
ServiceRequest, | ||
Config = (), | ||
Response = ServiceResponse<B>, | ||
Error = Error, | ||
InitError = (), | ||
>, | ||
{ | ||
app.route( | ||
"/api/tables/{table_name}", | ||
web::get().to(api::rest::get_table), | ||
) | ||
.route("/api/sql", web::post().to(api::sql::post)) | ||
.route("/api/graphql", web::post().to(api::graphql::post)) | ||
.route("/api/schema", web::get().to(api::schema::get)) | ||
.route( | ||
"/api/schema/{table_name}", | ||
web::get().to(api::schema::get_by_table_name), | ||
) | ||
use axum::{ | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
|
||
pub fn register_app_routes() -> Router { | ||
Router::new() | ||
.route("/api/tables/:table_name", get(api::rest::get_table)) | ||
.route("/api/sql", post(api::sql::post)) | ||
.route("/api/graphql", post(api::graphql::post)) | ||
.route("/api/schema", get(api::schema::schema)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,32 @@ | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use serde_derive::Deserialize; | ||
use axum::body::Body; | ||
use axum::extract; | ||
use axum::http::Response; | ||
|
||
use crate::api::HandlerContext; | ||
use crate::api::{bytes_to_json_resp, HandlerContext}; | ||
use crate::error::ApiErrResp; | ||
|
||
pub async fn get( | ||
data: web::Data<HandlerContext>, | ||
_req: HttpRequest, | ||
_query: web::Bytes, | ||
) -> Result<HttpResponse, ApiErrResp> { | ||
Ok(HttpResponse::Ok() | ||
.content_type("application/json") | ||
.body(serde_json::to_vec(data.cq.schema_map()).map_err(ApiErrResp::json_serialization)?)) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct SchemaTablePath { | ||
table_name: String, | ||
pub async fn schema( | ||
state: extract::Extension<Arc<HandlerContext>>, | ||
) -> Result<Response<Body>, ApiErrResp> { | ||
let ctx = state.0; | ||
let payload = | ||
serde_json::to_vec(ctx.cq.schema_map()).map_err(ApiErrResp::json_serialization)?; | ||
Ok(bytes_to_json_resp(payload)) | ||
} | ||
|
||
pub async fn get_by_table_name( | ||
data: web::Data<HandlerContext>, | ||
path: web::Path<SchemaTablePath>, | ||
_req: HttpRequest, | ||
_query: web::Query<HashMap<String, String>>, | ||
) -> Result<HttpResponse, ApiErrResp> { | ||
Ok(HttpResponse::Ok().content_type("application/json").body( | ||
serde_json::to_vec( | ||
data.cq | ||
.schema_map() | ||
.get(&path.table_name) | ||
.ok_or_else(|| ApiErrResp::not_found("invalid table name"))?, | ||
) | ||
.map_err(ApiErrResp::json_serialization)?, | ||
)) | ||
state: extract::Extension<Arc<HandlerContext>>, | ||
extract::Path(table_name): extract::Path<String>, | ||
) -> Result<Response<Body>, ApiErrResp> { | ||
let ctx = state.0; | ||
let payload = serde_json::to_vec( | ||
ctx.cq | ||
.schema_map() | ||
.get(&table_name) | ||
.ok_or_else(|| ApiErrResp::not_found("invalid table name"))?, | ||
) | ||
.map_err(ApiErrResp::json_serialization)?; | ||
Ok(bytes_to_json_resp(payload)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use std::sync::Arc; | ||
|
||
use crate::api::{encode_record_batches, encode_type_from_req, HandlerContext}; | ||
use axum::body::Body; | ||
use axum::body::Bytes; | ||
use axum::extract; | ||
use axum::http::header::HeaderMap; | ||
use axum::http::Response; | ||
|
||
use crate::api::{encode_record_batches, encode_type_from_hdr, HandlerContext}; | ||
use crate::error::ApiErrResp; | ||
|
||
pub async fn post( | ||
data: web::Data<HandlerContext>, | ||
req: HttpRequest, | ||
query: web::Bytes, | ||
) -> Result<HttpResponse, ApiErrResp> { | ||
let encode_type = encode_type_from_req(req)?; | ||
|
||
let sql = std::str::from_utf8(&query).map_err(ApiErrResp::read_query)?; | ||
let batches = data.cq.query_sql(sql).await?; | ||
|
||
state: extract::Extension<Arc<HandlerContext>>, | ||
headers: HeaderMap, | ||
body: Bytes, | ||
) -> Result<Response<Body>, ApiErrResp> { | ||
let ctx = state.0; | ||
let encode_type = encode_type_from_hdr(headers)?; | ||
let sql = std::str::from_utf8(&body).map_err(ApiErrResp::read_query)?; | ||
let batches = ctx.cq.query_sql(sql).await?; | ||
encode_record_batches(encode_type, &batches) | ||
} |
Oops, something went wrong.