1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! A zero cost and lightweight ORM operations for SQLx.
//!
//! Lorm generates type-safe database operations at compile time using derive macros.
//!
//! # Installation
//!
//! Add the following to your project's `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! lorm = { version = "0.2" }
//! sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite"] }
//! ```
//!
//! # Quick Example
//!
//! ```ignore
//! use lorm::ToLOrm;
//! use lorm::predicates::Where;
//! use sqlx::{FromRow, SqlitePool};
//!
//! #[derive(Debug, Default, Clone, FromRow, ToLOrm)]
//! struct User {
//! #[lorm(pk)]
//! #[lorm(readonly)]
//! pub id: i32,
//!
//! #[lorm(by)]
//! pub email: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let pool = SqlitePool::connect("sqlite::memory:").await?;
//!
//! // Create a user
//! let mut user = User::default();
//! user.email = "alice@example.com".to_string();
//! let user = user.save(&pool).await?;
//!
//! // Find by field (generated from #[lorm(by)])
//! let found = User::by_email(&pool, "alice@example.com").await?;
//!
//! // Query with filtering and pagination
//! let users = User::select()
//! .where_email(Where::Eq, "alice@example.com")
//! .order_by_email()
//! .desc()
//! .limit(10)
//! .build(&pool)
//! .await?;
//!
//! // Delete the user
//! user.delete(&pool).await?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Generated Methods
//!
//! For a struct with `#[derive(ToLOrm)]`, Lorm generates:
//!
//! - `save(&executor)` - Insert or update (upsert)
//! - `delete(&executor)` - Delete by primary key
//! - `by_{field}(&executor, value)` - Find one by field (for `#[lorm(by)]` fields)
//! - `with_{field}(&executor, value)` - Find all by field (for `#[lorm(by)]` fields)
//! - `select()` - Start a query builder
//!
//! # Query Builder
//!
//! The `select()` method returns a builder with these methods:
//!
//! - `where_{field}(Where::Eq, value)` - Filter by comparison
//! - `where_between_{field}(start, end)` - Filter by range
//! - `order_by_{field}()` - Add ordering (chain with `.asc()` or `.desc()`)
//! - `group_by_{field}()` - Group results
//! - `limit(n)` / `offset(n)` - Pagination
//! - `build(&executor)` - Execute and return results
pub use ToLOrm;