I am trying to insert, delete, search and update in google bigquaey using node js. I have followed up the all documents in google could. But no where its mentioned, how to connect - So I have created this, --
How to connect GCP BigQuery with NodeJS. I am new here. Any help will work.
the code which I have written -
const {BigQuery} = require('@google-cloud/bigquery');
const mainFunction = () => {
insertIntoBigQuery("John", "john@gmail.com", "+1-23232344231");
}
async function insertIntoBigQuery(name, email, phone) {
// const insertIntoBigQuery = async(name, email, phone) => {
const bigqueryClient = new BigQuery();
// The SQL query to run
const sqlQuery = "INSERT INTO `p4tyu78.Backend_testing.Test1` VALUES ("+name+ "," +email+","+ phone+")";
const options = {
query: sqlQuery,
// Location must match that of the dataset(s) referenced in the query.
location: 'US',
};
// Run the query
const [rows] = await bigqueryClient.query(options);
console.log('Rows:');
rows.forEach(row => console.log(`${row.subject}: ${row.num_duplicates}`));
}
const updateIntoBigQuery = () => {
}
const deleteFromBigQuery = () => {
}
const searchFromBigQuery = async() => {
const bigqueryClient = new BigQuery();
// The SQL query to run
const sqlQuery = "SELECT * from `p4tyu78.Backend_testing.Test1`";
const options = {
query: sqlQuery,
// Location must match that of the dataset(s) referenced in the query.
location: 'US',
};
// Run the query
const [rows] = await bigqueryClient.query(options);
console.log('Rows:');
rows.forEach(row => console.log(`${row.subject}: ${row.num_duplicates}`));
}
mainFunction();