๐ฏ A high-performance, secure, and feature-rich database access layer built on Sea-ORM
DBNexus provides a declarative database access approach:
| โจ Type Safe | ๐ Permission Control | ๐ Smart Pooling | ๐ Enterprise Monitoring |
|---|---|---|---|
| Compile-time checks | Table-level RBAC | RAII auto-management | Prometheus metrics |
use ;
use *;
async
๐ Table of Contents
- โจ Features
- ๐ Quick Start
- ๐จ Feature Flags
- ๐ Documentation
- ๐ป Examples
- ๐๏ธ Architecture
- ๐ Security
- ๐งช Testing
- ๐ค Contributing
- ๐ License
- ๐ Acknowledgments
โจ Features
| ๐ฏ Core Features | โก Enterprise Features |
|---|---|
| Always Available | Optional |
๐ฏ Core Features (Always Available)
| Status | Feature | Description |
|---|---|---|
| โ | Connection Pooling | RAII-style automatic connection lifecycle management |
| โ | Permission Control | Role-based table-level access control (RBAC) |
| โ | Procedural Macros | Auto-generate CRUD methods and permission checks |
| โ | SQL Parser | Extract operation type and target table |
| โ | Transaction Support | Complete transaction management |
| โ | Multi-Database Support | SQLite, PostgreSQL, MySQL |
โก Enterprise Features
| Status | Feature | Description |
|---|---|---|
| ๐ | Metrics Monitoring | Prometheus metrics export (metrics feature) |
| ๐ | Distributed Tracing | OpenTelemetry integration (tracing feature) |
| ๐ | Audit Logging | Automatic audit for all operations (audit feature) |
| ๐๏ธ | Database Migration | Automatic migration execution (migration feature) |
| ๐ | Data Sharding | Support for sharding strategies (sharding feature) |
| ๐ | Global Index | Cross-shard queries (global-index feature) |
| ๐พ | Caching | LRU cache support (cache feature) |
| ๐ | Permission Engine | Advanced permission system (permission-engine feature) |
๐ฆ Feature Presets
| Preset | Features | Use Case |
|---|---|---|
| embedded | runtime-tokio-rustls, sqlite, config-env |
Ultra-minimal for embedded/edge devices |
| microservice | runtime-tokio-rustls, postgres, permission, sql-parser, config-env, observability |
Microservice deployment |
| monolith | runtime-tokio-rustls, postgres, permission, sql-parser, yaml, data-management, security, observability |
Monolithic application |
| enterprise | postgres, monolith, permission-engine |
Full enterprise features |
| all-optional | All optional features without database drivers | All enterprise features (manual database selection) |
๐ Quick Start
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
= { = "1.50", = ["rt-multi-thread", "macros"] }
= { = "2.0.0-rc.37", = ["macros"] }
๐ก Basic Usage
๐ฌ 5-Minute Quick Start
Step 1: Define Entity
use ;
use *;
Step 2: Create Connection Pool
async
Step 3: Insert Data
let user = User ;
insert.await?;
Step 4: Query Data
let users = find_all.await?;
println!;
๐ Permission Control
use ;
use *;
// Admin can access
let session = pool.get_session.await?;
find_all.await?;
// Regular user will be denied
let session = pool.get_session.await?;
find_all.await?; // Error: Permission denied
๐จ Feature Flags
โ ๏ธ BREAKING CHANGE in v0.2.0
All users must update their Cargo.toml:
Version 0.1.x โ 0.2.0 is a breaking change. The cache feature is no longer enabled by default, and several features now explicitly require cache to be enabled.
Database Drivers (choose one)
# SQLite
= { = "0.2", = ["sqlite"] }
# PostgreSQL
= { = "0.2", = ["postgres"] }
# MySQL
= { = "0.2", = ["mysql"] }
Core Features
# Permission control (REQUIRES cache feature)
= { = "0.2", = ["permission", "cache"] }
# SQL parsing (REQUIRES cache feature)
= { = "0.2", = ["sql-parser", "cache"] }
# Procedural macros
= { = "0.2", = ["macros"] }
# Caching (required by permission and sql-parser)
= { = "0.2", = ["cache"] }
Using Presets (Recommended)
# Embedded/Edge devices (minimal)
= { = "0.2", = ["embedded"] }
# Microservices
= { = "0.2", = ["microservice"] }
# Monolithic applications
= { = "0.2", = ["monolith"] }
# Enterprise (all features)
= { = "0.2", = ["enterprise"] }
Optional Features
# Observability (metrics + tracing + health-check)
= { = "0.2", = ["observability"] }
# Data management (migration + sharding + global-index)
= { = "0.2", = ["data-management"] }
# Security (audit + permission-engine)
= { = "0.2", = ["security"] }
# Individual features
= { = "0.2", = [
"metrics", # Prometheus metrics
"tracing", # Distributed tracing
"audit", # Audit logging
"migration", # Database migration
"sharding", # Data sharding
"permission-engine" # Advanced permission engine (requires cache)
] }
Configuration
= { = "0.2", = [
"yaml", # YAML config support
"config-toml", # TOML config support
"config-env", # Environment variables
] }
๐ Documentation
๐ Additional Resources
| Resource | Description |
|---|---|
| ๐ User Guide | Comprehensive guide for using DBNexus |
| ๐ API Reference | Complete API documentation |
| ๐๏ธ Architecture | System architecture and design decisions |
| ๐ฆ Examples | Working code examples |
๐ป Examples
๐ก Real-world Examples
๐ Advanced Configuration
use ;
let config = new
.url
.max_connections
.min_connections
.idle_timeout
.acquire_timeout
.build?;
let pool = with_config.await?;
๐ง Environment Variables
let pool = new.await?;
๐ Transactions
let mut session = pool.get_session.await?;
// Begin transaction
session.begin_transaction.await?;
// Multiple operations
insert.await?;
insert.await?;
// Commit
session.commit_transaction.await?;
๐ Monitoring
use ;
let pool = new.await?;
// Get pool status
let status = pool.status;
println!;
// Export Prometheus metrics
let metrics = new;
println!;
๐๏ธ Architecture
๐๏ธ System Architecture
graph TD
A[Application Layer<br/>Your code using DbPool and Session] --> B[DBNexus API Layer<br/>DbPool, Session<br/>Permission checking<br/>Transaction management]
B --> C[Feature Modules<br/>Config, Permission, Metrics<br/>Migration, Sharding, Audit]
C --> D[Connection Pool<br/>Connection lifecycle management<br/>Health checking<br/>RAII guarantees]
D --> E[Sea-ORM / SQLx<br/>Database drivers<br/>Query builder]
See ARCHITECTURE.md for detailed architecture documentation.
๐ Security
๐ก๏ธ Security Features
DBNexus is built with security in mind:
- No unsafe code -
#![forbid(unsafe_code)]in all library code - Permission enforcement - Table-level access control with compile-time verification
- SQL injection prevention - Parameterized queries by default
- Config path validation - Protection against path traversal attacks
- Rate limiting - Permission check rate limiting to prevent abuse
๐งช Testing
๐ฏ Run Tests
# SQLite tests
# PostgreSQL tests
# MySQL tests
# All tests (requires Docker)
Using Docker
# Start databases
# Run all tests
# Stop databases
๐ค Contributing
Contributions are welcome! Please check the repository for contribution guidelines.
Development Setup
# Clone repository
# Install pre-commit hooks
# Run tests
# Run linter
๐ License
This project is licensed under MIT:
๐ Acknowledgments
๐ Built on Excellent Tools
- Sea-ORM - The excellent ORM framework DBNexus is built on
- SQLx - Async SQL toolkit
- The Rust community for amazing tools and libraries
๐ Support
โญ Star History
๐ Support This Project
If you find this project useful, please consider giving it a โญ๏ธ!
Built with โค๏ธ by Kirky.X
ยฉ 2026 Kirky.X. All rights reserved.