(instanceId, databaseId, projectId)
| 19 | 'use strict'; |
| 20 | |
| 21 | async function main(instanceId, databaseId, projectId) { |
| 22 | // [START spanner_rpc_priority_run] |
| 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 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] |
no test coverage detected