1use crate::expression::operators::Concat;
2use crate::mysql_like::MysqlLikeBackend;
3use crate::query_builder::insert_statement::DefaultValues;
4use crate::query_builder::locking_clause::{ForShare, ForUpdate, NoModifier, NoWait, SkipLocked};
5use crate::query_builder::nodes::StaticQueryFragment;
6use crate::query_builder::upsert::into_conflict_clause::OnConflictSelectWrapper;
7use crate::query_builder::upsert::on_conflict_actions::{DoNothing, DoUpdate};
8use crate::query_builder::upsert::on_conflict_clause::OnConflictValues;
9use crate::query_builder::upsert::on_conflict_target::{ConflictTarget, OnConflictTarget};
10use crate::query_builder::where_clause::NoWhereClause;
11use crate::query_builder::{AstPass, QueryFragment};
12use crate::result::QueryResult;
13use crate::{Column, Table};
14
15#[diagnostic::do_not_recommend]
16impl<DB: MysqlLikeBackend> QueryFragment<DB> for ForUpdate {
17 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
18 out.push_sql(" FOR UPDATE");
19 Ok(())
20 }
21}
22
23#[diagnostic::do_not_recommend]
24impl<DB: MysqlLikeBackend> QueryFragment<DB> for ForShare {
25 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
26 out.push_sql(" FOR SHARE");
27 Ok(())
28 }
29}
30
31#[diagnostic::do_not_recommend]
32impl<DB: MysqlLikeBackend> QueryFragment<DB> for NoModifier {
33 fn walk_ast<'b>(&'b self, _out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
34 Ok(())
35 }
36}
37
38#[diagnostic::do_not_recommend]
39impl<DB: MysqlLikeBackend> QueryFragment<DB> for SkipLocked {
40 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
41 out.push_sql(" SKIP LOCKED");
42 Ok(())
43 }
44}
45
46#[diagnostic::do_not_recommend]
47impl<DB: MysqlLikeBackend> QueryFragment<DB> for NoWait {
48 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
49 out.push_sql(" NOWAIT");
50 Ok(())
51 }
52}
53
54#[diagnostic::do_not_recommend]
55impl<DB: MysqlLikeBackend>
56 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlStyleDefaultValueClause>
57 for DefaultValues
58{
59 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
60 out.push_sql("() VALUES ()");
61 Ok(())
62 }
63}
64
65#[diagnostic::do_not_recommend]
66impl<DB: MysqlLikeBackend, L, R>
67 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlConcatClause> for Concat<L, R>
68where
69 L: QueryFragment<DB>,
70 R: QueryFragment<DB>,
71{
72 fn walk_ast<'b>(
73 &'b self,
74 mut out: crate::query_builder::AstPass<'_, 'b, DB>,
75 ) -> crate::result::QueryResult<()> {
76 out.push_sql("CONCAT(");
77 self.left.walk_ast(out.reborrow())?;
78 out.push_sql(",");
79 self.right.walk_ast(out.reborrow())?;
80 out.push_sql(")");
81 Ok(())
82 }
83}
84
85#[diagnostic::do_not_recommend]
86impl<DB: MysqlLikeBackend, T>
87 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlOnConflictClause> for DoNothing<T>
88where
89 T: Table + StaticQueryFragment,
90 T::Component: QueryFragment<DB>,
91 T::PrimaryKey: DoNothingClauseHelper<DB>,
92{
93 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
94 out.push_sql(" UPDATE ");
95 T::PrimaryKey::walk_ast::<T>(out.reborrow())?;
96 Ok(())
97 }
98}
99
100#[diagnostic::do_not_recommend]
101impl<DB: MysqlLikeBackend, T, Tab>
102 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlOnConflictClause>
103 for DoUpdate<T, Tab>
104where
105 T: QueryFragment<DB>,
106 Tab: Table + StaticQueryFragment,
107 Tab::PrimaryKey: DoNothingClauseHelper<DB>,
108 Tab::Component: QueryFragment<DB>,
109{
110 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
111 out.unsafe_to_cache_prepared();
112 out.push_sql(" UPDATE ");
113 if self.changeset.is_noop(out.backend())? {
114 Tab::PrimaryKey::walk_ast::<Tab>(out.reborrow())?;
115 } else {
116 self.changeset.walk_ast(out.reborrow())?;
117 }
118 Ok(())
119 }
120}
121
122#[diagnostic::do_not_recommend]
123impl<DB: MysqlLikeBackend, Values, Target, Action>
124 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlOnConflictClause>
125 for OnConflictValues<Values, Target, Action, NoWhereClause>
126where
127 Values: QueryFragment<DB>,
128 Target: QueryFragment<DB>,
129 Action: QueryFragment<DB>,
130 NoWhereClause: QueryFragment<DB>,
131{
132 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
133 self.values.walk_ast(out.reborrow())?;
134 out.push_sql(" ON DUPLICATE KEY");
135 self.target.walk_ast(out.reborrow())?;
136 self.action.walk_ast(out.reborrow())?;
137 self.where_clause.walk_ast(out)?;
138 Ok(())
139 }
140}
141
142#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DuplicatedKeys {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "DuplicatedKeys")
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for DuplicatedKeys { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DuplicatedKeys {
#[inline]
fn clone(&self) -> DuplicatedKeys { *self }
}Clone)]
149pub struct DuplicatedKeys;
150
151impl<Tab> OnConflictTarget<Tab> for ConflictTarget<DuplicatedKeys> {}
152
153#[diagnostic::do_not_recommend]
154impl<DB: MysqlLikeBackend>
155 QueryFragment<DB, crate::mysql_like::query_fragments::MysqlOnConflictClause>
156 for ConflictTarget<DuplicatedKeys>
157{
158 fn walk_ast<'b>(&'b self, _out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
159 Ok(())
160 }
161}
162
163#[diagnostic::do_not_recommend]
164impl<DB: MysqlLikeBackend, S> QueryFragment<DB> for OnConflictSelectWrapper<S>
165where
166 S: QueryFragment<DB>,
167{
168 fn walk_ast<'b>(&'b self, out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
169 self.0.walk_ast(out)
170 }
171}
172
173trait DoNothingClauseHelper<DB: MysqlLikeBackend> {
178 fn walk_ast<T>(out: AstPass<'_, '_, DB>) -> QueryResult<()>
179 where
180 T: StaticQueryFragment,
181 T::Component: QueryFragment<DB>;
182}
183
184#[diagnostic::do_not_recommend]
185impl<DB: MysqlLikeBackend, C> DoNothingClauseHelper<DB> for C
186where
187 C: Column,
188{
189 fn walk_ast<T>(mut out: AstPass<'_, '_, DB>) -> QueryResult<()>
190 where
191 T: StaticQueryFragment,
192 T::Component: QueryFragment<DB>,
193 {
194 T::STATIC_COMPONENT.walk_ast(out.reborrow())?;
195 out.push_sql(".");
196 out.push_identifier(C::NAME)?;
197 out.push_sql(" = ");
198 T::STATIC_COMPONENT.walk_ast(out.reborrow())?;
199 out.push_sql(".");
200 out.push_identifier(C::NAME)?;
201 Ok(())
202 }
203}
204
205macro_rules! do_nothing_for_composite_keys {
206 ($(
207 $Tuple:tt {
208 $(($idx:tt) -> $T:ident, $ST:ident, $TT:ident,)+
209 }
210 )+) => {
211 $(
212 impl<DB: MysqlLikeBackend,$($T,)*> DoNothingClauseHelper<DB> for ($($T,)*)
213 where $($T: Column,)*
214 {
215 fn walk_ast<Table>(mut out: AstPass<'_, '_, DB>) -> QueryResult<()>
216 where
217 Table: StaticQueryFragment,
218 Table::Component: QueryFragment<DB>,
219 {
220 let mut first = true;
221 $(
222 #[allow(unused_assignments)]
223 if first {
224 first = false;
225 } else {
226 out.push_sql(", ");
227 }
228 Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
229 out.push_sql(".");
230 out.push_identifier($T::NAME)?;
231 out.push_sql(" = ");
232 Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
233 out.push_sql(".");
234 out.push_identifier($T::NAME)?;
235 )*
236 Ok(())
237 }
238 }
239 )*
240 }
241}
242
243impl<DB: MysqlLikeBackend, T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
T27, T28, T29, T30, T31> DoNothingClauseHelper<DB> for
(T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16,
T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31)
where T: Column, T1: Column, T2: Column, T3: Column, T4: Column,
T5: Column, T6: Column, T7: Column, T8: Column, T9: Column, T10: Column,
T11: Column, T12: Column, T13: Column, T14: Column, T15: Column,
T16: Column, T17: Column, T18: Column, T19: Column, T20: Column,
T21: Column, T22: Column, T23: Column, T24: Column, T25: Column,
T26: Column, T27: Column, T28: Column, T29: Column, T30: Column,
T31: Column {
fn walk_ast<Table>(mut out: AstPass<'_, '_, DB>) -> QueryResult<()> where
Table: StaticQueryFragment, Table::Component: QueryFragment<DB> {
let mut first = true;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T1::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T1::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T2::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T2::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T3::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T3::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T4::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T4::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T5::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T5::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T6::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T6::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T7::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T7::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T8::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T8::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T9::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T9::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T10::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T10::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T11::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T11::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T12::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T12::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T13::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T13::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T14::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T14::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T15::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T15::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T16::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T16::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T17::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T17::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T18::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T18::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T19::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T19::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T20::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T20::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T21::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T21::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T22::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T22::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T23::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T23::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T24::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T24::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T25::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T25::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T26::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T26::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T27::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T27::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T28::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T28::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T29::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T29::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T30::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T30::NAME)?;
#[allow(unused_assignments)]
if first { first = false; } else { out.push_sql(", "); }
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T31::NAME)?;
out.push_sql(" = ");
Table::STATIC_COMPONENT.walk_ast(out.reborrow())?;
out.push_sql(".");
out.push_identifier(T31::NAME)?;
Ok(())
}
}crate::for_each_tuple!(do_nothing_for_composite_keys);