diesel/sqlite/query_builder/
query_fragment_impls.rs

1use crate::query_builder::select_statement::boxed::BoxedQueryHelper;
2use crate::query_builder::upsert::into_conflict_clause::OnConflictSelectWrapper;
3use crate::query_builder::where_clause::BoxedWhereClause;
4use crate::query_builder::where_clause::WhereClause;
5use crate::query_builder::AstPass;
6use crate::query_builder::BoxedSelectStatement;
7use crate::query_builder::QueryFragment;
8use crate::query_builder::SelectStatement;
9use crate::QueryResult;
10
11// The corresponding impl for`NoWhereClause` is missing because of
12// https://www.sqlite.org/lang_UPSERT.html (Parsing Ambiguity)
13#[cfg(feature = "sqlite")]
14impl<F, S, D, W, O, LOf, G, H, LC> QueryFragment<crate::sqlite::Sqlite>
15    for OnConflictSelectWrapper<SelectStatement<F, S, D, WhereClause<W>, O, LOf, G, H, LC>>
16where
17    SelectStatement<F, S, D, WhereClause<W>, O, LOf, G, H, LC>:
18        QueryFragment<crate::sqlite::Sqlite>,
19{
20    fn walk_ast<'b>(&'b self, out: AstPass<'_, 'b, crate::sqlite::Sqlite>) -> QueryResult<()> {
21        self.0.walk_ast(out)
22    }
23}
24
25#[cfg(feature = "sqlite")]
26impl<'a, ST, QS, GB> QueryFragment<crate::sqlite::Sqlite>
27    for OnConflictSelectWrapper<BoxedSelectStatement<'a, ST, QS, crate::sqlite::Sqlite, GB>>
28where
29    BoxedSelectStatement<'a, ST, QS, crate::sqlite::Sqlite, GB>:
30        QueryFragment<crate::sqlite::Sqlite>,
31    QS: QueryFragment<crate::sqlite::Sqlite>,
32{
33    fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, crate::sqlite::Sqlite>) -> QueryResult<()> {
34        // https://www.sqlite.org/lang_UPSERT.html (Parsing Ambiguity)
35        self.0.build_query(pass, |where_clause, mut pass| {
36            match where_clause {
37                BoxedWhereClause::None => pass.push_sql(" WHERE 1=1 "),
38                w => w.walk_ast(pass.reborrow())?,
39            }
40            Ok(())
41        })
42    }
43}