| 1 |
use crate::expression::*; |
| 2 |
use crate::query_builder::*; |
| 3 |
use crate::query_source::joins::ToInnerJoin; |
| 4 |
use crate::result::QueryResult; |
| 5 |
use crate::sql_types::{DieselNumericOps, IntoNotNullable}; |
| 6 |
|
| 7 |
#[derive(Default, Debug, Copy, Clone, DieselNumericOps, ValidGrouping)] |
| 8 |
pub struct AssumeNotNull<T>(T); |
| 9 |
|
| 10 |
impl<T> AssumeNotNull<T> { |
| 11 |
pub fn new(expr: T) -> Self { |
| 12 |
AssumeNotNull(expr) |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
impl<T> Expression for AssumeNotNull<T> |
| 17 |
where |
| 18 |
T: Expression, |
| 19 |
T::SqlType: IntoNotNullable, |
| 20 |
<T::SqlType as IntoNotNullable>::NotNullable: TypedExpressionType, |
| 21 |
{ |
| 22 |
type SqlType = <T::SqlType as IntoNotNullable>::NotNullable; |
| 23 |
} |
| 24 |
|
| 25 |
impl<T, DB> QueryFragment<DB> for AssumeNotNull<T> |
| 26 |
where |
| 27 |
DB: Backend, |
| 28 |
T: QueryFragment<DB>, |
| 29 |
{ |
| 30 |
fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { |
| 31 |
self.0.walk_ast(pass) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
impl<T, QS> AppearsOnTable<QS> for AssumeNotNull<T> |
| 36 |
where |
| 37 |
T: AppearsOnTable<QS>, |
| 38 |
AssumeNotNull<T>: Expression, |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
impl<T: QueryId> QueryId for AssumeNotNull<T> { |
| 43 |
type QueryId = T::QueryId; |
| 44 |
|
| 45 |
const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID; |
| 46 |
} |
| 47 |
|
| 48 |
impl<T, QS> SelectableExpression<QS> for AssumeNotNull<T> |
| 49 |
where |
| 50 |
Self: AppearsOnTable<QS>, |
| 51 |
QS: ToInnerJoin, |
| 52 |
T: SelectableExpression<QS::InnerJoin>, |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
impl<T> SelectableExpression<NoFromClause> for AssumeNotNull<T> where |
| 57 |
Self: AppearsOnTable<NoFromClause> |
| 58 |
{ |
| 59 |
} |