Premix ORM
Premix ORM is a zero-overhead, type-safe ORM for Rust, designed for performance and developer experience.
This crate (premix-orm) is the official facade that re-exports premix-core and premix-macros, providing a unified entry point for your application.
Research Status
This crate is part of an AI-assisted research prototype. APIs may change and production use is not recommended yet.
Requirements
- Rust 1.85+ (edition 2024).
- No nightly toolchain required.
Why use this facade?
- Unified imports:
use premix_orm::prelude::*;gets you everything. - No version mismatch: core and macros versions stay compatible.
- Clean dependencies: only one crate to add to your
Cargo.toml.
Installation
Add this to your Cargo.toml:
[]
= "1.0.9-alpha"
= { = "0.8", = ["runtime-tokio", "sqlite"] }
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Database Features
Enable database features on both premix-orm and sqlx:
= { = "1.0.9-alpha", = ["postgres", "axum"] }
= { = "0.8", = ["runtime-tokio", "sqlite", "postgres"] }
Feature Flags
| Feature | Description |
|---|---|
sqlite |
Enable SQLite support (default) |
postgres |
Enable PostgreSQL support |
mysql |
Enable MySQL support |
axum |
Enable Axum integration (PremixState) |
actix |
Enable Actix-web integration (PremixData) |
metrics |
Enable Prometheus metrics (install_prometheus_recorder) |
Quick Start
use *;
use ;
async
Common Query Helpers
// Fetch all rows.
let users = all.await?;
// Find by primary key.
let user = find_by_id.await?;
// Bulk update by primary key.
let updated = update_by_id.await?;
Features
- Compile-time SQL generation via macros
- Application-level eager loading using batched queries
- Optional soft delete support by
deleted_atconvention - SQLite, Postgres, and MySQL via
sqlxfeature flags - Axum and Actix-web integrations via feature flags
- Prometheus metrics collection support
Error Mapping Helpers
If you want domain errors instead of raw sqlx::Error, use ModelResultExt:
use *;
# async
Axum Integration
Use PremixState as your Axum state wrapper:
use ;
use ;
async
async
Compatibility
- Requires
sqlxwith matching database features - Works with the Tokio runtime
Book
For a longer-form guide, see orm-book/ in this repository.
SQL Transparency
Inspect the SQL generated by the query builder:
let query = find_in_pool.filter_gt.limit;
println!;
See the book for more on generated APIs and SQL inspection: orm-book/src/queries.md.
Raw SQL Escape Hatch
Run raw SQL while mapping results to your model:
let users = raw_sql
.fetch_all
.await?;
License
This project is licensed under the MIT license.