Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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