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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Declarative macros for the SQL module.
//!
//! Only [`crate::table!`] for now — it's exported at the crate root (the
//! `#[macro_export]` attribute pins it there). Users invoke it as
//! `linq_rs_sql::table! { ... }` from anywhere.
/// Declare a SQL table with typed columns.
///
/// # Syntax
///
/// ```text
/// table! {
/// table_name (primary_key_col [, more_pk_cols ...]) {
/// col_name -> SqlType,
/// ...
/// }
/// }
/// ```
///
/// `SqlType` is one of the markers exported from [`crate::types`]:
/// `Integer`, `Text`, `Boolean`, `Float`.
///
/// # Generated items
///
/// The macro expands into a `pub mod <table_name>` containing:
///
/// - A `Marker` zero-sized type implementing [`Table`](crate::Table) —
/// the type-level identity of the table.
/// - One zero-sized type per column (lowercase, matching the column name)
/// implementing [`Column`](crate::Column) and
/// [`Expr`](crate::Expr). Because they're unit structs, the lowercase
/// name doubles as both a type and a value.
/// - A `table()` constructor returning a fresh
/// [`Query`](crate::Query) seeded with `SELECT *`.
///
/// # Example
///
/// ```rust
/// use linq_rs_sql::*;
///
/// linq_rs_sql::table! {
/// users (id) {
/// id -> Integer,
/// name -> Text,
/// age -> Integer,
/// active -> Boolean,
/// }
/// }
///
/// let q = users::table()
/// .filter(users::age.gt(18))
/// .filter(users::active.eq(true))
/// .select((users::id, users::name))
/// .order_by_desc(users::age)
/// .limit(10)
/// .to_sql();
///
/// assert!(q.sql.contains("FROM users"));
/// assert!(q.sql.contains("WHERE"));
/// assert_eq!(q.params.len(), 2);
/// ```
;
/// Type-level marker for this table.
;
$+
/// Primary key column names. Reserved for future
/// `INSERT`/`UPDATE`/`DELETE` builders; unused in Phase 1.
pub const PRIMARY_KEY: & = &;
/// Begin a new query against this table. `SELECT *` is the
/// default projection — call `.select(...)` to narrow it.
}
};
}