Is there a way to reuse a query?

  • Goal: I have many complex queries with lots of parameterized where clauses, parameterized order bys (for table sorting of multiple columns) and optional limit and offset clauses. These queries are typically to provide datasets for Tables. But I also need a version of the same queries that omit the order bys and the limit/offsets (and retain ALL of the where clauses and the same form elements that they are bound to) to get the total count of the records so I can inform the Tables of the total count based on the current filter context.
    I am finding myself writing a two page query twice one for the data and for the count and any time I change something in the UI or add a filter concept, I have to change 2 queries.

Isn't there a way to build an abstraction in Retool that is:
Query 1: giant select with lots of filters and optional order by and optional limit/offset
Query 2: Wrapper around calling Query 1 with the filter values but blank order bys and limit/offsets to get the total count...

Thanks

1 Like

Following

Write the big query once against your DB to fetch all the data. Then write queries (JS, Query JSON with SQL) against the results of the big query to do your summing, filtering, etc.