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

Function queryWithRpcPriority

spanner/rpc-priority-run.js:39–76  ·  view source on GitHub ↗
(instanceId, databaseId)

Source from the content-addressed store, hash-verified

37 });
38
39 async function queryWithRpcPriority(instanceId, databaseId) {
40 let database;
41 try {
42 // Gets a reference to a Cloud Spanner instance and database.
43 const instance = spanner.instance(instanceId);
44 database = instance.database(databaseId);
45
46 const sql = `SELECT AlbumId, AlbumTitle, MarketingBudget
47 FROM Albums
48 ORDER BY AlbumTitle`;
49
50 // Execute a query with low priority. Note that the default for all
51 // requests is PRIORITY_HIGH, and that this option can only be used to
52 // reduce the priority of a request.
53 const [rows] = await database.run({
54 sql,
55 requestOptions: {
56 priority: Priority.PRIORITY_LOW,
57 },
58 json: true,
59 });
60
61 console.log(
62 `Successfully fetched ${rows.length} rows using low RPC priority.`
63 );
64
65 rows.forEach(row => {
66 console.log(
67 `AlbumId: ${row.AlbumId}, AlbumTitle: ${row.AlbumTitle}, MarketingBudget: ${row.MarketingBudget}`
68 );
69 });
70 } catch (err) {
71 console.error('ERROR:', err);
72 } finally {
73 // Close the database when finished.
74 await database.close();
75 }
76 }
77 await queryWithRpcPriority(instanceId, databaseId);
78 // [END spanner_rpc_priority_run]
79}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected