Constructor
new Dataset(bigQuery, id, optionsopt)
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
bigQuery |
BigQuery |
BigQuery instance. |
|||||||||
id |
string |
The ID of the Dataset. |
|||||||||
options |
object |
<optional> |
Dataset options. Properties
|
- Source:
Members
getModelsStream
List all or some of the {module:bigquery/model} objects in your project as a readable object stream.
- Source:
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
});
If you anticipate many results, you can end a stream early to prevent unnecessary processing and API requests.
dataset.getModelsStream()
.on('data', function(model) {
this.end();
});
getTablesStream
List all or some of the {module:bigquery/table} objects in your project as a readable object stream.
- Source:
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();
});
Methods
create(callbackopt) → {Promise}
Create a dataset.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
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];
});
createQueryJob(options, callbackopt) → {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 | Attributes | Description |
---|---|---|---|
options |
object |
See BigQuery#createQueryJob for full documentation of this method. |
|
callback |
function |
<optional> |
See BigQuery#createQueryJob for full documentation of this method. |
- Source:
createQueryStream(options) → {stream}
Run a query scoped to your dataset as a readable object stream.
See BigQuery#createQueryStream for full documentation of this method.
Parameters:
Name | Type | Description |
---|---|---|
options |
object |
See BigQuery#createQueryStream for full documentation of this method. |
- Source:
createRoutine(id, config, callbackopt) → {Promise.<CreateRoutineResponse>}
Create a routine.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
string |
The routine ID. |
|
config |
object | ||
callback |
CreateRoutineCallback |
<optional> |
The callback function. |
- Source:
- See:
Examples
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.
}
});
If the callback is omitted a Promise will be returned
const [routine, apiResponse] = await dataset.createRoutine(id, config);
createTable(id, optionsopt, callbackopt) → {Promise}
Create a table given a tableId or configuration object.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string |
Table id. |
|||||||||||||||||
options |
object |
<optional> |
See a Table resource. Properties
|
||||||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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];
});
delete(optionsopt, callbackopt) → {Promise}
Delete the dataset.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
The configuration object. Properties
|
||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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];
});
exists(callbackopt) → {Promise}
Check if the dataset exists.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
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];
});
get(optionsopt, callbackopt) → {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.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
options |
<optional> |
Configuration object. Properties
|
||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
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];
});
getMetadata(callbackopt) → {Promise}
Get the metadata for the Dataset.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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];
});
getModels(optionsopt, callbackopt) → {Promise}
Get a list of models.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Configuration object. Properties
|
|||||||||||||||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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.
});
To control how many API requests are made and page through the results manually, set `autoPaginate` to `false`.
function manualPaginationCallback(err, models, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
dataset.getModels(nextQuery, manualPaginationCallback);
}
}
dataset.getModels({
autoPaginate: false
}, manualPaginationCallback);
If the callback is omitted, we'll return a Promise.
dataset.getModels().then((data) => {
const models = data[0];
});
getRoutines(optionsopt, callbackopt) → {Promise.<GetRoutinesResponse>}
Get a list of routines.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
GetRoutinesOptions |
<optional> |
Request options. |
callback |
GetRoutinesCallback |
<optional> |
The callback function. |
- Source:
- See:
Examples
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.
});
To control how many API requests are made and page through the results manually, set `autoPaginate` to `false`.
function manualPaginationCallback(err, routines, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
dataset.getRoutines(nextQuery, manualPaginationCallback);
}
}
dataset.getRoutines({
autoPaginate: false
}, manualPaginationCallback);
If the callback is omitted a Promise will be returned
const [routines] = await dataset.getRoutines();
getRoutinesStream(optionsopt) → {stream}
List all or some of the Routine objects in your project as a readable object stream.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
GetRoutinesOptions |
<optional> |
Configuration object. |
- Source:
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
dataset.getRoutinesStream()
.on('error', console.error)
.on('data', (routine) => {})
.on('end', () => {
// All routines have been retrieved
});
If you anticipate many results, you can end a stream early to prevent unnecessary processing and API requests.
dataset.getRoutinesStream()
.on('data', function(routine) {
this.end();
});
getTables(optionsopt, callbackopt) → {Promise}
Get a list of tables.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Configuration object. Properties
|
|||||||||||||||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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];
});
model(id) → {Model}
Create a Model object.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
The ID of the model. |
- Source:
Throws:
-
if model ID is missing.
- Type
- TypeError
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
const model = dataset.model('my-model');
routine(id) → {Routine}
Create a Routine object.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
The ID of the routine. |
- Source:
Throws:
-
if routine ID is missing.
- Type
- TypeError
Example
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');
const routine = dataset.routine('my_routine');
setMetadata(metadata, callbackopt) → {Promise}
Sets the metadata of the Dataset object.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metadata |
object |
Metadata to save on the Dataset. |
|||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
- Source:
- See:
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];
});
table(id, optionsopt) → {Table}
Create a Table object.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
id |
string |
The ID of the table. |
|||||||||
options |
object |
<optional> |
Table options. Properties
|
- Source:
Throws:
-
if table ID is missing.
- Type
- TypeError