-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Datastore samples #249
Conversation
Should GCN be using new Node.js features in our docs as well? |
That's up to you, though I would say in 4-6 months you're definitely safe changing your docs examples to use features that require Node.js >= v4.3.2 In these samples we're only adopting arrow functions, template strings, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Disregard this comment)
runQuery: function () {}, | ||
save: function () {} | ||
let datastore = { | ||
delete: sinon.stub().returns(Promise.resolve([])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is there a good way to make this less repetitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
63fd52c
to
6b7cb36
Compare
datastore.get(taskKey) | ||
.then((results) => { | ||
// Task found. | ||
const entity = results[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this block seems a bit long - is console.log(results[0])
too short?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how they wanted it
this.datastore.runQuery(query, callback); | ||
}; | ||
return { | ||
priorities: priorities, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do the following (per ES6), or is it not explicit enough?
return {
priorities,
percentCompletes
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of doing this in user visible code, because I don't think it's the clearest ES2015 feature. If a user doesn't understand that feature, they'll just see a syntax error.
// the `endCursor` property. | ||
return runPageQuery(info.endCursor) | ||
.then((results) => { | ||
results[0] = entities.concat(results[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was confusing at first - perhaps add a comment explaining it? (e.g. Add current results to results list
or something like that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
const entities = results[0]; | ||
assert.equal(Array.isArray(entities), true); | ||
const info = results[1]; | ||
if (!info || !info.endCursor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is info.endCursor
going to be set if no more results are available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It will have a field that says "NO_MORE_RESULTS"
|
||
transaction.save(accounts); | ||
testEventualConsistentQuery () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They show it in the docs...
} | ||
callback(); | ||
}); | ||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ES6 to shorten this? (e.g. Entity: Entity
--> Entity
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see #249 (comment)
describe(`datastore:concepts`, () => { | ||
before(() => { | ||
const projectId = process.env.GCLOUD_PROJECT; | ||
assert(projectId, `You must set the GCLOUD_PROJECT env var!`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this conform to our standards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it does.
|
||
describe(`Transactions`, () => { | ||
it(`performs a transactional update`, () => transaction.testTransactionalUpdate()); | ||
it(`performs retries if necessary`, () => transaction.testTransactionalRetry()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern probably needs to be changed to fit our existing test standards - if not now, then later.
const task = results[0]; | ||
task.done = true; | ||
transaction.save({ | ||
key: taskKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can this be compressed by using ES6 and renaming variables? e.g. key: taskKey
==> key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see #249 (comment)
deleteEntity: deleteTask, | ||
main: function (args) { | ||
const program = module.exports = { | ||
addTask: addTask, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can this be compressed by using ES6 and renaming variables? e.g. `markDone:
Current coverage is 94.50% (diff: 93.35%)
|
Test failure is unrelated, something to do with a Pub/Sub sample. |
LGTM once CircleCI is passing and branch is up-to-date. |
* chore(main): release 4.0.4 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
* chore(main): release 4.0.4 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
* updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
* chore(main): release 4.0.4 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Fixes #48
Fixes #234
Brings the code up to >= Node.js v4.3.2 ES2015 features