ormkit
A comprehensive ORM layer for SQLx that provides type-safe database operations with minimal boilerplate.
Features
- Derive Macros: Automatic implementation of Entity traits with
#[derive(ormkit::Entity)] - ActiveModel Pattern: Track field changes for efficient partial updates
- Repository Pattern: Generic CRUD operations for any entity
- Query Builder: Type-safe dynamic query construction with filters and ordering
- Pagination: Built-in offset and cursor-based pagination support
- Transaction Management: Automatic commit/rollback with transaction guards
- Batch Operations: Efficient bulk inserts, updates, and deletes
- Relationship Loading: Prevents N+1 queries with eager/lazy loading strategies
Installation
[]
= "0.1"
= "0.1"
= { = "0.8", = ["runtime-tokio-rustls", "postgres", "chrono", "uuid", "json"] }
Quick Start
use ;
use ActiveValue;
use PgPool;
use Uuid;
// Define an Entity using the derive macro
// Repository operations (CRUD)
async
Core Features
Query Builder
use ;
let users: = query
.filter
.filter
.order_by
.limit
.fetch_all
.await?;
Pagination
use PaginationRequest;
let repo = new;
let request = new; // page 1, 25 per page
let page = repo.paginate.await?;
println!;
for user in page.items
Batch Operations
use ;
let new_users = vec!;
let options = new.batch_size;
let result = insert_many.await?;
println!;
Transactions
use transaction;
let result = transaction.await?;
Advanced Features
Relationships (Prevents N+1 Queries)
use RelationBuilder;
// Load related entities in a single query
let posts_with_users = for_entities
.
.await?;
for loaded in posts_with_users
Current Status
v0.1.0 - Core features fully functional:
- ✅ Entity derive macros
- ✅ Repository CRUD operations
- ✅ Query builder with filters
- ✅ Pagination (offset and cursor-based)
- ✅ Transaction management
- ✅ Batch operations
- ⚠️ Relationship auto-loading (requires additional macro work)
For complex relationship loading, raw SQLx queries can still be used alongside ormkit.
Documentation
Full API documentation is available at docs.rs.
License
MIT OR Apache-2.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
See Also
- SQLx - The underlying database driver
- ormkit-derive - Derive macros for ormkit