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

Function insertWithTimestamp

spanner/timestamp.js:71–132  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

69}
70
71async function insertWithTimestamp(instanceId, databaseId, projectId) {
72 // [START spanner_insert_data_with_timestamp_column]
73 // Imports the Google Cloud client library
74 const {Spanner} = require('@google-cloud/spanner');
75
76 /**
77 * TODO(developer): Uncomment the following lines before running the sample.
78 */
79 // const projectId = 'my-project-id';
80 // const instanceId = 'my-instance';
81 // const databaseId = 'my-database';
82
83 // Creates a client
84 const spanner = new Spanner({
85 projectId: projectId,
86 });
87 let database;
88 try {
89 // Gets a reference to a Cloud Spanner instance and database
90 const instance = spanner.instance(instanceId);
91 database = instance.database(databaseId);
92
93 // Instantiate Spanner table objects
94 const performancesTable = database.table('Performances');
95
96 const data = [
97 {
98 SingerId: '1',
99 VenueId: '4',
100 EventDate: '2017-10-05',
101 Revenue: '11000',
102 LastUpdateTime: 'spanner.commit_timestamp()',
103 },
104 {
105 SingerId: '1',
106 VenueId: '19',
107 EventDate: '2017-11-02',
108 Revenue: '15000',
109 LastUpdateTime: 'spanner.commit_timestamp()',
110 },
111 {
112 SingerId: '2',
113 VenueId: '42',
114 EventDate: '2017-12-23',
115 Revenue: '7000',
116 LastUpdateTime: 'spanner.commit_timestamp()',
117 },
118 ];
119
120 // Inserts rows into the Singers table
121 // Note: Cloud Spanner interprets Node.js numbers as FLOAT64s, so
122 // they must be converted to strings before being inserted as INT64s
123 await performancesTable.insert(data);
124 console.log('Inserted data.');
125 } catch (err) {
126 console.error('ERROR:', err);
127 } finally {
128 // Close the database when finished

Callers 1

timestamp.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected