### Full BigQuery Quickstart Example Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery A complete example demonstrating how to create a BigQuery dataset using the client library. ```javascript // Imports the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); async function createDataset() { // Creates a client const bigqueryClient = new BigQuery(); // Create the dataset const [dataset] = await bigqueryClient.createDataset(datasetName); console.log(`Dataset ${dataset.id} created.`); } createDataset(); ``` -------------------------------- ### Installation and Client Initialization Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Instructions on how to install the BigQuery client library and create a client instance using Application Default Credentials or explicit credentials. ```APIDOC ## Installation Install the client library with npm: ``` npm install @google-cloud/bigquery ``` ## Client Initialization Import the client library: ``` const {BigQuery} = require('@google-cloud/bigquery'); ``` Create a client that uses Application Default Credentials (ADC): ``` const bigquery = new BigQuery(); ``` Create a client with explicit credentials: ``` const bigquery = new BigQuery({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json' }); ``` ``` -------------------------------- ### Install BigQuery Node.js Client Library Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest Install the Google BigQuery client library for Node.js using npm. ```bash npm install @google-cloud/bigquery ``` -------------------------------- ### Create Dataset Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Demonstrates how to create a new BigQuery dataset using the `createDataset` method. It shows examples using both callbacks and Promises. ```APIDOC ## `createDataset(id, options)` Create a dataset. See Datasets: insert API Documentation **Parameters** --- **Name** | **Description** `id` | `string` ID of the dataset to create. `options` | `DatasetResource` See a Dataset resource. **Returns** --- **Type** | **Description** `Promise` | **Example** ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); bigquery.createDataset('my-dataset', function(err, dataset, apiResponse) { // handle error or dataset }); // Using Promises: bigquery.createDataset('my-dataset').then(function(data) { const dataset = data[0]; const apiResponse = data[1]; // handle dataset or apiResponse }); ``` ## `createDataset(id, options, callback)` **Parameters** --- **Name** | **Description** `id` | `string` `options` | `DatasetResource` `callback` | `DatasetCallback` **Returns** --- **Type** | **Description** `void` | ## `createDataset(id, callback)` **Parameters** --- **Name** | **Description** `id` | `string` `callback` | `DatasetCallback` **Returns** --- **Type** | **Description** `void` | ``` -------------------------------- ### Create a Dataset Instance Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Instantiate a Dataset object by providing the BigQuery client and the dataset ID. This is the starting point for interacting with a specific dataset. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); ``` -------------------------------- ### Create a BigQuery Table using Callbacks Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Create a BigQuery table with a specified ID and metadata. This example uses a callback function to handle the response. Ensure the BigQuery client and dataset are initialized. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); const tableId = 'institution_data'; const options = { // From the data.gov CSV dataset (http://goo.gl/kSE7z6): schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...' }; dataset.createTable(tableId, options, (err, table, apiResponse) => {}); ``` -------------------------------- ### Initialize BigQuery Table Object Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Instantiate a BigQuery client, dataset, and table object. This is a common setup for interacting with BigQuery tables. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const table = dataset.table('my-table'); ``` -------------------------------- ### Create Job Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Explains how to create a BigQuery job using the `createJob` method, suitable for fine-grained control over job creation. It includes examples for both callback and Promise-based usage. ```APIDOC ## `createJob(options)` Creates a job. Typically when creating a job you'll have a very specific task in mind. For this we recommend one of the following methods: * * * However in the event you need a finer level of control over the job creation, you can use this method to pass in a raw Job resource object. See Jobs Overview See Jobs: insert API Documentation **Parameter** --- **Name** | **Description** `options` | `JobOptions` Object in the form of a Job resource; **Returns** --- **Type** | **Description** `Promise` | **Example** ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const options = { configuration: { query: { query: 'SELECT url FROM `publicdata.samples.github_nested` LIMIT 100' } } }; bigquery.createJob(options, function(err, job) { if (err) { // Error handling omitted. } job.getQueryResults(function(err, rows) {}); }); // Using Promises: bigquery.createJob(options).then(function(data) { const job = data[0]; return job.getQueryResults(); }); ``` ## `createJob(options, callback)` **Parameters** --- **Name** | **Description** `options` | `JobOptions` `callback` | `JobCallback` **Returns** --- **Type** | **Description** `void` | ``` -------------------------------- ### Get BigQuery Routines with Callback Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a list of Routine resources from a dataset using a callback function. Ensure the BigQuery client and dataset are initialized. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); dataset.getRoutines((err, routines) => { // routines is an array of `Routine` objects. }); ``` -------------------------------- ### Get BigQuery Jobs Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Retrieves all jobs from your project. Supports automatic or manual pagination. If a callback is omitted, a Promise is returned. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); bigquery.getJobs(function(err, jobs) { if (!err) { // jobs is an array of Job objects. } }); ``` ```javascript //- // To control how many API requests are made and page through the results // manually, set `autoPaginate` to `false`. //- function manualPaginationCallback(err, jobs, nextQuery, apiRespose) { if (nextQuery) { // More results exist. bigquery.getJobs(nextQuery, manualPaginationCallback); } } bigquery.getJobs({ autoPaginate: false }, manualPaginationCallback); ``` ```javascript //- // If the callback is omitted, we'll return a Promise. //- bigquery.getJobs().then(function(data) { const jobs = data[0]; }); ``` -------------------------------- ### Get BigQuery Models with Callback Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a list of Model resources from a dataset using a callback function. Ensure the BigQuery client and dataset are initialized. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); dataset.getModels((err, models) => { // models is an array of `Model` objects. }); ``` -------------------------------- ### Delete a BigQuery Dataset using Callbacks Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Delete a BigQuery dataset. This example uses a callback to handle the response. You can optionally force deletion of the dataset and its tables by setting `force: true`. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); //- // Delete the dataset, only if it does not have any tables. //- dataset.delete((err, apiResponse) => {}); //- // Delete the dataset and any tables it contains. //- dataset.delete({ force: true }, (err, apiResponse) => {}); ``` -------------------------------- ### Get Tables from a BigQuery Dataset Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a list of Table resources within a dataset. Supports both callback and Promise-based usage, as well as manual pagination. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); dataset.getTables((err, tables) => { // tables is an array of `Table` objects. }); ``` ```javascript //- // To control how many API requests are made and page through the results // manually, set `autoPaginate` to `false`. //- function manualPaginationCallback(err, tables, nextQuery, apiResponse) { if (nextQuery) { // More results exist. dataset.getTables(nextQuery, manualPaginationCallback); } } dataset.getTables({ autoPaginate: false }, manualPaginationCallback); ``` ```javascript //- // If the callback is omitted, we'll return a Promise. //- dataset.getTables().then((data) => { const tables = data[0]; }); ``` -------------------------------- ### Get BigQuery Routines with Manual Pagination Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves Routine resources with manual pagination control by setting `autoPaginate` to `false`. This allows for custom handling of paginated results using a callback. ```javascript function manualPaginationCallback(err, routines, nextQuery, apiResponse) { if (nextQuery) { // More results exist. dataset.getRoutines(nextQuery, manualPaginationCallback); } } dataset.getRoutines({ autoPaginate: false }, manualPaginationCallback); ``` -------------------------------- ### getRows(options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Get rows from this table. ```APIDOC ## getRows(options) ### Description Get rows from this table. ### Method `getRows` ### Parameters #### Path Parameters - **options** (GetRowsOptions) - Optional - Configuration options for retrieving rows. ### Returns - **Promise** - A promise that resolves with the rows. - **ReadableStream** - A readable stream of rows. ``` -------------------------------- ### Create a Dataset Reference Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a reference to a BigQuery dataset using its ID and optional configuration. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('higher_education'); ``` -------------------------------- ### getQueryResults(options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Get the results of a job. ```APIDOC ### getQueryResults(options) ```typescript getQueryResults(options?: QueryResultsOptions): Promise; ``` Get the results of a job. See Jobs: getQueryResults API Documentation **Parameter** --- **Name** | **Description** `options` | `QueryResultsOptions` - Configuration object. **Returns** --- **Type** | **Description** `Promise` | {Promise **Example** ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const job = bigquery.job('job-id'); //- // Get all of the results of a query. //- job.getQueryResults((err, rows) => { if (!err) { // rows is an array of results. } }); //- // Customize the results you want to fetch. //- job.getQueryResults({ maxResults: 100 }, (err, rows) => {}); //- // To control how many API requests are made and page through the results // manually, set `autoPaginate` to `false`. //- function manualPaginationCallback(err, rows, nextQuery, apiResponse) { if (nextQuery) { // More results exist. job.getQueryResults(nextQuery, manualPaginationCallback); } } job.getQueryResults({ autoPaginate: false }, manualPaginationCallback); //- // If the callback is omitted, we'll return a Promise. //- job.getQueryResults().then((data) => { const rows = data[0]; }); ``` ``` ```APIDOC ### getQueryResults(options, callback) ```typescript getQueryResults(options: QueryResultsOptions, callback: QueryRowsCallback): void; ``` **Parameters** --- **Name** | **Description** `options` | `QueryResultsOptions` `callback` | `QueryRowsCallback` **Returns** --- **Type** | **Description** `void` | ``` ```APIDOC ### getQueryResults(callback) ```typescript getQueryResults(callback: QueryRowsCallback): void; ``` **Parameter** --- **Name** | **Description** `callback` | `QueryRowsCallback` **Returns** --- **Type** | **Description** `void` | ``` -------------------------------- ### Model Class Initialization Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/model Demonstrates how to instantiate a Model object using a dataset and model ID. ```APIDOC ## Constructor ### `constructor(dataset, id)` Constructs a new instance of the `Model` class. #### Parameters * **dataset** (`Dataset`) - The parent Dataset object. * **id** (`string`) - The ID of the model. ``` -------------------------------- ### getRows(callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Get rows from this table, with a callback. ```APIDOC ## getRows(callback) ### Description Get rows from this table, with a callback. ### Method `getRows` ### Parameters #### Path Parameters - **callback** (function) - Required - A callback function. ### Returns - **Promise** - A promise that resolves with the rows. ``` -------------------------------- ### Create BigQuery Client with Explicit Credentials Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a BigQuery client instance by explicitly providing the project ID and key file path. ```javascript const bigquery = new BigQuery({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json' }); ``` -------------------------------- ### getIamPolicy(optionsOrCallback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Get the IAM policy for this table. ```APIDOC ## getIamPolicy(optionsOrCallback) ### Description Get the IAM policy for this table. ### Method `getIamPolicy` ### Parameters #### Path Parameters - **optionsOrCallback** (GetIamPolicyOptions | GetIamPolicyCallback) - Optional - Configuration options or a callback function. ### Returns - **Promise** - A promise that resolves with the IAM policy. - **callback** (function) - Optional - A callback function. ``` -------------------------------- ### getRows(options, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Get rows from this table, with options and a callback. ```APIDOC ## getRows(options, callback) ### Description Get rows from this table, with options and a callback. ### Method `getRows` ### Parameters #### Path Parameters - **options** (GetRowsOptions) - Optional - Configuration options for retrieving rows. - **callback** (function) - Required - A callback function. ### Returns - **Promise** - A promise that resolves with the rows. ``` -------------------------------- ### getIamPolicy(options, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Get the IAM policy for this table, with options and a callback. ```APIDOC ## getIamPolicy(options, callback) ### Description Get the IAM policy for this table, with options and a callback. ### Method `getIamPolicy` ### Parameters #### Path Parameters - **options** (GetIamPolicyOptions) - Optional - Configuration options. - **callback** (function) - Required - A callback function. ### Returns - **Promise** - A promise that resolves with the IAM policy. ``` -------------------------------- ### Get Routine Stream Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a stream of Routine resources within a dataset. ```APIDOC ## getRoutinesStream(options) ### Description Get a stream of Routine resources. ### Method `getRoutinesStream(options?: GetRoutinesOptions): ResourceStream;` ### Parameters #### Path Parameters - `options` (GetRoutinesOptions) - Optional - Request options. ### Returns - `ResourceStream` - A stream of Routine resources. ``` -------------------------------- ### Instantiate a Routine object Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/routine Demonstrates how to instantiate a Routine object using the BigQuery client library for Node.js. This is typically done after obtaining a Dataset object. ```javascript const { BigQuery } = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const routine = dataset.routine('my_routine'); ``` -------------------------------- ### Instantiate BigQueryInt Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigqueryint.html Demonstrates how to create a BigQueryInt object using the BigQuery client library. For long integers, a string can be provided. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const anInt = bigquery.int(7); ``` -------------------------------- ### Get Model Stream Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a stream of Model resources within a dataset. ```APIDOC ## getModelsStream(options) ### Description Get a stream of Model resources. ### Method `getModelsStream(options?: GetModelsOptions): ResourceStream;` ### Parameters #### Path Parameters - `options` (GetModelsOptions) - Optional - Configuration object. ### Returns - `ResourceStream` - A stream of Model resources. ``` -------------------------------- ### Get IAM Policy Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Retrieves the IAM policy for a BigQuery resource. Can be used with either a Promise-based or callback-based approach. ```APIDOC ## getIamPolicy(optionsOrCallback) ### Description Retrieves the IAM policy for a BigQuery resource. ### Parameters #### Path Parameters * `optionsOrCallback` (GetPolicyOptions | PolicyCallback) - Optional - Options for retrieving the policy or a callback function. ### Returns * `Promise` - A promise that resolves with the policy response. ``` ```APIDOC ## getIamPolicy(options, callback) ### Description Retrieves the IAM policy for a BigQuery resource using a callback. ### Parameters #### Path Parameters * `options` (GetPolicyOptions) - Required - Options for retrieving the policy. * `callback` (PolicyCallback) - Required - A callback function to handle the policy response. ### Returns * `void` ``` -------------------------------- ### Create BigQuery Dataset with Promise Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a BigQuery dataset using the `createDataset` method and handle the response with a Promise. ```javascript //- // If the callback is omitted, we'll return a Promise. //- bigquery.createDataset('my-dataset').then(function(data) { const dataset = data[0]; const apiResponse = data[1]; }); ``` -------------------------------- ### Create BigQuery Dataset with Callback Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a BigQuery dataset using the `createDataset` method with a callback function for handling the response. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); bigquery.createDataset('my-dataset', function(err, dataset, apiResponse) { }); ``` -------------------------------- ### Get Rows from Table Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Retrieves rows from a BigQuery table. Supports options for filtering and pagination, and can be used with Promises or callbacks. ```APIDOC ## getRows(options) ### Description Retrieves rows from a BigQuery table with specified options. ### Parameters #### Path Parameters * `options` (GetRowsOptions) - Optional - Options for retrieving rows, such as filters and limits. ### Returns * `Promise` - A promise that resolves with the rows response. ``` ```APIDOC ## getRows(options, callback) ### Description Retrieves rows from a BigQuery table with specified options using a callback. ### Parameters #### Path Parameters * `options` (GetRowsOptions) - Required - Options for retrieving rows. * `callback` (RowsCallback) - Required - A callback function to handle the rows response. ### Returns * `void` ``` ```APIDOC ## getRows(callback) ### Description Retrieves rows from a BigQuery table using default options and a callback. ### Parameters #### Path Parameters * `callback` (RowsCallback) - Required - A callback function to handle the rows response. ### Returns * `void` ``` -------------------------------- ### createQueryJob(options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Run a query as a job. No results are immediately returned. Instead, your callback will be executed with a Job object that you must ping for the results. See the Job documentation for explanations of how to check on the status of the job. ```APIDOC ## createQueryJob(options) ### Description Run a query as a job. No results are immediately returned. Instead, your callback will be executed with a Job object that you must ping for the results. See the Job documentation for explanations of how to check on the status of the job. See for full documentation of this method. ### Parameters #### Path Parameters - **options** (string | Query) - Required - See for full documentation of this method. ### Response #### Success Response (200) - **Type**: Promise - **Description**: {Promise} ``` -------------------------------- ### Create BigQuery Client with ADC Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a BigQuery client instance using Application Default Credentials (ADC). ```javascript const bigquery = new BigQuery(); ``` -------------------------------- ### Get Routines Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a list of Routine resources within a dataset. Supports manual pagination and Promise-based or callback-based execution. ```APIDOC ## getRoutines(options, callback) ### Description Get a list of routines. See Routines: list API Documentation ### Method `getRoutines(options: GetRoutinesOptions, callback: GetRoutinesCallback): void;` ### Parameters #### Path Parameters - `options` (GetRoutinesOptions) - Required - Request options. - `callback` (GetRoutinesCallback) - Required - Callback function. ### Returns - `void` ``` ```APIDOC ## getRoutines(callback) ### Description Get a list of routines. See Routines: list API Documentation ### Method `getRoutines(callback: GetRoutinesCallback): void;` ### Parameters #### Path Parameters - `callback` (GetRoutinesCallback) - Required - Callback function. ### Returns - `void` ``` ```APIDOC ## getRoutines(options) ### Description Get a list of routines. See Routines: list API Documentation ### Method `getRoutines(options?: GetRoutinesOptions): Promise;` ### Parameters #### Path Parameters - `options` (GetRoutinesOptions) - Optional - Request options. ### Returns - `Promise` - A Promise that resolves with a list of Routine resources. ### Request Example ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); const [routines] = await dataset.getRoutines(); ``` ``` -------------------------------- ### Get Models Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves a list of Model resources within a dataset. Supports manual pagination and Promise-based or callback-based execution. ```APIDOC ## getModels(options, callback) ### Description Get a list of Model resources. See Models: list API Documentation ### Method `getModels(options: GetModelsOptions, callback: GetModelsCallback): void;` ### Parameters #### Path Parameters - `options` (GetModelsOptions) - Required - Configuration object. - `callback` (GetModelsCallback) - Required - Callback function. ### Returns - `void` ``` ```APIDOC ## getModels(callback) ### Description Get a list of Model resources. See Models: list API Documentation ### Method `getModels(callback: GetModelsCallback): void;` ### Parameters #### Path Parameters - `callback` (GetModelsCallback) - Required - Callback function. ### Returns - `void` ``` ```APIDOC ## getModels(options) ### Description Get a list of Model resources. See Models: list API Documentation ### Method `getModels(options?: GetModelsOptions): Promise;` ### Parameters #### Path Parameters - `options` (GetModelsOptions) - Optional - Configuration object. ### Returns - `Promise` - A Promise that resolves with a list of Model resources. ### Request Example ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('institutions'); dataset.getModels().then((data) => { const models = data[0]; }); ``` ``` -------------------------------- ### Constructor Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Constructs a new instance of the Job class. ```APIDOC ## Constructors ### (constructor)(bigQuery, id, options) ```typescript constructor(bigQuery: BigQuery, id: string, options?: JobOptions); ``` **Parameters** --- **Name** | **Description** `bigQuery` | `BigQuery` `id` | `string` `options` | `JobOptions` ``` -------------------------------- ### Create a BigQuery Dataset using Node.js Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest Use the BigQuery client library to create a new dataset in your Google Cloud project. Ensure you have set up authentication. ```javascript // Imports the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); async function createDataset() { // Creates a client const bigqueryClient = new BigQuery(); // Create the dataset const [dataset] = await bigqueryClient.createDataset(datasetName); console.log(`Dataset ${dataset.id} created.`); } createDataset(); ``` -------------------------------- ### Get IAM Policy (Promise) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Retrieves the IAM policy for a BigQuery table. This method returns a Promise that resolves with the policy response. ```typescript getIamPolicy(optionsOrCallback?: GetPolicyOptions | PolicyCallback): Promise; ``` -------------------------------- ### Instantiate and Monitor a BigQuery Job Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Instantiate a Job object and set up event listeners for 'complete' and 'error' events to monitor job status. Remove listeners to stop polling. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const job = bigquery.job('job-id'); //- // All jobs are event emitters. The status of each job is polled // continuously, starting only after you register a "complete" listener. //- job.on('complete', (metadata) => { // The job is complete. }); //- // Be sure to register an error handler as well to catch any issues which // impeded the job. //- job.on('error', (err) => { // An error occurred during the job. }); //- // To force the Job object to stop polling for updates, simply remove any // "complete" listeners you've registered. // // The easiest way to do this is with `removeAllListeners()`. //- job.removeAllListeners(); ``` -------------------------------- ### Create a Query Job with Callback Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Initiate a query job using a callback function for handling the response. This is an alternative to using Promises for asynchronous operations. ```javascript createQueryJob(options: string | Query, callback: JobCallback): void; ``` -------------------------------- ### Get Query Results Stream (TypeScript) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Retrieves query results as a `ResourceStream`. This method is useful for processing large result sets efficiently. ```typescript getQueryResultsStream(options?: QueryResultsOptions): ResourceStream; ``` -------------------------------- ### Set Table Metadata with Callback and Promise Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Demonstrates how to set metadata for a BigQuery table using both a callback function and a Promise-based approach. Ensure the BigQuery client is initialized and the dataset and table references are valid. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const table = dataset.table('my-table'); const metadata = { name: 'My recipes', description: 'A table for storing my recipes.', schema: 'name:string, servings:integer, cookingTime:float, quick:boolean' }; table.setMetadata(metadata, (err, metadata, apiResponse) => {}); //- // If the callback is omitted, we'll return a Promise. //- table.setMetadata(metadata).then((data) => { const metadata = data[0]; const apiResponse = data[1]; }); ``` -------------------------------- ### Get Table Rows (Callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Fetches rows from a BigQuery table using a callback function. This overload is useful for integrating with existing callback-based workflows. ```typescript getRows(options: GetRowsOptions, callback: RowsCallback): void; ``` -------------------------------- ### Instantiate a BigQuery Model Object Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/model Instantiate a new Model object. This requires a BigQuery client, a dataset, and a model ID. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const model = dataset.model('my-model'); ``` -------------------------------- ### Get Table Rows (Promise) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Fetches rows from a BigQuery table. This method returns a Promise that resolves with the rows response, allowing for asynchronous handling. ```typescript getRows(options?: GetRowsOptions): Promise; ``` -------------------------------- ### createCopyFromJob(source, metadata) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Initiates a copy job from multiple source tables into the current table, with optional metadata. Returns a Promise that resolves with the job response. ```APIDOC ## createCopyFromJob(source, metadata) ### Description Copy data from multiple tables into this table. See Jobs: insert API Documentation. ### Parameters #### Path Parameters - **source** (Table | Table[]) - Required - The source table(s) to copy data from. - **metadata** (CopyTableMetadata) - Optional - Metadata to set with the copy operation. The metadata object should be in the format of a `JobConfigurationTableCopy` object. ### Returns - **Promise** - A Promise that resolves with the job response. ### Example ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const table = dataset.table('my-table'); const sourceTables = [ dataset.table('your-table'), dataset.table('your-second-table') ]; const metadata = { createDisposition: 'CREATE_NEVER', writeDisposition: 'WRITE_TRUNCATE' }; table.createCopyFromJob(sourceTables, metadata).then((data) => { const job = data[0]; const apiResponse = data[1]; }); ``` ``` -------------------------------- ### Get IAM Policy (Callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Retrieves the IAM policy for a BigQuery table using a callback function. This overload is suitable for traditional callback patterns. ```typescript getIamPolicy(options: GetPolicyOptions, callback: PolicyCallback): void; ``` -------------------------------- ### createCopyFromJob(source, metadata, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Create a job to copy data from multiple source tables to this table, with a callback. ```APIDOC ## createCopyFromJob(source, metadata, callback) ### Description Create a job to copy data from multiple source tables to this table, with a callback. ### Method `createCopyFromJob` ### Parameters #### Path Parameters - **source** (Table[]) - Required - An array of source tables. - **metadata** (CopyTableMetadata) - Optional - Metadata to set with the copy operation. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### Creating a Dataset Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Methods for creating a new BigQuery dataset. Overloads are provided for different callback/options configurations. ```APIDOC ## createDataset(id, options) ### Description Creates a new BigQuery dataset. ### Method `createDataset(id, options)` ### Parameters - **id** (string) - Required - The ID of the dataset to create. - **options** (object) - Optional - Configuration options for dataset creation. ### Endpoint N/A (Client Library Method) ``` ```APIDOC ## createDataset(id, options, callback) ### Description Creates a new BigQuery dataset with a callback. ### Method `createDataset(id, options, callback)` ### Parameters - **id** (string) - Required - The ID of the dataset to create. - **options** (object) - Optional - Configuration options for dataset creation. - **callback** (function) - Optional - A callback function to handle the response. ``` ```APIDOC ## createDataset(id, callback) ### Description Creates a new BigQuery dataset with a callback, using default options. ### Method `createDataset(id, callback)` ### Parameters - **id** (string) - Required - The ID of the dataset to create. - **callback** (function) - Optional - A callback function to handle the response. ``` -------------------------------- ### Get BigQuery Routines with Promise Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves Routine resources from a dataset using Promises. If the callback is omitted, the method returns a Promise that resolves with the routines. ```javascript const [routines] = await dataset.getRoutines(); ``` -------------------------------- ### Table Constructors Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Information on how to construct a Table object. ```APIDOC ## Table Constructor ### Description Initializes a new instance of the Table class. ### Parameters * **dataset** (Dataset) - Required - The Dataset this table belongs to. * **id** (string) - Required - The ID of the table. * **options** (object) - Optional - Configuration options for the table. ``` -------------------------------- ### createCopyFromJob(source, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Create a job to copy data from multiple source tables to this table, with a callback. ```APIDOC ## createCopyFromJob(source, callback) ### Description Create a job to copy data from multiple source tables to this table, with a callback. ### Method `createCopyFromJob` ### Parameters #### Path Parameters - **source** (Table[]) - Required - An array of source tables. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### Get BigQuery Models with Promise Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves Model resources from a dataset using Promises. If the callback is omitted, the method returns a Promise that resolves with the models. ```javascript dataset.getModels().then((data) => { const models = data[0]; }); ``` -------------------------------- ### createQueryStream(options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Run a query scoped to your dataset as a readable object stream. ```APIDOC ## createQueryStream(options) ### Description Run a query scoped to your dataset as a readable object stream. See for full documentation of this method. ### Parameters #### Path Parameters - **options** (Query | string) - Required - See for full documentation of this method. ### Response #### Success Response (200) - **Type**: Duplex - **Description**: {stream} ``` -------------------------------- ### Create a load job with metadata Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Load data from a local file with custom metadata, such as encoding and source format. This is useful for overriding default format detection. ```javascript const metadata = { encoding: 'ISO-8859-1', sourceFormat: 'NEWLINE_DELIMITED_JSON' }; table.createLoadJob('./my-data.csv', metadata, callback); ``` -------------------------------- ### query (string, QueryOptions, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Runs a query with a string SQL query, QueryOptions, and an optional callback. ```APIDOC ## query(query, options, callback) ### Description ### Parameters #### Parameters - **query** (string) - Description - **options** (QueryOptions) - Description - **callback** (QueryRowsCallback) - Optional callback function. ### Returns #### Returns - **void** - ``` -------------------------------- ### Get Table Rows (Callback only) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Fetches all rows from a BigQuery table using a callback function. This overload is a simplified version for retrieving all rows without specific options. ```typescript getRows(callback: RowsCallback): void; ``` -------------------------------- ### Get Query Results As Stream (TypeScript) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Use this method when you need to retrieve query results as a stream. It is called internally by `getQueryResultsStream()` and requires the `autoPaginate` option to be set. ```typescript getQueryResultsAsStream_(options: QueryResultsOptions, callback: QueryRowsCallback): void; ``` -------------------------------- ### Create BigQuery Job with Callback Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Create a BigQuery job using the `createJob` method with a callback for handling the response and subsequent query results. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const options = { configuration: { query: { query: 'SELECT url FROM `publicdata.samples.github_nested` LIMIT 100' } } }; bigquery.createJob(options, function(err, job) { if (err) { // Error handling omitted. } job.getQueryResults(function(err, rows) {}); }); ``` -------------------------------- ### Create a BigQuery Routine using Promises Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Use this method to create a new routine in a BigQuery dataset. It returns a Promise that resolves with the routine and API response. Ensure the BigQuery client and dataset are initialized. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('my-dataset'); const id = 'my-routine'; const config = { arguments: [{ name: 'x', dataType: { typeKind: 'INT64' } }], definitionBody: 'x * 3', routineType: 'SCALAR_FUNCTION', returnType: { typeKind: 'INT64' } }; dataset.createRoutine(id, config, (err, routine, apiResponse) => { if (!err) { // The routine was created successfully. } }); ``` ```javascript const [routine, apiResponse] = await dataset.createRoutine(id, config); ``` -------------------------------- ### createLoadJob(source, metadata, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Create a job to load data into this table from a source, with a callback. ```APIDOC ## createLoadJob(source, metadata, callback) ### Description Create a job to load data into this table from a source, with a callback. ### Method `createLoadJob` ### Parameters #### Path Parameters - **source** (string | File | File[]) - Required - The source data for the load job. - **metadata** (JobLoadMetadata) - Optional - Metadata for the load job. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### Get BigQuery Models with Manual Pagination Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Retrieves Model resources with manual pagination control by setting `autoPaginate` to `false`. This allows for custom handling of paginated results using a callback. ```javascript function manualPaginationCallback(err, models, nextQuery, apiResponse) { if (nextQuery) { // More results exist. dataset.getModels(nextQuery, manualPaginationCallback); } } dataset.getModels({ autoPaginate: false }, manualPaginationCallback); ``` -------------------------------- ### dataset(id, options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Creates a reference to a BigQuery dataset. ```APIDOC ## dataset(id, options) ### Description Create a reference to a dataset. ### Parameters #### Path Parameters - **id** (string) - Required - ID of the dataset. - **options** (DatasetOptions) - Optional - Dataset options. ### Returns #### Success Response - **Dataset** - A Dataset object reference. ### Example ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const dataset = bigquery.dataset('higher_education'); ``` ``` -------------------------------- ### Create a BigQuery Table using Promises Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html Create a BigQuery table with a specified ID and metadata, returning a Promise. This is an alternative to the callback-based approach. Ensure the BigQuery client and dataset are initialized. ```javascript const [table, apiResponse] = await dataset.createTable(tableId, options); ``` -------------------------------- ### Get BigQuery Job Query Results Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/job.html Retrieve query results for a BigQuery job. You can fetch all results, customize the number of results, or manually paginate through them. Promises are returned if no callback is provided. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); const job = bigquery.job('job-id'); //- // Get all of the results of a query. //- job.getQueryResults((err, rows) => { if (!err) { // rows is an array of results. } }); //- // Customize the results you want to fetch. //- job.getQueryResults({ maxResults: 100 }, (err, rows) => {}); //- // To control how many API requests are made and page through the results // manually, set `autoPaginate` to `false`. //- function manualPaginationCallback(err, rows, nextQuery, apiResponse) { if (nextQuery) { // More results exist. job.getQueryResults(nextQuery, manualPaginationCallback); } } job.getQueryResults({ autoPaginate: false }, manualPaginationCallback); //- // If the callback is omitted, we'll return a Promise. //- job.getQueryResults().then((data) => { const rows = data[0]; }); ``` -------------------------------- ### List BigQuery Datasets Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Retrieve a list of datasets in a project. Supports callback-based or Promise-based execution, and manual pagination. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); bigquery.getDatasets(function(err, datasets) { if (!err) { // datasets is an array of Dataset objects. } }); ``` ```javascript function manualPaginationCallback(err, datasets, nextQuery, apiResponse) { if (nextQuery) { // More results exist. bigquery.getDatasets(nextQuery, manualPaginationCallback); } } bigquery.getDatasets({ autoPaginate: false }, manualPaginationCallback); ``` ```javascript bigquery.getDatasets().then(function(datasets) {}); ``` -------------------------------- ### getJobs(options) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Retrieves all jobs from your project. Supports pagination control. ```APIDOC ## getJobs(options) ### Description Get all of the jobs from your project. See Jobs: list API Documentation ### Parameters #### Path Parameters - `options` (GetJobsOptions) - Configuration object. ### Returns - `Promise` - A promise that resolves with the list of jobs. ### Example ```javascript const {BigQuery} = require('@google-cloud/bigquery'); const bigquery = new BigQuery(); bigquery.getJobs(function(err, jobs) { if (!err) { // jobs is an array of Job objects. } }); // Manual pagination bigquery.getJobs({ autoPaginate: false }, manualPaginationCallback); function manualPaginationCallback(err, jobs, nextQuery, apiRespose) { if (nextQuery) { bigquery.getJobs(nextQuery, manualPaginationCallback); } } // Using Promises bigquery.getJobs().then(function(data) { const jobs = data[0]; }); ``` ``` -------------------------------- ### createCopyJob(destination, metadata, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Create a job to copy data from this table to a destination table, with a callback. ```APIDOC ## createCopyJob(destination, metadata, callback) ### Description Create a job to copy data from this table to a destination table, with a callback. ### Method `createCopyJob` ### Parameters #### Path Parameters - **destination** (Table) - Required - The destination table. - **metadata** (CopyTableMetadata) - Optional - Metadata to set with the copy operation. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### createLoadJob(source, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Create a job to load data into this table from a source, with a callback. ```APIDOC ## createLoadJob(source, callback) ### Description Create a job to load data into this table from a source, with a callback. ### Method `createLoadJob` ### Parameters #### Path Parameters - **source** (string | File | File[]) - Required - The source data for the load job. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### load(source, metadata, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Load data from a source into a BigQuery table with specified metadata, using a callback for handling the response. ```APIDOC ## load(source, metadata, callback) ### Description Load data from a source into a BigQuery table with specified metadata, using a callback for handling the response. ### Method Signature `load(source: string | File | File[], metadata: JobLoadMetadata, callback: JobMetadataCallback): void;` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **source** (`string | File | File[]`) - Required - The source of the data to load. - **metadata** (`JobLoadMetadata`) - Required - Metadata for the load job. - **callback** (`JobMetadataCallback`) - Required - The callback function to handle the response. ### Response #### Success Response (200) - **void** - This method does not return a value directly; results are handled by the callback. ``` -------------------------------- ### load(source, metadata, callback) Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/table.html Load data into this table from a source, with a callback. ```APIDOC ## load(source, metadata, callback) ### Description Load data into this table from a source, with a callback. ### Method `load` ### Parameters #### Path Parameters - **source** (string | File | File[]) - Required - The source data for the load job. - **metadata** (JobLoadMetadata) - Optional - Metadata for the load job. - **callback** (function) - Optional - A callback function. ### Returns - **Promise** - A promise that resolves with the job response. ``` -------------------------------- ### Import BigQuery Client Library Source: https://docs.cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery Import the BigQuery client library into your Node.js application. ```javascript const {BigQuery} = require('@google-cloud/bigquery'); ```