Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active March 14, 2021 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr-pascal/d75d98495b96ead6cba4fe3cf3b33573 to your computer and use it in GitHub Desktop.
Save mr-pascal/d75d98495b96ead6cba4fe3cf3b33573 to your computer and use it in GitHub Desktop.
/**
* Retrieve data from BigQuery
* @param {string} projectId The ID of the GCP project the dataset/table is located
* @param {string} datasetId The ID of the parent dataset
* @param {string} tableId The ID of the table to get data from
* @returns {Promise<void>}
*/
const getData = async (projectId, datasetId, tableId) => {
const query = `
SELECT * from \`${projectId}.${datasetId}.${tableId}\`
LIMIT 100
`;
const options = {
query: query,
// Location must match that of the dataset(s) referenced in the query.
location,
};
// Run the query as a job
const [job] = await bigquery.createQueryJob(options);
console.log(`Job '${job.id}' started.\n`);
// Wait for the query to finish
const [rows] = await job.getQueryResults();
// Print the results
console.log('Resulted Rows:');
rows.forEach(row => console.log(row));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment