| 1 |
use crate::dsl; |
| 2 |
use crate::expression::TypedExpressionType; |
| 3 |
use crate::expression::ValidGrouping; |
| 4 |
use crate::query_builder::AsQuery; |
| 5 |
use crate::query_builder::FromClause; |
| 6 |
use crate::query_builder::SelectStatement; |
| 7 |
use crate::query_source::Table; |
| 8 |
use crate::Expression; |
| 9 |
|
| 10 |
/// The `into_boxed` method |
| 11 |
/// |
| 12 |
/// This trait should not be relied on directly by most apps. Its behavior is |
| 13 |
/// provided by [`QueryDsl`]. However, you may need a where clause on this trait |
| 14 |
/// to call `into_boxed` from generic code. |
| 15 |
/// |
| 16 |
/// [`QueryDsl`]: crate::QueryDsl |
| 17 |
#[diagnostic::on_unimplemented( |
| 18 |
message = "cannot box `{Self}` for backend `{DB}`", |
| 19 |
note = "this either means `{Self}` is no valid SQL for `{DB}`", |
| 20 |
note = "or this means `{Self}` uses clauses not supporting boxing like the `LOCKING` or `GROUP BY` clause" |
| 21 |
)] |
| 22 |
pub trait BoxedDsl<'a, DB> { |
| 23 |
/// The return type of `internal_into_boxed` |
| 24 |
type Output; |
| 25 |
|
| 26 |
/// See the trait documentation. |
| 27 |
fn internal_into_boxed(self) -> dsl::IntoBoxed<'a, Self, DB>; |
| 28 |
} |
| 29 |
|
| 30 |
#[diagnostic::do_not_recommend] |
| 31 |
impl<'a, T, DB> BoxedDsl<'a, DB> for T |
| 32 |
where |
| 33 |
T: Table + AsQuery<Query = SelectStatement<FromClause<T>>>, |
| 34 |
SelectStatement<FromClause<T>>: BoxedDsl<'a, DB>, |
| 35 |
T::DefaultSelection: Expression<SqlType = T::SqlType> + ValidGrouping<()>, |
| 36 |
T::SqlType: TypedExpressionType, |
| 37 |
{ |
| 38 |
type Output = dsl::IntoBoxed<'a, SelectStatement<FromClause<T>>, DB>; |
| 39 |
|
| 40 |
fn internal_into_boxed(self) -> Self::Output { |
| 41 |
self.as_query().internal_into_boxed() |
| 42 |
} |
| 43 |
} |