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

Function updateUsingDml

spanner/dml.js:66–104  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

64}
65
66async function updateUsingDml(instanceId, databaseId, projectId) {
67 // [START spanner_dml_standard_update]
68 // Imports the Google Cloud client library
69 const {Spanner} = require('@google-cloud/spanner');
70
71 /**
72 * TODO(developer): Uncomment the following lines before running the sample.
73 */
74 // const projectId = 'my-project-id';
75 // const instanceId = 'my-instance';
76 // const databaseId = 'my-database';
77
78 // Creates a client
79 const spanner = new Spanner({
80 projectId: projectId,
81 });
82
83 // Gets a reference to a Cloud Spanner instance and database
84 const instance = spanner.instance(instanceId);
85 const database = instance.database(databaseId);
86
87 try {
88 await database.runTransactionAsync(async transaction => {
89 const [rowCount] = await transaction.runUpdate({
90 sql: `UPDATE Albums SET MarketingBudget = MarketingBudget * 2
91 WHERE SingerId = 1 and AlbumId = 1`,
92 });
93
94 console.log(`Successfully updated ${rowCount} record.`);
95 await transaction.commit();
96 });
97 } catch (err) {
98 console.error('ERROR:', err);
99 } finally {
100 // Close the database when finished.
101 await database.close();
102 }
103 // [END spanner_dml_standard_update]
104}
105
106async function deleteUsingDml(instanceId, databaseId, projectId) {
107 // [START spanner_dml_standard_delete]

Callers 1

dml.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected