What is @google-cloud/bigquery?
@google-cloud/bigquery is a Node.js client library for Google BigQuery, a fully-managed, serverless data warehouse that enables scalable analysis over petabytes of data. This package allows you to interact with BigQuery to run queries, manage datasets, tables, and jobs, and perform data manipulations.
What are @google-cloud/bigquery's main functionalities?
Running Queries
This feature allows you to run SQL queries against your BigQuery datasets. The code sample demonstrates how to run a simple query to select names and ages from a table where the age is greater than 30.
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function query() {
const query = 'SELECT name, age FROM `my-dataset.my-table` WHERE age > 30';
const options = { query: query, location: 'US' };
const [rows] = await bigquery.query(options);
console.log('Rows:', rows);
}
query();
Managing Datasets
This feature allows you to create and manage datasets in BigQuery. The code sample demonstrates how to create a new dataset named 'my_new_dataset'.
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function createDataset() {
const [dataset] = await bigquery.createDataset('my_new_dataset');
console.log(`Dataset ${dataset.id} created.`);
}
createDataset();
Managing Tables
This feature allows you to create and manage tables within datasets. The code sample demonstrates how to create a new table named 'my_new_table' within the 'my_new_dataset' dataset.
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function createTable() {
const dataset = bigquery.dataset('my_new_dataset');
const [table] = await dataset.createTable('my_new_table');
console.log(`Table ${table.id} created.`);
}
createTable();
Loading Data
This feature allows you to load data from various sources into BigQuery tables. The code sample demonstrates how to load data from a local CSV file into a table named 'my_new_table' within the 'my_new_dataset' dataset.
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function loadData() {
const dataset = bigquery.dataset('my_new_dataset');
const table = dataset.table('my_new_table');
const [job] = await table.load('local-file.csv');
console.log(`Job ${job.id} completed.`);
}
loadData();
Other packages similar to @google-cloud/bigquery
aws-sdk
The aws-sdk package is the official AWS SDK for JavaScript, which allows you to interact with various AWS services, including Amazon Redshift, a data warehouse service similar to Google BigQuery. While aws-sdk provides a broader range of functionalities across different AWS services, it can be used to perform similar data warehousing tasks as @google-cloud/bigquery.
azure-sdk-for-js
The azure-sdk-for-js package is the official Azure SDK for JavaScript, which allows you to interact with various Azure services, including Azure Synapse Analytics, a data warehousing service similar to Google BigQuery. Like aws-sdk, azure-sdk-for-js offers a wide range of functionalities across different Azure services, including data warehousing capabilities.
snowflake-sdk
The snowflake-sdk package is the official Node.js driver for Snowflake, a cloud-based data warehousing service. It provides functionalities to connect to Snowflake, run queries, and manage data, similar to what @google-cloud/bigquery offers for Google BigQuery.
Google BigQuery Client Library for Node.js
Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
Quickstart
Before you begin
- Select or create a Cloud Platform project.
- Enable the Google BigQuery API.
- Set up authentication with a service account so you can access the
API from your local workstation.
Installing the client library
npm install @google-cloud/bigquery
Using the client library
const {BigQuery} = require('@google-cloud/bigquery');
async function createDataset() {
const bigqueryClient = new BigQuery();
const [dataset] = await bigqueryClient.createDataset(datasetName);
console.log(`Dataset ${dataset.id} created.`);
}
createDataset();
Samples
Samples are in the samples/
directory. The samples' README.md
has instructions for running the samples.
The Google BigQuery Node.js Client API Reference documentation
also contains samples.
Supported Node.js Versions
Our client libraries follow the Node.js release schedule.
Libraries are compatible with all current active and maintenance versions of
Node.js.
Client libraries targetting some end-of-life versions of Node.js are available, and
can be installed via npm dist-tags.
The dist-tags follow the naming convention legacy-(version)
.
Legacy Node.js versions are supported as a best effort:
- Legacy versions will not be tested in continuous integration.
- Some security patches may not be able to be backported.
- Dependencies will not be kept up-to-date, and features will not be backported.
Legacy tags available
legacy-8
: install client libraries from this dist-tag for versions
compatible with Node.js 8.
Versioning
This library follows Semantic Versioning.
This library is considered to be General Availability (GA). This means it
is stable; the code surface will not change in backwards-incompatible ways
unless absolutely necessary (e.g. because of critical security issues) or with
an extensive deprecation period. Issues and requests against GA libraries
are addressed with the highest priority.
More Information: Google Cloud Platform Launch Stages
Contributing
Contributions welcome! See the Contributing Guide.
Please note that this README.md
, the samples/README.md
,
and a variety of configuration files in this repository (including .nycrc
and tsconfig.json
)
are generated from a central template. To edit one of these files, make an edit
to its template in this
directory.
License
Apache Version 2.0
See LICENSE