| Crates.io | axion-db |
| lib.rs | axion-db |
| version | 0.0.4 |
| created_at | 2025-06-01 05:07:31.095965+00 |
| updated_at | 2025-06-18 06:04:32.756923+00 |
| description | Database functionality for the axion framework |
| homepage | |
| repository | https://github.com/Yrrrrrf/axion |
| max_upload_size | |
| id | 1696894 |
| size | 126,836 |
Core database interaction layer for the Axion framework.
Note: This crate is part of the Axion framework and is not typically intended for direct standalone use. It provides the foundational database connectivity, schema introspection, and type mapping capabilities that power Axion.
axion-db is responsible for:
sqlx::AnyPool for efficient, asynchronous database connections.sqlx and tokio for fully asynchronous database operations.sqlx::Any):
sqlx's robust connection pooling.DbConfig for various connection setups.This crate is primarily consumed by other Axion components (axion-server and axion). Direct usage would typically involve setting up a DbConfig and then creating a DbClient to perform introspection or raw queries.
use axion_db::prelude::*;
use std::sync::Arc;
# async fn run_example() -> axion_db::error::DbResult<()> {
// Ensure drivers are installed for sqlx::Any (typically done once in main application)
sqlx::any::install_default_drivers();
let db_config = DbConfig::new(DatabaseType::Postgres) // Or Mysql, Sqlite
.host("localhost")
.port(5432)
.username("your_user")
.password("your_password")
.database_name("your_database")
.pool_options(PoolOptionsConfig {
max_connections: Some(10),
..Default::default()
});
let client = Arc::new(DbClient::new(db_config).await?);
client.test_connection().await?;
let version = client.get_db_version().await?;
println!("Connected to database version: {}", version.lines().next().unwrap_or_default());
// Example: List schemas
let schemas = client.list_all_schemas(false).await?; // false = exclude system schemas
println!("Available user schemas: {:?}", schemas);
if let Some(first_schema) = schemas.first() {
// Example: List tables in the first user schema
let tables = client.list_tables_in_schema(first_schema).await?;
println!("Tables in schema '{}': {:?}", first_schema, tables);
if let Some(first_table) = tables.first() {
// Example: Get metadata for the first table in that schema
let table_meta = client.get_table_metadata(first_schema, first_table).await?;
println!("Metadata for table '{}.{}': {:#?}", first_schema, first_table, table_meta);
}
}
# Ok(())
# }
For more comprehensive examples of how axion-db is used to power automatic API generation, please see the main Axion repository examples.