Skip to content

feat: Snapshot reads #963

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

Merged
merged 12 commits into from
Jul 26, 2022
Merged

feat: Snapshot reads #963

merged 12 commits into from
Jul 26, 2022

Conversation

danieljbruce
Copy link
Contributor

This implements the snapshot read feature which allows the user to get data from a previous point in time.

@danieljbruce danieljbruce requested review from a team as code owners July 18, 2022 20:49
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Jul 18, 2022
@danieljbruce danieljbruce changed the title Snapshot reads feat: Snapshot reads Jul 18, 2022
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Left a couple small nits.

src/request.ts Outdated
@@ -284,6 +285,16 @@ class DatastoreRequest {
readConsistency: code,
};
}
if (options.readTime) {
if (!reqOpts.readOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

I might make this explicitly, if (reqOpts.readOptions !== undefined).

Since JavaScript is so loose with its truthiness, I like to be explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to if (reqOpts.readOptions === undefined) {

reqOpts.readOptions = {};
}
const readTime = options.readTime;
const seconds = readTime / 1000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you just make this parseInt(readTime / 1000, rather than having the floor? (I'm guessing this type should be an integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parseInt only accepts string as a parameter. Are you sure about this? Should I convert it into a string and then use parseInt?

Copy link
Contributor Author

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

First follow-up

src/request.ts Outdated
@@ -284,6 +285,16 @@ class DatastoreRequest {
readConsistency: code,
};
}
if (options.readTime) {
if (!reqOpts.readOptions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to if (reqOpts.readOptions === undefined) {

reqOpts.readOptions = {};
}
const readTime = options.readTime;
const seconds = readTime / 1000;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parseInt only accepts string as a parameter. Are you sure about this? Should I convert it into a string and then use parseInt?

@@ -308,6 +308,39 @@ describe('Datastore', () => {
await datastore.delete(postKey);
});

// TODO: Modify this
Copy link
Contributor

Choose a reason for hiding this comment

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

still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be removed. Good catch!

},
};
const path = ['Post', 'post1'];
const postKey = datastore.key(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - I would rename this to postKey1 or something similar to reference this is related to post1 rather than post2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same postKey is used for both post1 and post2. There is only one postKey.

await sleep(1000);
// Save new post2 data, but then verify the timestamp read has post1 data
await datastore.save({key: postKey, data: post2});
const [entity] = await datastore.get(postKey, {readTime: savedTime}); // Include new options here
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would be nice to do two of these; one for each post

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@danieljbruce danieljbruce merged commit 0ecca86 into main Jul 26, 2022
@danieljbruce danieljbruce deleted the snapshot-reads branch July 26, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants