【发布时间】:2021-05-03 14:32:50
【问题描述】:
我正在尝试使用节点 js 在 google bigquaey 中插入、删除、搜索和更新。我已经跟进了谷歌中的所有文件。但是没有提到它,如何连接 - 所以我创建了这个,--
如何将 GCP BigQuery 与 NodeJS 连接起来。我是新来的。任何帮助都会奏效。
我写的代码-
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();
【问题讨论】:
标签: node.js google-cloud-platform google-bigquery google-api-nodejs-client