Return data from a specific time period

Hey @caysle!

To add on to what Scott has said, you might also try using additional scope here. if you rewrite your JS query as follows

const query = timeout;
const intervals = [moment().subtract(1, 'month').format('YYYY-MM-DD')];
const results = intervals.map(interval => query.trigger({additionalScope: {interval}}));
return Promise.all(results);

You can then reference the {{interval}} variable directly in your query, e.g. with something like

select count(*) from issuances where network = 'xyz' and issued_at > {{interval}} and status = 'completed';

If you'd like, you can also reference date_transformer.value when defining your intervals in the JS query (note that JS queries don't require {{}} to reference objects in your app):

const intervals = [moment().subtract(1, 'month').format('YYYY-MM-DD'), date_transformer.value];

Also note that .map and Promise.all are used here so that the JS query will actually return the collected results of each query trigger, see this post for more details there.

1 Like