Constructor

Dataset

new Dataset(bigQuery, id)

Interact with your BigQuery dataset. Create a Dataset instance with BigQuery#createDataset or BigQuery#dataset.

Parameter

bigQuery

BigQuery

BigQuery instance.

id

string

The ID of the Dataset.

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

Property

getTablesStream

List all or some of the {module:bigquery/table} objects in your project as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Dataset#getTables for a complete list of options.

Returns

stream 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

dataset.getTablesStream()
  .on('error', console.error)
  .on('data', function(table) {})
  .on('end', function() {
    // All tables have been retrieved
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
dataset.getTablesStream()
  .on('data', function(table) {
    this.end();
  });

Methods

create

create(callback) returns Promise

Create a dataset.

Parameter

callback

Optional

function()

The callback function.

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.create(function(err, dataset, apiResponse) {
  if (!err) {
    // The dataset was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.create().then(function(data) {
  const dataset = data[0];
  const apiResponse = data[1];
});

createQueryJob

createQueryJob(options, callback) returns Promise

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 BigQuery#createQueryJob for full documentation of this method.

Parameter

options

object

See BigQuery#createQueryJob for full documentation of this method.

callback

Optional

function()

See BigQuery#createQueryJob for full documentation of this method.

Returns

Promise 

See BigQuery#createQueryJob for full documentation of this method.

createQueryStream

createQueryStream(options) returns stream

Run a query scoped to your dataset as a readable object stream.

See BigQuery#createQueryStream for full documentation of this method.

Parameter

options

object

See BigQuery#createQueryStream for full documentation of this method.

Returns

stream 

createTable

createTable(id, options, callback) returns Promise

Create a table given a tableId or configuration object.

Parameter

id

string

Table id.

options

Optional

object

See a Table resource.

callback

Optional

function()

The callback function.

See also

Tables: insert API Documentation

Returns

Promise 

Example

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, function(err, table, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.createTable(tableId, options).then(function(data) {
  const table = data[0];
  const apiResponse = data[1];
});

delete

delete(options, callback) returns Promise

Delete the dataset.

Parameter

options

Optional

object

The configuration object.

callback

Optional

function()

The callback function.

See also

Datasets: delete API Documentation

Returns

Promise 

Example

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(function(err, apiResponse) {});

//-
// Delete the dataset and any tables it contains.
//-
dataset.delete({ force: true }, function(err, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.delete().then(function(data) {
  var apiResponse = data[0];
});

exists

exists(callback) returns Promise

Check if the dataset exists.

Parameter

callback

Optional

function()

The callback function.

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.exists(function(err, exists) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.exists().then(function(data) {
  const exists = data[0];
});

get

get(options, callback) returns Promise

Get a dataset if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Parameter

options

Optional

options

Configuration object.

callback

Optional

function()

The callback function.

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.get(function(err, dataset, apiResponse) {
  if (!err) {
    // `dataset.metadata` has been populated.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.get().then(function(data) {
  const dataset = data[0];
  const apiResponse = data[1];
});

getMetadata

getMetadata(callback) returns Promise

Get the metadata for the Dataset.

Parameter

callback

Optional

function()

The callback function.

See also

Datasets: get API Documentation

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.getMetadata(function(err, metadata, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.getMetadata().then(function(data) {
  const metadata = data[0];
  const apiResponse = data[1];
});

getTables

getTables(options, callback) returns Promise

Get a list of tables.

Parameter

options

Optional

object

Configuration object.

callback

Optional

function()

The callback function.

See also

Tables: list API Documentation

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

dataset.getTables(function(err, tables) {
  // tables is an array of `Table` objects.
});

//-
// 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);

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.getTables().then(function(data) {
  var tables = data[0];
});

query

query(options, callback) returns Promise

Run a query scoped to your dataset.

See BigQuery#query for full documentation of this method.

Parameter

options

object

See BigQuery#query for full documentation of this method.

callback

Optional

function()

See BigQuery#query for full documentation of this method.

Returns

Promise 

See BigQuery#query for full documentation of this method.

setMetadata

setMetadata(metadata, callback) returns Promise

Sets the metadata of the Dataset object.

Parameter

metadata

object

Metadata to save on the Dataset.

callback

Optional

function()

The callback function.

See also

Datasets: patch API Documentation

Returns

Promise 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const metadata = {
  description: 'Info for every institution in the 2013 IPEDS universe'
};

dataset.setMetadata(metadata, function(err, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.setMetadata(metadata).then(function(data) {
  const apiResponse = data[0];
});

table

table(id) returns Table

Create a Table object.

Parameter

id

string

The ID of the table.

Returns

Table 

Example

const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const institutions = dataset.table('institution_data');