new Model(dataset, id)

Example

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

const model = dataset.model('my-model');

Parameters

Name Type Optional Description

dataset

 

 

Dataset instance.

id

 

 

The ID of the model.

Methods

delete([callback]) → Promise

Delete the model.

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const model = dataset.model('my-model');

model.delete((err, apiResponse) => {});
<caption>If the callback is omitted we'll return a Promise.
</caption>
const [apiResponse] = await model.delete();

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

apiResponse

object

 

The full API response.

See also

Models: delete API Documentation

Returns

Promise 

exists([callback]) → Promise

Check if the model exists.

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const model = dataset.model('my-model');

model.exists((err, exists) => {});
<caption>If the callback is omitted we'll return a Promise.
</caption>
const [exists] = await model.exists();

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

exists

boolean

 

Whether the model exists or not.

Returns

Promise 

get:([callback]) → Promise

Get a model if it exists.

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const model = dataset.model('my-model');

model.get(err => {
  if (!err) {
    // `model.metadata` has been populated.
  }
});
<caption>If the callback is omitted we'll return a Promise.
</caption>
await model.get();

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

model

Model

 

The Model.

apiResponse

object

 

The full API response.

See also

Models: get API Documentation

Returns

Promise 

getMetadata([callback]) → Promise

Return the metadata associated with the model.

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const model = dataset.model('my-model');

model.getMetadata((err, metadata, apiResponse) => {});
<caption>If the callback is omitted we'll return a Promise.
</caption>
const [metadata, apiResponse] = await model.getMetadata();

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

metadata

object

 

The metadata of the model.

apiResponse

object

 

The full API response.

See also

Models: get API Documentation

Returns

Promise 

setMetadata(metadata[, callback]) → Promise

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const model = dataset.model('my-model');

const metadata = {
  friendlyName: 'TheBestModelEver'
};

model.setMetadata(metadata, (err, metadata, apiResponse) => {});
<caption>If the callback is omitted we'll return a Promise.
</caption>
const [metadata, apiResponse] = await model.setMetadata(metadata);

Parameters

Name Type Optional Description

metadata

object

 

The metadata key/value object to set.

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

metadata

object

 

The updated metadata of the model.

apiResponse

object

 

The full API response.

See also

Models: patch API Documentation

Returns

Promise