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
use backend::Backend;
use expression::operators::Eq;
use expression::AppearsOnTable;
use query_builder::*;
use query_source::{Column, QuerySource};
use result::QueryResult;
pub trait AsChangeset {
type Target: QuerySource;
type Changeset;
fn as_changeset(self) -> Self::Changeset;
}
impl<T: AsChangeset> AsChangeset for Option<T> {
type Target = T::Target;
type Changeset = Option<T::Changeset>;
fn as_changeset(self) -> Self::Changeset {
self.map(|v| v.as_changeset())
}
}
impl<Left, Right> AsChangeset for Eq<Left, Right>
where
Left: Column,
Right: AppearsOnTable<Left::Table>,
{
type Target = Left::Table;
type Changeset = Assign<Left, Right>;
fn as_changeset(self) -> Self::Changeset {
Assign {
_column: self.left,
expr: self.right,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct Assign<Col, Expr> {
_column: Col,
expr: Expr,
}
impl<T, U, DB> QueryFragment<DB> for Assign<T, U>
where
DB: Backend,
T: Column,
U: QueryFragment<DB>,
{
fn walk_ast(&self, mut out: AstPass<DB>) -> QueryResult<()> {
out.push_identifier(T::NAME)?;
out.push_sql(" = ");
QueryFragment::walk_ast(&self.expr, out)
}
}