premix_orm/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![deny(missing_debug_implementations)]
3#![deny(missing_docs)]
4
5//! # Premix ORM
6//!
7//! > **"Write Rust, Run Optimized SQL."**
8//!
9//! Premix is a zero-overhead, type-safe ORM for Rust. It generates SQL at
10//! compile time with macros and executes via `sqlx`.
11//!
12//! ## Key Features
13//!
14//! - Auto-sync schema from models.
15//! - Compile-time SQL generation (no runtime reflection).
16//! - Application-level joins with batched `WHERE IN` queries.
17//! - SQLite, Postgres, and MySQL support via `sqlx`.
18//!
19//! ## Quick Start
20//!
21//! ```rust,no_run
22//! use premix_orm::prelude::*;
23//! use serde::{Deserialize, Serialize};
24//!
25//! #[derive(Model, Debug, Serialize, Deserialize)]
26//! struct User {
27//! id: i32,
28//! name: String,
29//! }
30//!
31//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
32//! let pool = Premix::smart_sqlite_pool("sqlite::memory:").await?;
33//! premix_orm::Premix::sync::<premix_orm::sqlx::Sqlite, User>(&pool).await?;
34//!
35//! let mut user = User { id: 0, name: "Alice".to_string() };
36//! user.save(&pool).await?;
37//! # Ok(())
38//! # }
39//! ```
40//!
41//! ## Relations and Eager Loading
42//!
43//! ```rust,no_run
44//! use premix_orm::prelude::*;
45//!
46//! #[derive(Model)]
47//! struct User {
48//! id: i32,
49//! name: String,
50//!
51//! #[has_many(Post)]
52//! #[premix(ignore)]
53//! posts: Option<Vec<Post>>,
54//! }
55//!
56//! #[derive(Model)]
57//! #[belongs_to(User)]
58//! struct Post {
59//! id: i32,
60//! user_id: i32,
61//! title: String,
62//! }
63//!
64//! # async fn example(pool: premix_orm::sqlx::SqlitePool) -> Result<(), sqlx::Error> {
65//! let _users = User::find_in_pool(&pool).include("posts").all().await?;
66//! # Ok(())
67//! # }
68//! ```
69//!
70//! ## Bulk Operations
71//!
72//! ```rust,no_run
73//! use premix_orm::prelude::*;
74//! use serde_json::json;
75//!
76//! #[derive(Model)]
77//! struct User {
78//! id: i32,
79//! status: String,
80//! }
81//!
82//! # async fn example(pool: premix_orm::sqlx::SqlitePool) -> Result<(), sqlx::Error> {
83//! let _updated = User::find_in_pool(&pool)
84//! .filter_eq("status", "inactive")
85//! .update(json!({ "status": "active" }))
86//! .await?;
87//! # Ok(())
88//! # }
89//! ```
90//!
91//! ## Installation
92//!
93//! ```toml
94//! [dependencies]
95//! premix-orm = "1.0.8-alpha"
96//! ```
97//!
98//! ## Book
99//!
100//! A longer-form guide lives in `orm-book/` at the repository root. It covers
101//! models, queries, relations, migrations, transactions, and limitations.
102
103pub use premix_core::schema_models;
104pub use premix_core::*;
105pub use premix_macros::Model;
106/// Compile-time query macro for true Zero-Overhead SQL generation.
107///
108/// This macro generates SQL at compile time, achieving 0% overhead compared to raw sqlx.
109///
110/// # Example
111///
112/// ```ignore
113/// use premix_orm::prelude::*;
114///
115/// let user = premix_query!(User, FIND, filter_eq("id", user_id))
116/// .fetch_one(&pool)
117/// .await?;
118/// ```
119pub use premix_macros::premix_query;
120
121/// Integration with common web frameworks (Axum, Actix, etc.).
122pub mod integrations;
123
124#[cfg(feature = "axum")]
125pub use integrations::axum::*;
126
127#[cfg(feature = "actix")]
128pub use integrations::actix::*;
129
130/// The Premix prelude, re-exporting commonly used traits and types.
131pub mod prelude {
132 pub use premix_core::prelude::*;
133
134 pub use crate::Model; // The macro
135 pub use crate::premix_query; // Zero-overhead compile-time query macro
136 pub use crate::schema_models;
137}