Skip to content

Commit a410dfb

Browse files
docs(spanner): migrate quickstart sample
Migrates quickstart.js from googleapis/nodejs-spanner and enables its test suite in spanner.test.js.
1 parent e29c4b7 commit a410dfb

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

spanner/quickstart.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function quickstart(
18+
projectId = 'YOUR-PROJECT-ID', // Your Google Cloud Platform project ID
19+
instanceId = 'my-instance', // Your Cloud Spanner instance ID
20+
databaseId = 'my-database', // Your Cloud Spanner database ID
21+
) {
22+
// [START spanner_quickstart]
23+
// Imports the Google Cloud client library
24+
const {Spanner} = require('@google-cloud/spanner');
25+
26+
// Creates a client
27+
const spanner = new Spanner({projectId});
28+
29+
// Gets a reference to a Cloud Spanner instance and database
30+
const instance = spanner.instance(instanceId);
31+
const database = instance.database(databaseId);
32+
33+
// The query to execute
34+
const query = {
35+
sql: 'SELECT 1',
36+
};
37+
38+
// Execute a simple SQL statement
39+
const [rows] = await database.run(query);
40+
console.log(`Query: ${rows.length} found.`);
41+
rows.forEach(row => console.log(row));
42+
// [END spanner_quickstart]
43+
}
44+
45+
const args = process.argv.slice(2);
46+
quickstart(...args).catch(console.error);

spanner/system-test/spanner.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Google LLC
1+
// Copyright 2026 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -585,7 +585,7 @@ describe('Autogenerated Admin Clients', () => {
585585
});
586586
});
587587

588-
describe.skip('quickstart', () => {
588+
describe('quickstart', () => {
589589
// Running the quickstart test in here since there's already a spanner
590590
// instance and database set up at this point.
591591
it('should query a table', async () => {

0 commit comments

Comments
 (0)