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

Function main

spanner/get-database-roles.js:21–69  ·  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
21async function main(
22 instanceId = 'my-instance',
23 databaseId = 'my-database',
24 projectId = 'my-project-id'
25) {
26 // [START spanner_list_database_roles]
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 getDatabaseRoles() {
45 try {
46 const dbPath = databaseAdminClient.databasePath(
47 projectId,
48 instanceId,
49 databaseId
50 );
51
52 // Fetching database roles
53 const [databaseRoles] = await databaseAdminClient.listDatabaseRoles({
54 parent: dbPath,
55 });
56
57 console.log(`Roles for Database: ${dbPath}`);
58 databaseRoles.forEach(role => {
59 console.log(`Role: ${role.name}`);
60 });
61 } catch (err) {
62 console.error('Error listing database roles:', err);
63 } finally {
64 spanner.close();
65 }
66 }
67 await getDatabaseRoles();
68 // [END spanner_list_database_roles]
69}
70
71process.on('unhandledRejection', err => {
72 console.error(err.message);

Callers 1

Calls 1

getDatabaseRolesFunction · 0.85

Tested by

no test coverage detected