Last active
March 14, 2021 15:34
-
-
Save mr-pascal/d75d98495b96ead6cba4fe3cf3b33573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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