| 132 | } |
| 133 | |
| 134 | async function queryTableWithTimestamp(instanceId, databaseId, projectId) { |
| 135 | // [START spanner_query_new_table_with_timestamp_column] |
| 136 | // Imports the Google Cloud client library |
| 137 | const {Spanner} = require('@google-cloud/spanner'); |
| 138 | |
| 139 | /** |
| 140 | * TODO(developer): Uncomment the following lines before running the sample. |
| 141 | */ |
| 142 | // const projectId = 'my-project-id'; |
| 143 | // const instanceId = 'my-instance'; |
| 144 | // const databaseId = 'my-database'; |
| 145 | |
| 146 | // Creates a client |
| 147 | const spanner = new Spanner({ |
| 148 | projectId: projectId, |
| 149 | }); |
| 150 | let database; |
| 151 | try { |
| 152 | // Gets a reference to a Cloud Spanner instance and database |
| 153 | const instance = spanner.instance(instanceId); |
| 154 | database = instance.database(databaseId); |
| 155 | |
| 156 | const query = { |
| 157 | sql: `SELECT SingerId, VenueId, EventDate, Revenue, LastUpdateTime |
| 158 | FROM Performances |
| 159 | ORDER BY LastUpdateTime DESC`, |
| 160 | }; |
| 161 | |
| 162 | // Queries rows from the Performances table |
| 163 | const [rows] = await database.run(query); |
| 164 | |
| 165 | rows.forEach(row => { |
| 166 | const json = row.toJSON(); |
| 167 | console.log( |
| 168 | `SingerId: ${json.SingerId}, VenueId: ${json.VenueId}, EventDate: ${json.EventDate}, Revenue: ${json.Revenue}, LastUpdateTime: ${json.LastUpdateTime}` |
| 169 | ); |
| 170 | }); |
| 171 | } catch (err) { |
| 172 | console.error('ERROR:', err); |
| 173 | } finally { |
| 174 | // Close the database when finished |
| 175 | await database.close(); |
| 176 | } |
| 177 | // [END spanner_query_new_table_with_timestamp_column] |
| 178 | } |
| 179 | |
| 180 | async function addTimestampColumn(instanceId, databaseId, projectId) { |
| 181 | // [START spanner_add_timestamp_column] |