Last active
March 14, 2021 10:08
-
-
Save mr-pascal/dbfce542a9ffc875bd7198632a11113c 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
/** | |
* Insert a certain set of rows into the passed table | |
* @param {string} datasetId The ID of the parent dataset | |
* @param {string} tableId The ID of the table to insert data in | |
* @returns {Promise<void>} | |
*/ | |
const insertRows = async (datasetId, tableId) => { | |
const rows = [ | |
{ Name: 'Tom', Age: 30 }, | |
{ Name: 'Jane', Age: 32, Weight: 87, IsMagic: true }, | |
]; | |
try { | |
// Insert data into a table | |
await bigquery | |
.dataset(datasetId) | |
.table(tableId) | |
.insert(rows); | |
console.log(`Inserted ${rows.length} rows`); | |
} catch (e) { | |
// Pretty print error as JSON | |
console.error(JSON.stringify(e, null, 2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment