Skip to content
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

Merged
merged 1 commit into from
Nov 21, 2016
Merged

Update Datastore samples #249

merged 1 commit into from
Nov 21, 2016

Conversation

jmdobry
Copy link
Member

@jmdobry jmdobry commented Nov 8, 2016

Fixes #48
Fixes #234

Brings the code up to >= Node.js v4.3.2 ES2015 features

@stephenplusplus
Copy link
Contributor

stephenplusplus commented Nov 9, 2016

Should GCN be using new Node.js features in our docs as well?

@jmdobry
Copy link
Member Author

jmdobry commented Nov 9, 2016

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 const/let for now.

Copy link
Contributor

@ace-n ace-n left a 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([])),
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jmdobry jmdobry force-pushed the datastore branch 3 times, most recently from 63fd52c to 6b7cb36 Compare November 15, 2016 21:43
datastore.get(taskKey)
.then((results) => {
// Task found.
const entity = results[0];
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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
}

Copy link
Member Author

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]);
Copy link
Contributor

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.)

Copy link
Member Author

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) {
Copy link
Contributor

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?

Copy link
Member Author

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 () {
Copy link
Contributor

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?

Copy link
Member Author

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 = {
Copy link
Contributor

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)

Copy link
Member Author

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!`);
Copy link
Contributor

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?

Copy link
Member Author

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());
Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Member Author

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,
Copy link
Contributor

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:

@codecov-io
Copy link

codecov-io commented Nov 15, 2016

Current coverage is 94.50% (diff: 93.35%)

No coverage report found for master at 073fe3e.

Powered by Codecov. Last update 073fe3e...6b7cb36

@jmdobry
Copy link
Member Author

jmdobry commented Nov 16, 2016

Test failure is unrelated, something to do with a Pub/Sub sample.

@ace-n
Copy link
Contributor

ace-n commented Nov 17, 2016

LGTM once CircleCI is passing and branch is up-to-date.

Fixes #234
Fixes #250

Addressed comments.
@jmdobry jmdobry merged commit 1b3dd3f into master Nov 21, 2016
@jmdobry jmdobry deleted the datastore branch November 21, 2016 23:13
NimJay pushed a commit that referenced this pull request Nov 10, 2022
Fixes #234
Fixes #250

Addressed comments.
NimJay pushed a commit that referenced this pull request Nov 10, 2022
Fixes #234
Fixes #250

Addressed comments.
unforced pushed a commit that referenced this pull request Nov 17, 2022
* 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>
unforced pushed a commit that referenced this pull request Nov 17, 2022
* 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>
unforced pushed a commit that referenced this pull request Nov 17, 2022
* 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>
ahrarmonsur pushed a commit that referenced this pull request Nov 17, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants