diesel/query_builder/upsert/
into_conflict_clause.rs

1use crate::query_builder::insert_statement::{BatchInsert, InsertFromSelect};
2use crate::query_builder::{BoxedSelectStatement, Query, SelectStatement, ValuesClause};
3
4pub trait IntoConflictValueClause {
5    type ValueClause;
6
7    fn into_value_clause(self) -> Self::ValueClause;
8}
9
10#[derive(Debug, Clone, Copy)]
11pub struct OnConflictSelectWrapper<S>(pub(crate) S);
12
13impl<Q> Query for OnConflictSelectWrapper<Q>
14where
15    Q: Query,
16{
17    type SqlType = Q::SqlType;
18}
19
20impl<Inner, Tab> IntoConflictValueClause for ValuesClause<Inner, Tab> {
21    type ValueClause = Self;
22
23    fn into_value_clause(self) -> Self::ValueClause {
24        self
25    }
26}
27
28impl<V, Tab, QId, const STATIC_QUERY_ID: bool> IntoConflictValueClause
29    for BatchInsert<V, Tab, QId, STATIC_QUERY_ID>
30{
31    type ValueClause = Self;
32
33    fn into_value_clause(self) -> Self::ValueClause {
34        self
35    }
36}
37
38impl<F, S, D, W, O, LOf, G, H, LC, Columns> IntoConflictValueClause
39    for InsertFromSelect<SelectStatement<F, S, D, W, O, LOf, G, H, LC>, Columns>
40{
41    type ValueClause = InsertFromSelect<
42        OnConflictSelectWrapper<SelectStatement<F, S, D, W, O, LOf, G, H, LC>>,
43        Columns,
44    >;
45
46    fn into_value_clause(self) -> Self::ValueClause {
47        let InsertFromSelect { columns, query } = self;
48        InsertFromSelect {
49            query: OnConflictSelectWrapper(query),
50            columns,
51        }
52    }
53}
54
55impl<'a, ST, QS, DB, GB, Columns> IntoConflictValueClause
56    for InsertFromSelect<BoxedSelectStatement<'a, ST, QS, DB, GB>, Columns>
57{
58    type ValueClause = InsertFromSelect<
59        OnConflictSelectWrapper<BoxedSelectStatement<'a, ST, QS, DB, GB>>,
60        Columns,
61    >;
62
63    fn into_value_clause(self) -> Self::ValueClause {
64        let InsertFromSelect { columns, query } = self;
65        InsertFromSelect {
66            query: OnConflictSelectWrapper(query),
67            columns,
68        }
69    }
70}