diesel/mariadb/returning/
old_impl.rs1use crate::deserialize::SqlTypeLikeMarker;
4use crate::expression::subselect::SubselectGroupBy;
5use crate::expression::{
6 AppearsOnTable, Expression, QueryMetadata, SelectableExpression, TypedExpressionType,
7 ValidGrouping, is_aggregate,
8};
9use crate::mariadb::Mariadb;
10use crate::query_builder::returning::{OldIdent, ReturningQuerySource, UpdateStmt};
11use crate::query_builder::{AstPass, QueryFragment, QueryId};
12use crate::query_dsl::load_dsl::CompatibleType;
13use crate::query_source::{AppearsInFromClause, Column};
14use crate::result::QueryResult;
15use crate::sql_types::{IntoNotNullable, IntoNullable, SingleValue};
16use crate::util::TupleSize;
17use core::marker::PhantomData;
18
19#[derive(#[automatically_derived]
impl<C: ::core::fmt::Debug> ::core::fmt::Debug for OldValue<C> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "OldValue",
"_column", &&self._column)
}
}Debug, #[automatically_derived]
impl<C: ::core::clone::Clone> ::core::clone::Clone for OldValue<C> {
#[inline]
fn clone(&self) -> Self {
Self { _column: ::core::clone::Clone::clone(&self._column) }
}
}Clone, #[automatically_derived]
impl<C: ::core::marker::Copy> ::core::marker::Copy for OldValue<C> { }Copy, const _: () =
{
use diesel;
#[allow(non_camel_case_types)]
impl<C: diesel::query_builder::QueryId> diesel::query_builder::QueryId
for OldValue<C> {
type QueryId =
OldValue<<C as diesel::query_builder::QueryId>::QueryId>;
const HAS_STATIC_QUERY_ID: bool =
<C as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
true;
const IS_WINDOW_FUNCTION: bool =
<C as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
false;
}
};QueryId)]
24pub struct OldValue<C> {
25 _column: C,
26}
27
28impl<C> OldValue<C> {
29 pub(crate) fn new(c: C) -> Self {
30 OldValue { _column: c }
31 }
32}
33
34pub fn old_value<C: Column>(col: C) -> old_value<C> {
84 OldValue::new(col)
85}
86
87impl<C> Expression for OldValue<C>
88where
89 C: Column + Expression,
90 C::SqlType: SingleValue,
91{
92 type SqlType = OldValueOf<C::SqlType>;
93}
94
95#[derive(#[automatically_derived]
impl<ST: ::core::fmt::Debug> ::core::fmt::Debug for OldValueOf<ST> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "OldValueOf",
&&self.0)
}
}Debug, #[automatically_derived]
impl<ST: ::core::clone::Clone> ::core::clone::Clone for OldValueOf<ST> {
#[inline]
fn clone(&self) -> Self { Self(::core::clone::Clone::clone(&self.0)) }
}Clone, #[automatically_derived]
impl<ST: ::core::marker::Copy> ::core::marker::Copy for OldValueOf<ST> { }Copy, #[automatically_derived]
impl<ST: ::core::default::Default> ::core::default::Default for OldValueOf<ST>
{
#[inline]
fn default() -> Self { Self(::core::default::Default::default()) }
}Default, const _: () =
{
use diesel;
#[allow(non_camel_case_types)]
impl<ST: diesel::query_builder::QueryId>
diesel::query_builder::QueryId for OldValueOf<ST> {
type QueryId =
OldValueOf<<ST as diesel::query_builder::QueryId>::QueryId>;
const HAS_STATIC_QUERY_ID: bool =
<ST as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
true;
const IS_WINDOW_FUNCTION: bool =
<ST as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
false;
}
};QueryId)]
101pub struct OldValueOf<ST>(PhantomData<ST>);
102
103#[diagnostic::do_not_recommend]
104impl<U, ST> CompatibleType<U, Mariadb> for OldValueOf<ST>
105where
106 ST: CompatibleType<U, Mariadb>,
107{
108 type SqlType = ST;
109}
110
111impl<ST> TypedExpressionType for OldValueOf<ST> {}
112
113impl<ST> SqlTypeLikeMarker for OldValueOf<ST> {
114 type SqlType = ST;
115}
116
117impl<ST: TupleSize> TupleSize for OldValueOf<ST> {
118 const SIZE: usize = ST::SIZE;
119}
120
121impl<C> ValidGrouping<()> for OldValue<C>
122where
123 C: Column,
124{
125 type IsAggregate = is_aggregate::No;
126}
127
128impl<C, GB, From> ValidGrouping<SubselectGroupBy<GB, From>> for OldValue<C>
130where
131 C: Column,
132 Self: ValidGrouping<GB>,
133{
134 type IsAggregate = <Self as ValidGrouping<GB>>::IsAggregate;
135}
136
137impl<ST: IntoNullable> IntoNullable for OldValueOf<ST> {
138 type Nullable = OldValueOf<ST::Nullable>;
139}
140
141impl<ST: IntoNotNullable> IntoNotNullable for OldValueOf<ST> {
142 type NotNullable = OldValueOf<ST::NotNullable>;
143}
144
145impl<ST> QueryMetadata<OldValueOf<ST>> for Mariadb
146where
147 Self: QueryMetadata<ST>,
148{
149 fn row_metadata(lookup: &mut Self::MetadataLookup, out: &mut Vec<Option<Self::TypeMetadata>>) {
150 <Self as QueryMetadata<ST>>::row_metadata(lookup, out);
151 }
152}
153
154impl<C, QS> AppearsOnTable<ReturningQuerySource<UpdateStmt, QS>> for OldValue<C>
159where
160 C: Column,
161 Self: Expression,
162 ReturningQuerySource<UpdateStmt, QS>:
164 AppearsInFromClause<OldIdent, Count = crate::query_source::Once>,
165 ReturningQuerySource<UpdateStmt, QS>: AppearsInFromClause<
167 ReturningQuerySource<OldIdent, C::Table>,
168 Count = crate::query_source::Once,
169 >,
170{
171}
172
173impl<C> SelectableExpression<ReturningQuerySource<UpdateStmt, C::Table>> for OldValue<C>
176where
177 C: Column,
178 Self: AppearsOnTable<ReturningQuerySource<UpdateStmt, C::Table>>,
179{
180}
181
182impl<C> QueryFragment<Mariadb> for OldValue<C>
183where
184 C: Column,
185{
186 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Mariadb>) -> QueryResult<()> {
187 out.push_sql("OLD_VALUE(");
188 out.push_identifier(C::NAME)?;
189 out.push_sql(")");
190 Ok(())
191 }
192}
193
194pub use return_type_helpers_reexported::*;
195
196pub(crate) mod return_type_helpers_reexported {
197 use super::OldValue;
198
199 #[allow(non_camel_case_types)]
201 pub type old_value<C> = OldValue<C>;
202}