MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / addNumericColumn

Function addNumericColumn

spanner/numeric-add-column.js:17–60  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function addNumericColumn(instanceId, databaseId, projectId) {
18 // [START spanner_add_numeric_column]
19
20 /**
21 * TODO(developer): Uncomment the following lines before running the sample.
22 */
23 // const projectId = 'my-project-id';
24 // const instanceId = 'my-instance';
25 // const databaseId = 'my-database';
26
27 // Imports the Google Cloud client library
28 const {Spanner} = require('@google-cloud/spanner');
29
30 // creates a client
31 const spanner = new Spanner({
32 projectId: projectId,
33 });
34
35 const databaseAdminClient = spanner.getDatabaseAdminClient();
36
37 const request = ['ALTER TABLE Venues ADD COLUMN Revenue NUMERIC'];
38 try {
39 // Alter existing table to add a column.
40 const [operation] = await databaseAdminClient.updateDatabaseDdl({
41 database: databaseAdminClient.databasePath(
42 projectId,
43 instanceId,
44 databaseId
45 ),
46 statements: request,
47 });
48
49 console.log(`Waiting for operation on ${databaseId} to complete...`);
50
51 await operation.promise();
52
53 console.log(
54 `Added Revenue column to Venues table in database ${databaseId}.`
55 );
56 } catch (err) {
57 console.error('ERROR:', err);
58 }
59 // [END spanner_add_numeric_column]
60}
61
62module.exports.addNumericColumn = addNumericColumn;

Callers 1

datatypes.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected