SSW (Simple Smart Wrapper)
A lightweight, type-safe Rust ORM library built on top of rbatis
๐ Features
- โ Type-safe SQL generation - Compile-time query validation
- โ Wrapper pattern - Fluent API for building complex queries
- โ DaoTrait - Standard CRUD operations out of the box
- โ
Macro support - Minimal boilerplate with
impl_model_trait!andimpl_dao_trait! - โ Async/await - Native async support with tokio
- โ
Multi-database support - PostgreSQL, SQLite, MySQL via
rbatis - โ
Pagination - Built-in
PageResultwith metadata - โ
Aggregate functions -
count,max,min,sum,avg,exists
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.1.1"
# For PostgreSQL
= "4.9"
# For SQLite
= "4.8"
# For MySQL
= "4.8"
# Common dependencies
= { = "1.0", = ["derive"] }
= "1.5"
๐ฅ Quick Start
1. Define Your Model
use ;
use ;
use QueryWrapper;
// Implement ModelTrait (required)
impl_model_trait!;
2. Initialize RBatis
use RBatis;
use PgDriver;
use lazy_static;
lazy_static!
async
3. Implement DaoTrait
// Use macro (recommended)
impl_dao_trait!;
// Or implement manually
4. Use CRUD Operations
async
5. Pagination (Optional)
use Page;
// Create a Page (recommended: use ::new())
let page = new; // Page 1, 10 records per page
let wrapper = new
.table
.order_by;
let page_result = select_page.await;
println!;
println!;
println!;
๐ Documentation
๐ Full documentation: See skills/SKILL.md for:
- Complete API reference
- Advanced usage examples
- Best practices
- Troubleshooting guide
- Migration guide
๐งช Examples: See integration tests for complete working examples:
examples/rbatis_test/pgsql_test/src/main.rs- PostgreSQLexamples/rbatis_test/sqlite_test/src/main.rs- SQLiteexamples/rbatis_test/mysql_test/src/main.rs- MySQL
๐งช Testing
# Run unit tests
# Run integration tests (requires database)
# PostgreSQL
# SQLite
# MySQL
# Check code coverage (optional)
โ ๏ธ Safety Warnings
try_delete_all() - EXTREME DANGER!
// โ ๏ธ WARNING: This will DELETE ALL RECORDS in the table!
let result = try_delete_all.await?;
Never use try_delete_all() in production! Always add WHERE conditions:
// โ
Safe: Delete with condition
try_delete_by_column.await?;
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repo
# Run tests
# Run integration tests (requires database)
# PostgreSQL
# SQLite
# MySQL
๐ License
Licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
๐ Acknowledgments
๐ง Contact
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with โค๏ธ in Rust