Hi!
I’m trying to filter a query using a dynamic structure that is a wrapper over a Vec<Vec<FilterClause>>
, where FilterClause
is a structure that can generate something like Eq
, NotEq
or one of those (not sure the trait).
The outer vector should have the “OR” clauses, and the internal one the “AND” clauses. So something like this:
[
[aEQb, bNEQc],
[aEQc, cNEQb],
]
Should be converted to something like WHERE (a = b AND b != c) OR (a = c AND c != b)
This vector structure is wrapped in a Filter
structure, that ideally should have an apply_filter()
method to get a query and either mutate it or return a new query (which is a better/more idiomatic approach?)
To complicate things a bit more, I’m using an unreleased version of diesel_dynamic_schema
, that allows me using dynamic selects in a changing schema. This is the code calling the apply_filter()
:
type DynTable = diesel_dynamic_schema::Table<String>;
pub(crate) fn get_record_list<S>(
db_conn: &PgConnection,
table: &DynTable,
select: S,
filter: Option<Filter>,
) -> Result<Vec<Record>, diesel::result::Error>
where
S: 'static
+ Expression<SqlType = Any>
+ SelectableExpression<DynTable>
+ QueryId
+ QueryFragment<Pg>
{
let mut query = table
.clone()
.select(select)
.into_boxed();
if let Some(filter) = filter {
query = filter.apply_filter(query);
}
todo!()
}
With some help from Gitter, I got to this definition of the apply_filter()
method:
fn apply_filter<'f, Q>(&self, query: Q) -> Q
where
Q: BoxedDsl<'f, DynTable>,
{
todo!()
}
But it seems that this is not working properly, since I’m getting the following error:
overflow evaluating the requirement `diesel::query_builder::BoxedSelectStatement<'_, diesel_dynamic_schema::dynamic_value::Any, diesel_dynamic_schema::table::Table<std::string::String>, diesel::pg::Pg>: diesel::query_dsl::boxed_dsl::BoxedDsl<'_, diesel_dynamic_schema::table::Table<std::string::String>>`
Does anyone have a good approach to implement this?