How to use the @google-cloud/spanner.Spanner.struct function in @google-cloud/spanner

To help you get started, we’ve selected a few @google-cloud/spanner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-spanner / samples / dml.js View on Github external
function updateUsingDmlWithStruct(instanceId, databaseId, projectId) {
  // [START spanner_dml_structs]
  // Imports the Google Cloud client library
  const {Spanner} = require('@google-cloud/spanner');

  const nameStruct = Spanner.struct({
    FirstName: 'Timothy',
    LastName: 'Campbell',
  });

  /**
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = 'my-project-id';
  // const instanceId = 'my-instance';
  // const databaseId = 'my-database';

  // Creates a client
  const spanner = new Spanner({
    projectId: projectId,
  });
github googleapis / nodejs-spanner / samples / struct.js View on Github external
* TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = 'my-project-id';
  // const instanceId = 'my-instance';
  // const databaseId = 'my-database';

  // Creates a client
  const spanner = new Spanner({
    projectId: projectId,
  });

  // Gets a reference to a Cloud Spanner instance and database
  const instance = spanner.instance(instanceId);
  const database = instance.database(databaseId);

  const nameStruct = Spanner.struct({
    FirstName: 'Elena',
    LastName: 'Campbell',
  });
  const query = {
    sql: 'SELECT SingerId FROM Singers WHERE FirstName = @name.FirstName',
    params: {
      name: nameStruct,
    },
  };

  // Queries rows from the Singers table
  try {
    const [rows] = await database.run(query);

    rows.forEach(row => {
      const json = row.toJSON();
github googleapis / nodejs-spanner / samples / struct.js View on Github external
async function queryDataWithStruct(instanceId, databaseId, projectId) {
  // [START spanner_create_struct_with_data]
  // Imports the Google Cloud client library
  const {Spanner} = require('@google-cloud/spanner');

  const nameStruct = Spanner.struct({
    FirstName: 'Elena',
    LastName: 'Campbell',
  });
  // [END spanner_create_struct_with_data]

  // [START spanner_query_data_with_struct]
  /**
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = 'my-project-id';
  // const instanceId = 'my-instance';
  // const databaseId = 'my-database';

  // Creates a client
  const spanner = new Spanner({
    projectId: projectId,
github googleapis / nodejs-spanner / samples / struct.js View on Github external
{
        name: 'LastName',
        type: 'string',
      },
    ],
  };
  // [END spanner_create_user_defined_struct]

  // [START spanner_create_array_of_struct_with_data]
  const bandMembersType = {
    type: 'array',
    child: nameType,
  };

  const bandMembers = [
    Spanner.struct({
      FirstName: 'Elena',
      LastName: 'Campbell',
    }),
    Spanner.struct({
      FirstName: 'Gabriel',
      LastName: 'Wright',
    }),
    Spanner.struct({
      FirstName: 'Benjamin',
      LastName: 'Martinez',
    }),
  ];
  // [END spanner_create_array_of_struct_with_data]

  // [START spanner_query_data_with_array_of_struct]
  const query = {
github googleapis / nodejs-spanner / samples / struct.js View on Github external
const songInfoType = {
    type: 'struct',
    fields: [
      {
        name: 'SongName',
        type: 'string',
      },
      {
        name: 'ArtistNames',
        type: 'array',
        child: nameType,
      },
    ],
  };

  const songInfoStruct = Spanner.struct({
    SongName: 'Imagination',
    ArtistNames: [
      Spanner.struct({FirstName: 'Elena', LastName: 'Campbell'}),
      Spanner.struct({FirstName: 'Hannah', LastName: 'Harris'}),
    ],
  });

  const query = {
    sql:
      'SELECT SingerId, @songInfo.SongName FROM Singers ' +
      'WHERE STRUCT(FirstName, LastName) ' +
      'IN UNNEST(@songInfo.ArtistNames)',
    params: {
      songInfo: songInfoStruct,
    },
    types: {
github googleapis / nodejs-spanner / samples / struct.js View on Github external
name: 'SongName',
        type: 'string',
      },
      {
        name: 'ArtistNames',
        type: 'array',
        child: nameType,
      },
    ],
  };

  const songInfoStruct = Spanner.struct({
    SongName: 'Imagination',
    ArtistNames: [
      Spanner.struct({FirstName: 'Elena', LastName: 'Campbell'}),
      Spanner.struct({FirstName: 'Hannah', LastName: 'Harris'}),
    ],
  });

  const query = {
    sql:
      'SELECT SingerId, @songInfo.SongName FROM Singers ' +
      'WHERE STRUCT(FirstName, LastName) ' +
      'IN UNNEST(@songInfo.ArtistNames)',
    params: {
      songInfo: songInfoStruct,
    },
    types: {
      songInfo: songInfoType,
    },
  };
github googleapis / nodejs-spanner / samples / struct.js View on Github external
{
        name: 'SongName',
        type: 'string',
      },
      {
        name: 'ArtistNames',
        type: 'array',
        child: nameType,
      },
    ],
  };

  const songInfoStruct = Spanner.struct({
    SongName: 'Imagination',
    ArtistNames: [
      Spanner.struct({FirstName: 'Elena', LastName: 'Campbell'}),
      Spanner.struct({FirstName: 'Hannah', LastName: 'Harris'}),
    ],
  });

  const query = {
    sql:
      'SELECT SingerId, @songInfo.SongName FROM Singers ' +
      'WHERE STRUCT(FirstName, LastName) ' +
      'IN UNNEST(@songInfo.ArtistNames)',
    params: {
      songInfo: songInfoStruct,
    },
    types: {
      songInfo: songInfoType,
    },
  };

@google-cloud/spanner

Cloud Spanner Client Library for Node.js

Apache-2.0
Latest version published 8 days ago

Package Health Score

86 / 100
Full package analysis