Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Cannot call into_boxed() for Table #11

Closed
Razican opened this issue Dec 27, 2019 · 2 comments
Closed

Cannot call into_boxed() for Table #11

Razican opened this issue Dec 27, 2019 · 2 comments

Comments

@Razican
Copy link
Member

Razican commented Dec 27, 2019

Hi,
I'm trying to add dynamic ordering and filtering to a query, but I'm facing some issues. I'm trying this:

let query = table.into_boxed();
    query = query
        .select(select)
        .limit(limit)
        .offset(offset)
        .into_boxed();

    if let Some(order_by) = order_by {
        for (col, order) in order_by.iter() {
            let column: diesel_dynamic_schema::Column<_, _, Any> = table.column(col.to_owned());
            match order {
                OrderType::Asc => query = query.then_order_by(column.asc()),
                OrderType::Desc => query = query.then_order_by(column.desc()),
            }
        }
    }

But I'm getting this error:

error[E0277]: the trait bound `diesel::query_builder::SelectStatement<diesel_dynamic_schema::table::Table<T>>: diesel::query_dsl::boxed_dsl::BoxedDsl<'_, _>` is not satisfied
   --> src/db.rs:407:23
    |
407 |     let query = table.into_boxed();
    |                       ^^^^^^^^^^ the trait `diesel::query_dsl::boxed_dsl::BoxedDsl<'_, _>` is not implemented for `diesel::query_builder::SelectStatement<diesel_dynamic_schema::table::Table<T>>`
    |
    = help: the following implementations were found:
              <diesel::query_builder::SelectStatement<F, diesel::query_builder::select_clause::DefaultSelectClause, D, W, O, L, Of, G> as diesel::query_dsl::boxed_dsl::BoxedDsl<'a, DB>>
              <diesel::query_builder::SelectStatement<F, diesel::query_builder::select_clause::SelectClause<S>, D, W, O, L, Of, G> as diesel::query_dsl::boxed_dsl::BoxedDsl<'a, DB>>
    = note: required because of the requirements on the impl of `diesel::query_dsl::boxed_dsl::BoxedDsl<'_, _>` for `diesel_dynamic_schema::table::Table<T>`

It seems that into_boxed() is not implemented for this case. Is there a way to do this properly?

@Razican
Copy link
Member Author

Razican commented Jan 3, 2020

This might be related to using a Dynamic Select Clause. I tried to implement BoxedDsl myself, but it seems that some types are internal to Diesel, so I could not do it.

If I get some pointers I can implement it and create a pull request :)

@weiznich
Copy link
Member

weiznich commented Jan 3, 2020

I've updated #10 to fix that.
A basic requirement remains that the select clause appears before the boxing.

@weiznich weiznich closed this as completed Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants