diesel/expression/
nullable.rs1use crate::backend::DieselReserveSpecialization;
2use crate::expression::*;
3use crate::query_builder::*;
4use crate::query_source::joins::ToInnerJoin;
5use crate::result::QueryResult;
6use crate::sql_types::{DieselNumericOps, IntoNullable};
7
8#[doc(hidden)] #[derive(#[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for Nullable<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Nullable",
&&self.0)
}
}Debug, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Nullable<T> { }Copy, #[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Nullable<T> {
#[inline]
fn clone(&self) -> Nullable<T> {
Nullable(::core::clone::Clone::clone(&self.0))
}
}Clone, const _: () =
{
use diesel;
use diesel::internal::derives::numeric_ops as ops;
use diesel::expression::{Expression, AsExpression};
use diesel::sql_types::ops::{Add, Sub, Mul, Div};
use diesel::sql_types::{SqlType, SingleValue};
impl<T, __Rhs> ::std::ops::Add<__Rhs> for Nullable<T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Add,
<<Self as Expression>::SqlType as Add>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Add>::Rhs> {
type Output = ops::Add<Self, __Rhs::Expression>;
fn add(self, rhs: __Rhs) -> Self::Output {
ops::Add::new(self, rhs.as_expression())
}
}
impl<T, __Rhs> ::std::ops::Sub<__Rhs> for Nullable<T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Sub,
<<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Sub>::Rhs> {
type Output = ops::Sub<Self, __Rhs::Expression>;
fn sub(self, rhs: __Rhs) -> Self::Output {
ops::Sub::new(self, rhs.as_expression())
}
}
impl<T, __Rhs> ::std::ops::Mul<__Rhs> for Nullable<T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Mul,
<<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Mul>::Rhs> {
type Output = ops::Mul<Self, __Rhs::Expression>;
fn mul(self, rhs: __Rhs) -> Self::Output {
ops::Mul::new(self, rhs.as_expression())
}
}
impl<T, __Rhs> ::std::ops::Div<__Rhs> for Nullable<T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Div,
<<Self as Expression>::SqlType as Div>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Div>::Rhs> {
type Output = ops::Div<Self, __Rhs::Expression>;
fn div(self, rhs: __Rhs) -> Self::Output {
ops::Div::new(self, rhs.as_expression())
}
}
};DieselNumericOps, const _: () =
{
use diesel;
impl<T, __GroupByClause>
diesel::expression::ValidGrouping<__GroupByClause> for Nullable<T>
where T: diesel::expression::ValidGrouping<__GroupByClause> {
type IsAggregate =
<T as
diesel::expression::ValidGrouping<__GroupByClause>>::IsAggregate;
}
};ValidGrouping)]
10pub struct Nullable<T>(pub(crate) T);
11
12impl<T> Nullable<T> {
13 pub(crate) fn new(expr: T) -> Self {
14 Nullable(expr)
15 }
16}
17
18impl<T> Expression for Nullable<T>
19where
20 T: Expression,
21 T::SqlType: IntoNullable,
22 <T::SqlType as IntoNullable>::Nullable: TypedExpressionType,
23{
24 type SqlType = <T::SqlType as IntoNullable>::Nullable;
25}
26
27impl<T, DB> QueryFragment<DB> for Nullable<T>
28where
29 DB: Backend + DieselReserveSpecialization,
30 T: QueryFragment<DB>,
31{
32 fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
33 self.0.walk_ast(pass)
34 }
35}
36
37impl<T, QS> AppearsOnTable<QS> for Nullable<T>
38where
39 T: AppearsOnTable<QS>,
40 Nullable<T>: Expression,
41{
42}
43
44impl<T: QueryId> QueryId for Nullable<T> {
45 type QueryId = T::QueryId;
46
47 const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID;
48}
49
50impl<T, QS> SelectableExpression<QS> for Nullable<T>
51where
52 Self: AppearsOnTable<QS>,
53 QS: ToInnerJoin,
54 T: SelectableExpression<QS::InnerJoin>,
55{
56}
57
58impl<T> SelectableExpression<NoFromClause> for Nullable<T> where Self: AppearsOnTable<NoFromClause> {}