Constructor

Table

new Table(database, name)

Parameter

database

Database

Database instance.

name

string

Name of the table.

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();

const instance = spanner.instance('my-instance');
const database = instance.database('my-database');
const table = database.table('my-table');

Properties

database

Database

The Database instance of this Table instance.

name

string

The name of this table.

Method

createReadStream

createReadStream(query, options) returns ReadableStream

Create a readable object stream to receive rows from the database using key lookups and scans.

Parameter

query

ReadRequest

Configuration object. See official ReadRequest. API documentation.

options

Optional

TimestampBounds

Transaction options.

See also

StreamingRead API Documentation

ReadRequest API Documentation

Returns

ReadableStream 

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();

const instance = spanner.instance('my-instance');
const database = instance.database('my-database');
const table = database.table('Singers');

table.createReadStream({
    keys: ['1'],
    columns: ['SingerId', 'name']
  })
  .on('error', function(err) {})
  .on('data', function(row) {
    // row = {
    //   SingerId: '1',
    //   Name: 'Eddie Wilson'
    // }
  })
  .on('end', function() {
    // All results retrieved.
  });

//-
// Provide an array for `query.keys` to read with a composite key.
//-
const query = {
  keys: [
    [
      'Id1',
      'Name1'
    ],
    [
      'Id2',
      'Name2'
    ]
  ],
  // ...
};

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
table.createReadStream({
    keys: ['1'],
    columns: ['SingerId', 'name']
  })
  .on('data', function(row) {
    this.end();
  });