Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active March 14, 2021 10:08
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/dbfce542a9ffc875bd7198632a11113c to your computer and use it in GitHub Desktop.
Save mr-pascal/dbfce542a9ffc875bd7198632a11113c to your computer and use it in GitHub Desktop.
/**
* 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