Backbone-ORM
Status: ✅ FULLY IMPLEMENTED Last Updated: 2026-02-11
A powerful, type-safe PostgreSQL ORM for Rust applications, designed for Backbone Framework.
🚀 Features
- Type-Safe Query Building - Build queries with compile-time safety
- SQL Injection Protection - All queries use parameterized binding
- Generic Repository Pattern - Reusable CRUD operations
- Advanced Querying - JOINs, CTEs, window functions, aggregations
- Database Migrations - Version-controlled schema management
- Database Seeding - Structured data seeding for development and testing
- Raw SQL Support - When you need full power of SQL
- Async/Await - Built on Tokio for high performance
- Comprehensive Testing - Full test coverage with integration tests
📦 Installation
Add to your Cargo.toml:
[]
= { = "0.1", = ["default"] }
= { = "0.8", = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "json", "migrate"] }
= { = "1.0", = ["full"] }
= "1.0"
= { = "1.0", = ["derive"] }
= "1.0"
= { = "1.0", = ["v4", "serde"] }
= { = "0.4", = ["serde"] }
🎯 Quick Start
use *;
use ;
use ;
async
📖 Overview
Backbone-ORM provides a complete database solution for Rust applications with these key principles:
Security First
- Parameterized Queries: All queries use parameter binding to prevent SQL injection
- Type Safety: Compile-time checks prevent runtime errors
- Validation: Built-in validation for all data operations
Developer Experience
- Intuitive API: Clean, fluent interface for building queries
- Comprehensive Documentation: Examples and patterns for common use cases
- Error Handling: Rich error types with context for debugging
Performance
- Async/Await: Non-blocking database operations
- Connection Pooling: Efficient connection management
- Query Optimization: Smart query building with minimal overhead
Flexibility
- Raw SQL Support: Drop to raw SQL when needed
- Generic Patterns: Reusable repository implementations
🔧 Usage
Basic CRUD Operations
use *;
// Create
let user = User ;
let created = user_repo.create.await?;
// Read by ID
let user = user_repo.find_by_id.await?;
// Read all
let users = user_repo.find_all.await?;
// Update
user.name = "Updated Name";
let updated = user_repo.update.await?;
// Delete
let deleted = user_repo.delete.await?;
// Count
let count = user_repo.count.await?;
Query Builder
use *;
// Basic filtering
let users = new
.where_gt
.where_like
.order_by
.limit
.build
.
.await?;
// Complex conditions
let results = new
.where_gte
.where_lt
.order_by
.limit
.build
.
.await?;
Advanced Querying
use *;
// JOIN operations
let users_with_profiles: = new
.select
.join
.where_gt
.order_by
.build
.execute
.await?;
// Common Table Expressions (CTEs)
let analytics: = new
.with_cte
.select
.join
.where_gt
.order_by
.build
.execute
.await?;
// Window Functions
let ranked_users: = new
.select
.order_by
.build
.execute
.await?;
Raw SQL Queries
use *;
// Parameterized raw query
let users: = new
.bind
.bind
.limit
.execute
.await?;
// Scalar queries
let average_age: f64 = scalar.await?;
let departments: = many.await?;
🛠️ Security Features
-
SQL Injection Prevention
- All queries use parameter binding
- No string concatenation for values
- Type-safe parameter handling
-
Connection Security
- SSL/TLS support
- Connection timeout configuration
- Secure credential management
-
Data Validation
- Type-safe field mapping
- Runtime parameter validation
- SQL error handling
📚 Testing
Comprehensive testing approach:
- Unit Tests: Test individual components in isolation
- Integration Tests: Test database operations end-to-end
- Mock Tests: Test business logic without database
- Performance Tests: Validate query performance
Running tests
# Run all tests
# Run with database (for integration tests)
DATABASE_URL="postgresql://root:password@localhost/test"
🔗 Dependencies
[]
# Core dependencies
= { = "1.0", = ["full"] }
= "0.1"
= { = "1.0", = ["derive"] }
= "1.0"
= { = "1.0", = ["v4", "serde"] }
= { = "0.4", = ["serde"] }
= "1.0"
= "1.0"
# Database driver
= { = "0.8", = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "json", "migrate"] }
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for Backbone Framework