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

Function queryNestedStructField

spanner/struct.js:272–359  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

270}
271
272async function queryNestedStructField(instanceId, databaseId, projectId) {
273 // [START spanner_field_access_on_nested_struct_parameters]
274 // Imports the Google Cloud client library
275 const {Spanner} = require('@google-cloud/spanner');
276
277 /**
278 * TODO(developer): Uncomment the following lines before running the sample.
279 */
280 // const projectId = 'my-project-id';
281 // const instanceId = 'my-instance';
282 // const databaseId = 'my-database';
283
284 // Creates a client
285 const spanner = new Spanner({
286 projectId: projectId,
287 });
288 let database;
289 try {
290 // Gets a reference to a Cloud Spanner instance and database
291 const instance = spanner.instance(instanceId);
292 database = instance.database(databaseId);
293
294 const nameType = {
295 type: 'struct',
296 fields: [
297 {
298 name: 'FirstName',
299 type: 'string',
300 },
301 {
302 name: 'LastName',
303 type: 'string',
304 },
305 ],
306 };
307
308 // Creates Song info STRUCT with a nested ArtistNames array
309 const songInfoType = {
310 type: 'struct',
311 fields: [
312 {
313 name: 'SongName',
314 type: 'string',
315 },
316 {
317 name: 'ArtistNames',
318 type: 'array',
319 child: nameType,
320 },
321 ],
322 };
323
324 const songInfoStruct = Spanner.struct({
325 SongName: 'Imagination',
326 ArtistNames: [
327 Spanner.struct({FirstName: 'Elena', LastName: 'Campbell'}),
328 Spanner.struct({FirstName: 'Hannah', LastName: 'Harris'}),
329 ],

Callers 1

struct.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected