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

Function main

spanner/database-update.js:21–79  ·  view source on GitHub ↗
(
  instanceId = 'my-instance',
  databaseId = 'my-database',
  projectId = 'my-project-id'
)

Source from the content-addressed store, hash-verified

19'use strict';
20
21function main(
22 instanceId = 'my-instance',
23 databaseId = 'my-database',
24 projectId = 'my-project-id'
25) {
26 // [START spanner_update_database]
27 /**
28 * TODO(developer): Uncomment these variables before running the sample.
29 */
30 // const instanceId = 'my-instance';
31 // const databaseId = 'my-database';
32 // const projectId = 'my-project-id';
33
34 // Imports the Google Cloud client library
35 const {Spanner} = require('@google-cloud/spanner');
36
37 // creates a client
38 const spanner = new Spanner({
39 projectId: projectId,
40 });
41
42 const databaseAdminClient = spanner.getDatabaseAdminClient();
43
44 async function updateDatabase() {
45 // Update the database metadata fields
46 try {
47 console.log(
48 `Updating database ${databaseAdminClient.databasePath(
49 projectId,
50 instanceId,
51 databaseId
52 )}.`
53 );
54 const [operation] = await databaseAdminClient.updateDatabase({
55 database: {
56 name: databaseAdminClient.databasePath(
57 projectId,
58 instanceId,
59 databaseId
60 ),
61 enableDropProtection: true,
62 },
63 // updateMask contains the fields to be updated in database
64 updateMask: {
65 paths: ['enable_drop_protection'],
66 },
67 });
68 console.log(
69 `Waiting for update operation for ${databaseId} to complete...`
70 );
71 await operation.promise();
72 console.log(`Updated database ${databaseId}.`);
73 } catch (error) {
74 console.error('Failed to update database:', error.message || error);
75 }
76 }
77 updateDatabase();
78 // [END spanner_update_database]

Callers 1

database-update.jsFile · 0.70

Calls 1

updateDatabaseFunction · 0.85

Tested by

no test coverage detected