Dataset
Source: dataset.
Interact with your BigQuery dataset. Create a Dataset instance with BigQuery#createDataset or BigQuery#dataset.
Properties
Methods
new Dataset(bigQuery, id[, options])
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| bigQuery | 
 | 
 | BigQuery instance. | ||||||||
| id | 
 | 
 | The ID of the Dataset. | ||||||||
| options | 
 | Yes | Dataset options. Values in  
 | 
Properties
getModelsStream
List all or some of the {module:bigquery/model} objects in your project as a readable object stream.
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.getModelsStream()
  .on('error', console.error)
  .on('data', (model) => {})
  .on('end', () => {
    // All models have been retrieved
  });<caption>If you anticipate many results, you can end a stream
early to prevent unnecessary processing and API requests.</caption>
dataset.getModelsStream()
  .on('data', function(model) {
    this.end();
  });Parameter
| Name | Type | Optional | Description | 
|---|---|---|---|
| options | object | Yes | Configuration object. See Dataset#getModels for a complete list of options. | 
- Returns
- 
                  stream
getTablesStream
List all or some of the {module:bigquery/table} objects in your project as a readable object 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', (table) => {})
  .on('end', () => {
    // 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();
  });Parameter
| Name | Type | Optional | Description | 
|---|---|---|---|
| options | object | Yes | Configuration object. See Dataset#getTables for a complete list of options. | 
- Returns
- 
                  stream
Methods
create([callback]) → Promise
Create a dataset.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.create((err, dataset, apiResponse) => {
  if (!err) {
    // The dataset was created successfully.
  }
});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.create().then((data) => {
  const dataset = data[0];
  const apiResponse = data[1];
});Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| callback | function() | Yes | The callback function. Values in  
 | 
- Returns
- 
                  Promise
createQueryJob(options[, callback]) → 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.
Parameters
| Name | Type | Optional | Description | 
|---|---|---|---|
| options | object | 
 | See BigQuery#createQueryJob for full documentation of this method. | 
| callback | function() | Yes | See BigQuery#createQueryJob for full documentation of this method. | 
- Returns
- 
                  PromiseSee BigQuery#createQueryJob for full documentation of this method. 
createQueryStream(options) → stream
Run a query scoped to your dataset as a readable object stream.
See BigQuery#createQueryStream for full documentation of this method.
Parameter
| Name | Type | Optional | Description | 
|---|---|---|---|
| options | object | 
 | See BigQuery#createQueryStream for full documentation of this method. | 
- Returns
- 
                  stream
createTable(id[, options][, callback]) → Promise
Create a table given a tableId or configuration object.
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, (err, table, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.createTable(tableId, options).then((data) => {
  const table = data[0];
  const apiResponse = data[1];
});Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| id | string | 
 | Table id. | ||||||||||||||||
| options | object | Yes | See a Table resource. Values in  
 | ||||||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
delete([options][, callback]) → Promise
Delete the dataset.
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((err, apiResponse) => {});
//-
// Delete the dataset and any tables it contains.
//-
dataset.delete({ force: true }, (err, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.delete().then((data) => {
  const apiResponse = data[0];
});Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | object | Yes | The configuration object. Values in  
 | ||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
exists([callback]) → Promise
Check if the dataset exists.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.exists((err, exists) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.exists().then((data) => {
  const exists = data[0];
});Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| callback | function() | Yes | The callback function. Values in  
 | 
- Returns
- 
                  Promise
get([options][, callback]) → 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.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.get((err, dataset, apiResponse) => {
  if (!err) {
    // `dataset.metadata` has been populated.
  }
});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.get().then((data) => {
  const dataset = data[0];
  const apiResponse = data[1];
});Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | options | Yes | Configuration object. Values in  
 | ||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- Returns
- 
                  Promise
getMetadata([callback]) → Promise
Get the metadata for the Dataset.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.getMetadata((err, metadata, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.getMetadata().then((data) => {
  const metadata = data[0];
  const apiResponse = data[1];
});Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
getModels([options][, callback]) → Promise
Get a list of models.
Examples
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.
});<caption>To control how many API requests are made and page
through the results manually, set `autoPaginate` to `false`.</caption>
function manualPaginationCallback(err, models, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    dataset.getModels(nextQuery, manualPaginationCallback);
  }
}
dataset.getModels({
  autoPaginate: false
}, manualPaginationCallback);<caption>If the callback is omitted, we'll return a Promise.
</caption>
dataset.getModels().then((data) => {
  const models = data[0];
});Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | object | Yes | Configuration object. Values in  
 | ||||||||||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
getTables([options][, callback]) → Promise
Get a list of tables.
Example
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.
});
//-
// 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((data) => {
  const tables = data[0];
});Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | object | Yes | Configuration object. Values in  
 | ||||||||||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
model(id) → Model
Create a Model object.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
const model = dataset.model('my-model');Parameter
| Name | Type | Optional | Description | 
|---|---|---|---|
| id | string | 
 | The ID of the model. | 
- Throws
- 
                  TypeErrorif model ID is missing. 
- Returns
setMetadata(metadata[, callback]) → Promise
Sets the metadata of the Dataset object.
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, (err, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.setMetadata(metadata).then((data) => {
  const apiResponse = data[0];
});Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| metadata | object | 
 | Metadata to save on the Dataset. | ||||||||||||
| callback | function() | Yes | The callback function. Values in  
 | 
- See also
- Returns
- 
                  Promise
table(id[, options]) → Table
Create a Table object.
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
const institutions = dataset.table('institution_data');Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| id | string | 
 | The ID of the table. | ||||||||
| options | object | Yes | Table options. Values in  
 | 
- Throws
- 
                  TypeErrorif table ID is missing. 
- Returns