Routine

Routine

Routine objects are returned by methods such as Dataset#routine, Dataset#createRoutine, and Dataset#getRoutines.

Constructor

new Routine(dataset, id)

Parameters:
Name Type Description
dataset Dataset

Dataset instance.

id string

The ID of the routine.

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

const routine = dataset.routine('my_routine');

Methods

create(config, callbackopt) → {Promise.<CreateRoutineResponse>}

Create a routine.

Parameters:
Name Type Attributes Description
config object

A routine resource.

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 routine = dataset.routine('my_routine');

const config = {
  arguments: [{
    name: 'x',
    dataType: {
      typeKind: 'INT64'
    }
  }],
  definitionBody: 'x * 3',
  routineType: 'SCALAR_FUNCTION',
  returnType: {
    typeKind: 'INT64'
  }
};

routine.create(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 routine.create(config);

delete(callbackopt) → {Promise.<DeleteRoutineResponse>}

Deletes a routine.

Parameters:
Name Type Attributes Description
callback DeleteRoutineCallback <optional>

The callback function.

Source:
See:
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const routine = dataset.routine('my_routine');

routine.delete((err, apiResponse) => {});

If the callback is omitted a Promise will be returned

const [apiResponse] = await routine.delete();

exists(callbackopt) → {Promise.<RoutineExistsResponse>}

Check if the routine exists.

Parameters:
Name Type Attributes Description
callback RoutineExistsCallback <optional>

The callback function.

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

routine.exists((err, exists) => {});

If the callback is omitted a Promise will be returned

const [exists] = await routine.exists();

get(callbackopt) → {Promise.<GetRoutineResponse>}

Get a routine if it exists.

Parameters:
Name Type Attributes Description
callback GetRoutineCallback <optional>

The callback function.

Source:
See:
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const routine = dataset.routine('my_routine');

routine.get((err, routine) => {});

If the callback is omitted a Promise will be returned

const [routine2] = await routine.get();

getMetadata(callbackopt) → {Promise.<GetRoutineMetadataResponse>}

Get the metadata associated with a routine.

Parameters:
Name Type Attributes Description
callback GetRoutineMetadataCallback <optional>

The callback function.

Source:
See:
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const routine = dataset.routine('my_routine');

routine.getMetadata((err, metadata, apiResponse) => {});

If the callback is omitted a Promise will be returned

const [metadata, apiResponse] = await routine.getMetadata();

setMetadata(metadata, callbackopt) → {Promise.<SetRoutineMetadataResponse>}

Update a routine.

Parameters:
Name Type Attributes Description
metadata object

A routine resource object.

callback SetRoutineMetadataCallback <optional>

The callback function.

Source:
See:
Examples
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');
const routine = dataset.routine('my_routine');

const updates = {
  description: 'The perfect description!'
};

routine.setMetadata(updates, (err, metadata, apiResponse) => {});

If the callback is omitted a Promise will be returned

const [metadata, apiResponse] = await routine.setMetadata(updates);