| 15 | 'use strict'; |
| 16 | |
| 17 | async function updateWithJsonData(instanceId, databaseId, projectId) { |
| 18 | // [START spanner_update_data_with_json_column] |
| 19 | // Imports the Google Cloud client library. |
| 20 | const {Spanner} = require('@google-cloud/spanner'); |
| 21 | |
| 22 | /** |
| 23 | * TODO(developer): Uncomment the following lines before running the sample. |
| 24 | */ |
| 25 | // const projectId = 'my-project-id'; |
| 26 | // const instanceId = 'my-instance'; |
| 27 | // const databaseId = 'my-database'; |
| 28 | |
| 29 | // Creates a client. |
| 30 | const spanner = new Spanner({ |
| 31 | projectId: projectId, |
| 32 | }); |
| 33 | let database; |
| 34 | try { |
| 35 | // Gets a reference to a Cloud Spanner instance and database. |
| 36 | const instance = spanner.instance(instanceId); |
| 37 | database = instance.database(databaseId); |
| 38 | |
| 39 | // Instantiate Spanner table objects. |
| 40 | const venuesTable = database.table('Venues'); |
| 41 | |
| 42 | const data = [ |
| 43 | { |
| 44 | VenueId: '19', |
| 45 | VenueDetails: {rating: 9, open: true}, |
| 46 | LastUpdateTime: 'spanner.commit_timestamp()', |
| 47 | }, |
| 48 | { |
| 49 | VenueId: '4', |
| 50 | // VenueDetails must be specified as a string, as it contains a top-level |
| 51 | // array of objects that should be inserted into a JSON column. If we were |
| 52 | // to specify this value as an array instead of a string, the client |
| 53 | // library would encode this value as ARRAY<JSON> instead of JSON. |
| 54 | VenueDetails: `[ |
| 55 | { |
| 56 | "name": null, |
| 57 | "open": true |
| 58 | }, |
| 59 | { |
| 60 | "name": "room 2", |
| 61 | "open": false |
| 62 | }, |
| 63 | { |
| 64 | "main hall": { |
| 65 | "description": "this is the biggest space", |
| 66 | "size": 200 |
| 67 | } |
| 68 | } |
| 69 | ]`, |
| 70 | LastUpdateTime: 'spanner.commit_timestamp()', |
| 71 | }, |
| 72 | { |
| 73 | VenueId: '42', |
| 74 | VenueDetails: { |