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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Names accepted inside `#[MySQLTable(...)]`, `#[column(...)]`,
//! `#[MySQLView(...)]` and `#[MySQLIndex(...)]`.
//!
//! The macros read these attributes by name before type checking. The
//! constants here exist so your editor can resolve each attribute and show
//! its documentation on hover; import them through the prelude. They carry
//! no runtime state.
/// The type of every attribute constant in this module.
;
/// Adds a `DEFAULT` clause to the column, so `MySQL` fills it when an insert
/// leaves it out.
///
/// String literals become quoted SQL values. SQL keywords and function calls
/// are written as SQL expressions.
pub const DEFAULT: AttributeMarker = AttributeMarker;
/// Generates a value in Rust for each insert that leaves the column unset.
///
/// This does not add a database `DEFAULT` clause.
pub const DEFAULT_FN: AttributeMarker = AttributeMarker;
/// Declares a foreign key to another table's column.
///
/// ```rust
/// # let _ = r####"
/// #[column(REFERENCES = User::id)]
/// user_id: u64,
/// # "####;
/// ```
///
/// With the `query` feature this also generates relation accessors: a
/// forward one on this table, named after the column without its `_id` suffix
/// (`user_id` gives `.user()`), and a reverse one on the referenced table
/// (see [`RELATION`]).
pub const REFERENCES: AttributeMarker = AttributeMarker;
/// Sets the reverse relation accessor name on the referenced table.
///
/// By default, reverse relations are named from the referencing struct
/// (`posts` for a `Post` table). When several foreign keys target the same
/// table, or the foreign key is self-referential, the name is disambiguated as
/// `{forward}_{plural}` (e.g. `author_posts`). Use `RELATION` to pick an
/// explicit reverse name instead; it is required only when two reverse names
/// would still collide.
///
/// The forward relation (on this table) is unchanged; only the reverse
/// accessor on the referenced table is renamed.
///
/// ```rust
/// # let _ = r####"
/// // Users get `.authored()` instead of `.author_posts()`
/// #[column(REFERENCES = User::id, RELATION = "authored")]
/// author_id: u64,
///
/// // Still auto-disambiguated: Users get `.editor_posts()`
/// #[column(REFERENCES = User::id)]
/// editor_id: Option<u64>,
/// # "####;
/// ```
///
/// Requires a `REFERENCES` attribute on the same column.
pub const RELATION: AttributeMarker = AttributeMarker;
markers!;