axum_sql_viewer/api/
mod.rs

1//! REST API endpoints
2//!
3//! This module contains all API endpoint handlers for the SQL viewer.
4
5use axum::Router;
6use std::sync::Arc;
7
8use crate::database::traits::DatabaseProvider;
9
10pub mod query;
11pub mod rows;
12pub mod tables;
13
14// Re-export handlers for convenience
15pub use query::execute_query_handler;
16pub use rows::{count_rows_handler, get_rows_handler};
17pub use tables::{get_table_schema_handler, list_tables_handler};
18
19/// Create the API router with all endpoints
20///
21/// This function creates a router with all API endpoints configured and state attached.
22///
23/// # Arguments
24///
25/// * `database` - Arc-wrapped database provider implementation
26///
27/// # Returns
28///
29/// An Axum Router configured with all API routes
30pub fn create_api_router<DB: DatabaseProvider>(database: Arc<DB>) -> Router {
31    Router::new()
32        .route("/tables", axum::routing::get(tables::list_tables_handler::<DB>))
33        .route("/tables/:name", axum::routing::get(tables::get_table_schema_handler::<DB>))
34        .route("/tables/:name/rows", axum::routing::get(rows::get_rows_handler::<DB>))
35        .route("/tables/:name/count", axum::routing::get(rows::count_rows_handler::<DB>))
36        .route("/query", axum::routing::post(query::execute_query_handler::<DB>))
37        .with_state(database)
38}