| 1 |
use crate::backend::DieselReserveSpecialization; |
| 2 |
use crate::expression::*; |
| 3 |
use crate::query_builder::*; |
| 4 |
use crate::query_source::joins::ToInnerJoin; |
| 5 |
use crate::result::QueryResult; |
| 6 |
use crate::sql_types::{DieselNumericOps, IntoNullable}; |
| 7 |
|
| 8 |
#[doc(hidden)] // This is used by the `table!` macro internally |
| 9 |
#[derive(Debug, Copy, Clone, DieselNumericOps, ValidGrouping)] |
| 10 |
pub struct Nullable<T>(pub(crate) T); |
| 11 |
|
| 12 |
impl<T> Nullable<T> { |
| 13 |
pub(crate) fn new(expr: T) -> Self { |
| 14 |
Nullable(expr) |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
impl<T> Expression for Nullable<T> |
| 19 |
where |
| 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 |
|
| 27 |
impl<T, DB> QueryFragment<DB> for Nullable<T> |
| 28 |
where |
| 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 |
|
| 37 |
impl<T, QS> AppearsOnTable<QS> for Nullable<T> |
| 38 |
where |
| 39 |
T: AppearsOnTable<QS>, |
| 40 |
Nullable<T>: Expression, |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
impl<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 |
|
| 50 |
impl<T, QS> SelectableExpression<QS> for Nullable<T> |
| 51 |
where |
| 52 |
Self: AppearsOnTable<QS>, |
| 53 |
QS: ToInnerJoin, |
| 54 |
T: SelectableExpression<QS::InnerJoin>, |
| 55 |
{ |
| 56 |
} |
| 57 |
|
| 58 |
impl<T> SelectableExpression<NoFromClause> for Nullable<T> where Self: AppearsOnTable<NoFromClause> {} |