diesel/query_builder/update_statement/
target.rs1use crate::associations::{HasTable, Identifiable};
2use crate::dsl::Find;
3use crate::query_dsl::methods::FindDsl;
4use crate::query_source::Table;
5
6#[doc(hidden)]
7#[derive(Debug)]
8pub struct UpdateTarget<Table, WhereClause> {
9 pub table: Table,
10 pub where_clause: WhereClause,
11}
12
13#[diagnostic::on_unimplemented(
29 note = "only tables or select statements with only the filter clause applied are valid update targets"
30)]
31pub trait IntoUpdateTarget: HasTable {
32 type WhereClause;
34
35 fn into_update_target(self) -> UpdateTarget<Self::Table, Self::WhereClause>;
37}
38
39impl<T, Tab, V> IntoUpdateTarget for T
40where
41 T: Identifiable<Table = Tab>,
42 Tab: Table + FindDsl<T::Id>,
43 Find<Tab, T::Id>: IntoUpdateTarget<Table = Tab, WhereClause = V>,
44{
45 type WhereClause = V;
46
47 fn into_update_target(self) -> UpdateTarget<Self::Table, Self::WhereClause> {
48 T::table().find(self.id()).into_update_target()
49 }
50}