Created
June 3, 2019 20:16
-
-
Save suru-dissanaike/04cdea748b0be5612186c04b39410248 to your computer and use it in GitHub Desktop.
bigQueryExample.js
This file contains hidden or 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
// Imports the Google Cloud client library | |
const {BigQuery} = require('@google-cloud/bigquery'); | |
// Your Google Cloud Platform project ID | |
const projectId = 'bigquery-242619'; | |
const datasetId = "test_data"; | |
const tableId = "raw_data"; | |
const bqTimestamp = BigQuery.timestamp(new Date()); | |
const rows = [{ deviceId: 'esp8266v3', gas: 41.84, hum: 57.24, press: 1002.62, temp: 29.46, timestamp: bqTimestamp }]; | |
// Creates a client | |
const bigquery = new BigQuery({ | |
projectId: projectId, | |
}); | |
// Inserts data into a table | |
bigquery | |
.dataset(datasetId) | |
.table(tableId) | |
.insert(rows) | |
.then(() => { | |
console.log(`Inserted ${rows.length} rows`); | |
}) | |
.catch(err => { | |
if (err && err.name === 'PartialFailureError') { | |
if (err.errors && err.errors.length > 0) { | |
console.log('Insert errors:'); | |
err.errors.forEach(err => console.error(err)); | |
} | |
} else { | |
console.error('ERROR:', err); | |
} | |
}); | |
// [END bigquery_table_insert_rows] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment