Skip to content

Commit 9fd795b

Browse files
irrijmdobry
authored andcommitted
Added example with eventual read consistency in Node.js (GoogleCloudPlatform#480)
1 parent 5468b07 commit 9fd795b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

datastore/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Commands:
4747
delete <taskId> Deletes a task.
4848
4949
Options:
50-
--help Show help [boolean]
50+
--version Show version number [boolean]
51+
--help Show help [boolean]
5152
5253
Examples:
5354
node tasks.js new "Buy milk" Adds a task with description "Buy milk".

datastore/concepts.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,25 @@ class Query extends TestHelper {
10331033

10341034
testEventualConsistentQuery (t) {
10351035
t.plan(0);
1036+
const datastoreMock = datastore;
1037+
datastore = this.datastore;
10361038
// [START eventual_consistent_query]
1037-
// Read consistency cannot be specified in google-cloud-node.
1039+
const ancestorKey = datastore.key(['TaskList', 'default']);
1040+
const query = datastore.createQuery('Task')
1041+
.hasAncestor(ancestorKey);
1042+
1043+
query.run({ consistency: 'eventual' });
10381044
// [END eventual_consistent_query]
1045+
return query.run({ consistency: 'eventual' })
1046+
.then((results) => {
1047+
datastore = datastoreMock;
1048+
const entities = results[0];
1049+
return entities;
1050+
})
1051+
.catch((err) => {
1052+
datastore = datastoreMock;
1053+
return Promise.reject(err);
1054+
});
10391055
}
10401056
}
10411057

datastore/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
1010
},
1111
"engines": {
12-
"node": ">=4.3.2"
12+
"node": ">=4"
1313
},
1414
"scripts": {
1515
"lint": "samples lint",
@@ -18,13 +18,13 @@
1818
},
1919
"dependencies": {
2020
"@google-cloud/datastore": "1.1.0",
21-
"yargs": "8.0.2"
21+
"yargs": "9.0.1"
2222
},
2323
"devDependencies": {
2424
"@google-cloud/nodejs-repo-tools": "1.4.17",
25-
"ava": "0.21.0",
25+
"ava": "0.22.0",
2626
"proxyquire": "1.8.0",
27-
"sinon": "3.2.0"
27+
"sinon": "3.3.0"
2828
},
2929
"cloud-repo-tools": {
3030
"requiresKeyFile": true,

0 commit comments

Comments
 (0)