Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2021 06:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
pub trait FilterWith: AsQuery + Sized {
fn filter_with(self, filters: FilterOpts) -> FilteredQuery<Self::Query> {
FilteredQuery {
query: self.as_query(),
pub struct FilteredQuery<T> {
query: T,
filters: FilterOpts,
impl<T: Query> Query for FilteredQuery<T> {
type SqlType = T::SqlType;
impl<T> RunQueryDsl<PgConnection> for FilteredQuery<T> {}
impl<T: AsQuery> FilterWith for T {}
impl<T> QueryFragment<Pg> for FilteredQuery<T>
T: QueryFragment<Pg>,
fn walk_ast(&self, mut out: AstPass<Pg>) -> QueryResult<()> {
out.push_sql(" WHERE ");
// TODO: dyanmically build this from self (looping self.filters and joining each with
// and/or).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment