axum_sql_viewer/lib.rs
1//! # axum-sql-viewer
2//!
3//! A development tool for viewing SQL tables in web browsers, easily integrable as an Axum layer.
4//!
5//! ## Features
6//!
7//! - Dynamic schema discovery for any SQL database
8//! - Web-based table browser with infinite scrolling
9//! - Column sorting and filtering
10//! - Raw SQL query execution
11//! - Support for SQLite and PostgreSQL
12//!
13//! ## Security Warning
14//!
15//! **This is a development tool only!**
16//!
17//! - No authentication/authorization built-in
18//! - Exposes full database schema and data
19//! - Raw query execution allows full database access (INSERT/UPDATE/DELETE)
20//! - Should never be exposed in production or public networks
21//!
22//! ## Example Usage
23//!
24//! ```rust,no_run
25//! use axum::{Router, routing::get};
26//! use axum_sql_viewer::SqlViewerLayer;
27//! use sqlx::SqlitePool;
28//!
29//! #[tokio::main]
30//! async fn main() {
31//! let pool = SqlitePool::connect("sqlite::memory:")
32//! .await
33//! .unwrap();
34//!
35//! let app = Router::new()
36//! .route("/", get(|| async { "Hello, World!" }))
37//! .merge(SqlViewerLayer::sqlite("/sql-viewer", pool).into_router());
38//!
39//! // Serve the application...
40//! }
41//! ```
42
43// Public modules
44pub mod api;
45pub mod database;
46pub mod frontend;
47pub mod layer;
48pub mod schema;
49
50// Public exports
51pub use layer::SqlViewerLayer;
52pub use schema::{ColumnInfo, ForeignKey, IndexInfo, TableSchema};
53
54// Re-export database providers
55pub use database::traits::DatabaseProvider;
56
57#[cfg(feature = "sqlite")]
58pub use database::sqlite::SqliteProvider;
59
60#[cfg(feature = "postgres")]
61pub use database::postgres::PostgresProvider;
62
63// Error type
64use thiserror::Error;
65
66#[derive(Debug, Error)]
67pub enum Error {
68 #[error("Database error: {0}")]
69 Database(String),
70
71 #[error("Serialization error: {0}")]
72 Serialization(#[from] serde_json::Error),
73
74 #[error("Invalid query: {0}")]
75 InvalidQuery(String),
76}
77
78pub type Result<T> = std::result::Result<T, Error>;