premix_orm/lib.rs
1//! # Premix ORM
2//!
3//! > **"Write Rust, Run Optimized SQL."**
4//!
5//! Premix is a zero-overhead, type-safe ORM for Rust. It generates SQL at
6//! compile time with macros and executes via `sqlx`.
7//!
8//! ## Key Features
9//!
10//! - Auto-sync schema from models.
11//! - Compile-time SQL generation (no runtime reflection).
12//! - Application-level joins with batched `WHERE IN` queries.
13//! - SQLite, Postgres, and MySQL support via `sqlx`.
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! use premix_orm::prelude::*;
19//! use serde::{Deserialize, Serialize};
20//!
21//! #[derive(Model, Debug, Serialize, Deserialize)]
22//! struct User {
23//! id: i32,
24//! name: String,
25//! }
26//!
27//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
28//! let pool = premix_orm::sqlx::SqlitePool::connect("sqlite::memory:").await?;
29//! premix_orm::Premix::sync::<premix_orm::sqlx::Sqlite, User>(&pool).await?;
30//!
31//! let mut user = User { id: 0, name: "Alice".to_string() };
32//! user.save(&pool).await?;
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! ## Relations and Eager Loading
38//!
39//! ```rust,no_run
40//! use premix_orm::prelude::*;
41//!
42//! #[derive(Model)]
43//! struct User {
44//! id: i32,
45//! name: String,
46//!
47//! #[has_many(Post)]
48//! #[premix(ignore)]
49//! posts: Option<Vec<Post>>,
50//! }
51//!
52//! #[derive(Model)]
53//! #[belongs_to(User)]
54//! struct Post {
55//! id: i32,
56//! user_id: i32,
57//! title: String,
58//! }
59//!
60//! # async fn example(pool: premix_orm::sqlx::SqlitePool) -> Result<(), sqlx::Error> {
61//! let _users = User::find_in_pool(&pool).include("posts").all().await?;
62//! # Ok(())
63//! # }
64//! ```
65//!
66//! ## Bulk Operations
67//!
68//! ```rust,no_run
69//! use premix_orm::prelude::*;
70//! use serde_json::json;
71//!
72//! #[derive(Model)]
73//! struct User {
74//! id: i32,
75//! status: String,
76//! }
77//!
78//! # async fn example(pool: premix_orm::sqlx::SqlitePool) -> Result<(), sqlx::Error> {
79//! let _updated = User::find_in_pool(&pool)
80//! .filter("status = 'inactive'")
81//! .update(json!({ "status": "active" }))
82//! .await?;
83//! # Ok(())
84//! # }
85//! ```
86//!
87//! ## Installation
88//!
89//! ```toml
90//! [dependencies]
91//! premix-orm = "1.0.5"
92//! ```
93//!
94//! ## Book
95//!
96//! A longer-form guide lives in `orm-book/` at the repository root. It covers
97//! models, queries, relations, migrations, transactions, and limitations.
98
99pub use premix_core::*;
100pub use premix_macros::Model;
101
102pub mod prelude {
103 pub use premix_core::prelude::*;
104
105 pub use crate::Model; // The macro // The traits and other core items
106}