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
use super::*;
impl Delete {
/// Creates a delete statement for a table or view source.
pub(crate) fn from(target: impl Into<Source>) -> Self {
Self {
ctes: Vec::new(),
target: target.into(),
using: Vec::new(),
filter: None,
returning: Vec::new(),
}
}
/// Adds a CTE to the delete statement.
#[inline]
pub fn with(mut self, cte: Cte) -> Self {
self.ctes.push(cte);
self
}
/// Adds a `USING` source.
pub fn using(mut self, source: impl Into<Source>) -> Self {
self.using.push(source.into());
self
}
/// Adds one or more fields to `RETURNING`.
///
/// Use a field for one returned column or tuple syntax for a small
/// heterogeneous field list: `.returning((users::ID, users::EMAIL))`.
pub fn returning(mut self, fields: impl IntoColumns) -> Self {
self.returning.extend(fields.into_columns().items);
self
}
/// Adds an aliased expression to `RETURNING`.
pub fn returning_as(mut self, expr: impl Into<ValueExpr>, alias: impl Into<String>) -> Self {
self.returning.push(SelectItem {
expr: expr.into(),
alias: Some(alias.into()),
});
self
}
/// Replaces `RETURNING` with every field exposed by the target source.
#[inline]
pub fn returning_all(mut self) -> Self {
self.returning.clear();
push_all_source_fields(&self.target, &mut self.returning);
self
}
}
impl_filter_methods!(Delete);