Skip to content

Commit 838ee7c

Browse files
author
Ace Nassri
committed
Address comments
1 parent 82e335f commit 838ee7c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

functions/spanner/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
// Imports the Google Cloud client library
2020
const Spanner = require('@google-cloud/spanner');
2121

22-
// Your Google Cloud Platform project ID
23-
const projectId = 'YOUR_PROJECT_ID';
24-
2522
// Instantiates a client
26-
const spanner = Spanner({
27-
projectId: projectId
28-
});
23+
const spanner = Spanner();
2924

3025
// Your Cloud Spanner instance ID
3126
const instanceId = 'my-instance';
@@ -53,9 +48,11 @@ exports.get = (req, res) => {
5348
database.run(query)
5449
.then((results) => {
5550
const rows = results[0];
56-
var data = [];
57-
rows.forEach((row) => data.push(row.toJSON()));
58-
res.send(data);
51+
res.send(rows.map((row) => row.toJSON()));
52+
})
53+
.catch((err) => {
54+
res.status(500);
55+
res.send(`Error querying Spanner: ${err}`);
5956
});
6057
};
6158
// [END spanner_functions_quickstart]

functions/spanner/test/index.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ function getSample () {
6969
};
7070
}
7171

72-
test(`get: Gets albums`, async (t) => {
72+
test(`get: Gets albums`, (t) => {
7373
const sample = getSample();
7474
const mocks = sample.mocks;
7575

76-
const err = await sample.program.get(mocks.req, mocks.res);
77-
t.falsy(err, null);
76+
const err = sample.program.get(mocks.req, mocks.res);
7877
t.true(mocks.spanner.instance.called);
7978
t.true(mocks.instance.database.called);
8079
t.true(mocks.database.run.calledWith(query));

0 commit comments

Comments
 (0)