| 131 | } |
| 132 | |
| 133 | async function queryWithArrayofStruct(instanceId, databaseId, projectId) { |
| 134 | // Imports the Google Cloud client library |
| 135 | const {Spanner} = require('@google-cloud/spanner'); |
| 136 | |
| 137 | /** |
| 138 | * TODO(developer): Uncomment the following lines before running the sample. |
| 139 | */ |
| 140 | // const projectId = 'my-project-id'; |
| 141 | // const instanceId = 'my-instance'; |
| 142 | // const databaseId = 'my-database'; |
| 143 | |
| 144 | // Creates a client |
| 145 | const spanner = new Spanner({ |
| 146 | projectId: projectId, |
| 147 | }); |
| 148 | |
| 149 | // Gets a reference to a Cloud Spanner instance and database |
| 150 | const instance = spanner.instance(instanceId); |
| 151 | const database = instance.database(databaseId); |
| 152 | |
| 153 | // [START spanner_create_user_defined_struct] |
| 154 | const nameType = { |
| 155 | type: 'struct', |
| 156 | fields: [ |
| 157 | { |
| 158 | name: 'FirstName', |
| 159 | type: 'string', |
| 160 | }, |
| 161 | { |
| 162 | name: 'LastName', |
| 163 | type: 'string', |
| 164 | }, |
| 165 | ], |
| 166 | }; |
| 167 | // [END spanner_create_user_defined_struct] |
| 168 | |
| 169 | // [START spanner_create_array_of_struct_with_data] |
| 170 | const bandMembersType = { |
| 171 | type: 'array', |
| 172 | child: nameType, |
| 173 | }; |
| 174 | |
| 175 | const bandMembers = [ |
| 176 | Spanner.struct({ |
| 177 | FirstName: 'Elena', |
| 178 | LastName: 'Campbell', |
| 179 | }), |
| 180 | Spanner.struct({ |
| 181 | FirstName: 'Gabriel', |
| 182 | LastName: 'Wright', |
| 183 | }), |
| 184 | Spanner.struct({ |
| 185 | FirstName: 'Benjamin', |
| 186 | LastName: 'Martinez', |
| 187 | }), |
| 188 | ]; |
| 189 | // [END spanner_create_array_of_struct_with_data] |
| 190 | |