I'm trying to use the '@google-cloud/bigquery' library to query BigQuery from a Google Cloud function. When the Promise returns, all I get back is an Array with another empty Array inside it, even though when I run the same query from the Big Query console I get a non-empty response back.
I've tried using an async function instead of a promise, but that was not successful. I also gave my Service Account "BigQuery Admin" and "Editor" privileges but that has not worked out either.
I do know the API is hitting Big Query. When I tried creating a new dataset from my Cloud Function, that call worked just fine, but for some reason I'm unable to get query results back from BQ.
function warningAndPreventionIntent(agent) {
let userCountry = agent.parameters['geo-country'];
console.log(String(userCountry[0]));
const gotCountry = userCountry.length > 0;
if(gotCountry) {
agent.add('Im looking into your trip');
const OPTIONS = {
query: 'SELECT disease.name FROM `projectId.dataset.table`, unnest(disease) disease WHERE country = @country',
timeoutMs: 10000,
useLegacySql: false,
params: {country: userCountry[0]}
};
return bigquery
.query(OPTIONS)
.then(results => {
console.log(JSON.stringify(results[0]))
const ROWS = results[0];
let diseaseList = [];
for(var row of ROWS) {
diseaseList.push(row.name);
console.log(diseaseList);
}
return true;
})
.catch(err => {
console.error('ERROR:', err);
});
}
}
I should get a JSON result
object with values, but I only get and array with an empty array [[]]