I am trying to keep db queries to a minimum. The goal is to make one query and use data in other functions. So far, I have this code:
async function GetCoverage(scroll_path) {
const apiName = "xxxx";
const path = "/scrolls/" + scroll_path;
const myInit = {
headers: {},
response: false,
};
const response = await API.get(apiName, path, myInit);
console.log("response:", response);
return response.Items;
}
let dataGlobal;
const getData = async () => {
const response = await GetCoverage("all");
dataGlobal = response;
return response;
};
(async () => {
await getData();
console.log("dataGlobal:", dataGlobal);
})();
The problem is every await getData()
invocation drives another db query. How can I avoid that?