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

Function main

spanner/rpc-priority-partitioned-dml.js:21–67  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

19'use strict';
20
21async function main(instanceId, databaseId, projectId) {
22 // [START spanner_rpc_priority_partitioned_dml]
23 // Imports the Google Cloud client library.
24 const {Spanner, protos} = require('@google-cloud/spanner');
25 const Priority = protos.google.spanner.v1.RequestOptions.Priority;
26
27 /**
28 * TODO(developer): Uncomment the following lines before running the sample.
29 */
30 // const projectId = 'my-project-id';
31 // const instanceId = 'my-instance';
32 // const databaseId = 'my-database';
33
34 // Creates a client
35 const spanner = new Spanner({
36 projectId: projectId,
37 });
38
39 async function updateUsingPartitionedDmlWithRpcPriority(
40 instanceId,
41 databaseId
42 ) {
43 let database;
44 try {
45 // Gets a reference to a Cloud Spanner instance and database
46 const instance = spanner.instance(instanceId);
47 database = instance.database(databaseId);
48
49 const [rowCount] = await database.runPartitionedUpdate({
50 sql: 'UPDATE Albums SET MarketingBudget = 100000 WHERE SingerId = 1',
51 requestOptions: {
52 priority: Priority.PRIORITY_LOW,
53 },
54 });
55 console.log(
56 `Successfully updated ${rowCount} records using low RPC priority.`
57 );
58 } catch (err) {
59 console.error('ERROR:', err);
60 } finally {
61 // Close the database when finished.
62 await database.close();
63 }
64 }
65 await updateUsingPartitionedDmlWithRpcPriority(instanceId, databaseId);
66 // [END spanner_rpc_priority_partitioned_dml]
67}
68
69main(...process.argv.slice(2));

Callers 1

Tested by

no test coverage detected