axion 0.0.4

Automatic API generator that creates a REST API mirror of a database in Rust
Documentation

GitHub: Axion crates.io docs.rs Crates.io Downloads License: MIT

High-performance Rust library for automatic API generation from database schemas.It empowers you to create a blazingly fast REST API that mirrors your database structure, effortlessly handling tables, views, functions, and procedures with Rust's renowned memory safety and zero-cost abstractions. Focused on speed and resource efficiency, it's the ideal solution for microservices and high-traffic APIs.

The name axion not only hints at its foundation on Axum but also resonates with the Spanish word "acciรณn" (action), reflecting its core promise: to take decisive action in transforming your database schema into a fully functional API with minimal effort.

Note: This library is part of a broader ecosystem aimed at simplifying database-to-client workflows, which also includes Python (prism-py) and TypeScript (prism-ts) variants. Axion represents the high-performance Rust engine within this ecosystem.

Note: This is an early version of the library. While functional, it may not be fully stable. Please report any issues you encounter.

Key Features

๐Ÿš€ High Performance: Built on Tokio and Hyper for maximum throughput.
๐Ÿ”’ Memory Safety: Rust's ownership model guarantees thread safety.
โšก Async Everything: Fully asynchronous I/O operations without blocking.
๐Ÿ”„ Automatic Route Generation: Create CRUD endpoints for database objects.
๐ŸŒ Database Independence: Support for PostgreSQL, MySQL, and SQLite.
๐Ÿงฉ Schema-Based Organization: Routes organized by database schemas for clean API structure.
๐Ÿ“Š Enhanced Filtering: Sorting, pagination, and complex query support.
๐Ÿ” Metadata API: Explore your database structure programmatically.
๐Ÿฅ Health Monitoring: Built-in health check endpoints.
๐Ÿ“ฆ Zero Boilerplate: Generate complete APIs with minimal code โ€“ true "acciรณn"!
๐Ÿ“‰ Low Resource Usage: Minimal memory footprint and CPU utilization.

Installation

Add to your Cargo.toml

cargo add axion

Quick Start

Here's a minimal example to get you started with axion:

use axion::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Initialize tracing for logs
    tracing_subscriber::fmt::init();

    // Configure database connection
    let db_config = DbConfig::new()
        .database_type(DatabaseType::Postgres) // Example
        .host("localhost")
        .port(5432)
        .database("yourdb")
        .username("username")
        .password("password")
        .build()?;

    // Create database client
    let db_client = Arc::new(DbClient::new(db_config).await?);
    db_client.test_connection().await?;

    // Create model manager with selected schemas
    let model_manager = Arc::new(ModelManager::new(
        db_client.clone(),
        vec!["public".to_string(), "app".to_string()]
    ).await?);

    // Initialize API generator
    let axion_api = AxionApi::new(model_manager.clone());
    
    // Build router with all generated routes
    let app = axion_api.build_router();
    
    // Serve the application
    let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8000));
    println!("Listening on http://{}", addr);
    
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await?;

    Ok(())
}

Plans for the Future

  • Full feature parity with prism-py and prism-ts.
  • Comprehensive support for all database types (PostgreSQL, MySQL, SQLite, etc.).
  • Support for all query types (CRUD, JOIN, etc.).
  • Robust authentication mechanisms (JWT, OAuth, etc.).
  • Flexible authorization models (RBAC, ABAC, etc.).
  • Advanced error handling strategies (HTTP, custom, etc.).
  • Versatile logging options (file, console, etc.).
  • Customizable API routes and endpoints.
  • Advanced filtering and sorting capabilities.
  • Custom pagination solutions.
  • Support for various response formats (e.g., JSON, XML, etc.).
  • Custom request validation and sanitization.

Performance

axion is engineered for exceptional performance and minimal resource usage:

  • Aims for significantly faster response times compared to equivalent dynamic language implementations.
  • Minimal memory footprint with efficient connection pooling.
  • High concurrency, capable of handling thousands of simultaneous connections.
  • Low CPU usage, even under heavy load.

License

This project is licensed under the MIT License. See the LICENSE file for details.