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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! 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;
/// Names the accessor that loads this table's rows from the referenced table
/// (the reverse relation).
///
/// By default it is the plural of this struct's name (`posts` for a `Post`
/// table), or the singular when this column alone is unique, which loads an
/// `Option` (`profile` for a `Profile` table). A column named for a role
/// rather than the table it references starts the name with the role:
/// `author_id` gives `users.author_posts()`, while `user_id` gives
/// `users.posts()`. The name depends on this column alone, so `RELATION` is needed
/// only to choose another one.
///
/// The forward relation (on this table) is unchanged; only the reverse
/// accessor on the referenced table is renamed.
///
/// # Examples
/// ```rust
/// # let _ = r####"
/// // Users get `.authored()` instead of `.author_posts()`
/// #[column(REFERENCES = User::id, RELATION = "authored")]
/// author_id: u64,
/// # "####;
/// ```
///
/// Requires a `REFERENCES` attribute on the same column.
pub const RELATION: AttributeMarker = AttributeMarker;
/// Names the many-to-many accessor the referenced table gets through this
/// link table.
///
/// A table is a link table when it has exactly two foreign keys and its rows
/// are that pair: the pair is the primary key or a `UNIQUE` constraint, or
/// the table has no other column besides a single-column primary key, and
/// neither key is unique on its own. Each referenced table then gets an
/// accessor to the other one, named after the other column: `post_id` and
/// `tag_id` in `PostTags` give `posts.tags()` and `tags.posts()`. A link whose
/// name adds to what it links appends it, so `PostLikes` gives
/// `users.posts_via_likes()` and never clashes with another link.
///
/// `MANY_TO_MANY` chooses another name, and makes any table with two foreign keys a
/// link table.
///
/// # Examples
/// ```rust
/// # let _ = r####"
/// // users.liked_posts() instead of users.posts_via_likes()
/// #[column(REFERENCES = User::id, MANY_TO_MANY = "liked_posts")]
/// user_id: u64,
/// # "####;
/// ```
///
/// Requires a `REFERENCES` attribute on the same column.
pub const MANY_TO_MANY: AttributeMarker = AttributeMarker;
markers!;