Hi,
I am trying to run a query for every row in a table or query.
Example being either for each user or for every hour.
I had seen this example:
Promising an array of query returns
const promises = table1.data.map((row) => {
return query1.trigger({
additionalScope: {
id: row.id,
},
});
});
return Promise.all(promises);
This is meant to run the query for each row in the table passing the ID in an an argument and return the results in an array?
Edit for a clearer example.
If I have 2 tables one for users and one for orders.
If the orders table has a user field and I had a query that returned the number of orders for a certain user name called getOrderCount, which was something simple like
Select count(order_id) from orders where user = {{user}}
and the code above was change to:
const promises = userTable.data.map((row) => {
return getOrderCount.trigger({
additionalScope: {
user : row.username,
},
});
});
return Promise.all(promises);
Where userTable has all the usernames listed from the user table.
Select username from users;
Does this return the array of counts? - return Promise.all(promises);
Or is this just an array showing the queries have all completed so it has to wait before it carries on?
How do I return the values from multiple calls to getOrderCount query as an array and use that as the data source for table?
So would then have a table with username and the order count for example.
This is a basic example the thing I am trying to do, I want to be able to call multiple queries per user and then populate a table with the results.
So it might have ordercount, averageorder price, latest order number, etc etc for each user in the user table.
Hope this makes more sense.
Thanks.