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
use ;
use PhantomData;
use stmt;
/// Apply a field mutation to an update statement's [`Assignments`] map.
///
/// This trait is used for field types where the mutation semantics are
/// ambiguous from a plain value alone — primarily **has-many** collection
/// fields. For these fields, callers must use an explicit combinator
/// ([`insert`], [`remove`], or [`set`]) to specify the intent.
///
/// Scalar fields continue to accept `impl IntoExpr<T>` directly (a plain
/// value means "set"). Only collection setters use `Assign`.
///
/// Arrays and [`Vec`]s of assignments implement `Assign<T>` when their
/// elements do, allowing multiple operations in a single setter call:
///
/// ```ignore
/// user.update()
/// .todos([
/// stmt::insert(Todo::create().title("Buy groceries")),
/// stmt::insert(Todo::create().title("Walk the dog")),
/// stmt::remove(&old_todo),
/// ])
/// .exec(&mut db)
/// .await?;
/// ```
/// A typed assignment produced by the [`insert`], [`remove`], and [`set`]
/// combinators.
///
/// `Assignment<T>` implements `Assign<T>`, so it can be passed directly
/// to any update builder setter that accepts `impl Assign<T>`.
// Assignment<T> implements Assign<T>
// Arrays of assignments: [Q; N] implements Assign<T> when Q does.
// Vec of assignments
/// Insert a value into a collection field.
///
/// Takes an expression of `T` (a single item) and produces an assignment for
/// `List<T>` (the collection). The returned [`Assignment`] can be passed to any
/// update builder setter that accepts `impl Assign<List<T>>`.
///
/// [`Assignments`]: toasty_core::stmt::Assignments
///
/// # Examples
///
/// ```ignore
/// user.update()
/// .todos(stmt::insert(Todo::create().title("Buy groceries")))
/// .exec(&mut db)
/// .await?;
/// ```
/// Remove a value from a collection field.
///
/// Takes an expression of `T` (the item to remove) and produces an assignment
/// for `List<T>` (the collection).
///
/// What "remove" means depends on the belongs-to side of the relationship:
/// - **Optional foreign key**: The foreign key is set to `NULL`.
/// - **Required foreign key**: The related record is deleted.
///
/// # Examples
///
/// ```ignore
/// user.update()
/// .todos(stmt::remove(&todo_a))
/// .exec(&mut db)
/// .await?;
/// ```
/// Replace a field's value entirely.
///
/// For collection fields, `set` replaces the entire collection: all current
/// members are disassociated (following the same optional/required foreign key
/// rules as [`remove`]), then the new set is associated.
///
/// Pass an empty slice to clear the collection:
///
/// ```ignore
/// user.update()
/// .todos(stmt::set::<List<Todo>>([]))
/// .exec(&mut db)
/// .await?;
/// ```
///
/// For scalar fields, `set` is equivalent to passing a plain value (the
/// setter already defaults to set semantics).
///
/// # Examples
///
/// ```ignore
/// // Replace all todos
/// user.update()
/// .todos(stmt::set([
/// Todo::create().title("Only todo"),
/// ]))
/// .exec(&mut db)
/// .await?;
/// ```