Table

Table

Create a Table object to interact with a table in a Cloud Spanner database.

Constructor

new Table(database, name)

Parameters:
Name Type Description
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'); ```

Members

database

The Database instance of this Table instance.

name

The name of this table.

Methods

createReadStream(query, optionsopt) → {PartialResultStream}

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

Parameters:
Name Type Attributes Description
query ReadRequest

Configuration object, describing what to read from the table..

options TimestampBounds <optional>

Transaction options.

Returns:
Type Description
PartialResultStream

A readable stream that emits rows.

See:
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(); }); ```