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

Adding snippets for Datastore queries #181

Merged
merged 4 commits into from
Oct 12, 2016
Merged

Adding snippets for Datastore queries #181

merged 4 commits into from
Oct 12, 2016

Conversation

tmatsuo
Copy link
Contributor

@tmatsuo tmatsuo commented Oct 6, 2016

No description provided.

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Oct 6, 2016

The datastore index!

I created the datastore index manually.

$ gcloud preview datastore --project cloud-samples-tests-php create-indexes index.yaml

{
// [START run_query]
$result = $datastore->runQuery($query);
// Result is a generator of \Google\Cloud\Datastore\Entity
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really feel this line is necessary, but if you feel strongly about it, it should be above the line of code and not below

Copy link
Contributor

@bshaffer bshaffer Oct 7, 2016

Choose a reason for hiding this comment

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

Not necessary because @return states it's a generator

Copy link
Contributor Author

@tmatsuo tmatsuo Oct 7, 2016

Choose a reason for hiding this comment

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

Hm, when you look at the source code on github, yes, it's obvious. But if you look at our docs, it's not.

But I will actually remove the comment. It's easy to guess the result is a list (or generator) and you can loop it with foreach anyways.

try {
$func();
return;
} catch (\Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make this PHPUnit_Framework_ExpectationFailedException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that in this repo, but when we generalize it, I don't think it will work with phpunit 5.x


public function runEventualConsistentTest(Callable $func)
{
// TODO: Generalize and move it to php-tools.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

this can be pulled in with php-tools v0.5.0

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Oct 11, 2016

The tests should fail now, but they should pass once the following PRs are submitted.
googleapis/google-cloud-php#194
googleapis/google-cloud-php#200

(of course, and also we update the google-cloud-php)

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Oct 11, 2016

Now the tests are passing with dev-master branch of the client library :)
I have squashed, rebased, and pushed. Let's see the tests are now stable with our eventual consistent test runner.

@bshaffer PTAL

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Oct 11, 2016

Oh logging test is failing

1) Google\Cloud\Samples\Logging\Tests\ListEntriesCommandTest::testListEntries

I will use the eventual consistent test runner for them too in a different PR: #186

@@ -1,9 +1,10 @@
{
"require": {
"google/cloud": "dev-master"
"google/cloud": "<2.0"
Copy link
Contributor

@bshaffer bshaffer Oct 11, 2016

Choose a reason for hiding this comment

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

Would prefer something closer to semantic versioning here, i.e. ~0.5

Copy link
Contributor Author

@tmatsuo tmatsuo Oct 11, 2016

Choose a reason for hiding this comment

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

It might look weird, but it makes sense to me.

If we pin to the current version, something like 0.10.2 for example, in the future, users who copies this sample will use that pinned version, which might be outdated at the time when they start their project.

If we use something like ~0.10 it works and fetches the current version (0.10.2) now, but when google/cloud 0.11 is released, you will start with the outdated version.

The above statement is incorrect. It will fetch the newer version up to 1.0 (exclusive). It will still be outdated version when google/cloud 1.0 is released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately ~1.0 and ^1.0 don't work because the latest version of google/cloud is still 0.10.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it more intuitive if I do "~1.0|~0.10" or something like that?

@tmatsuo
Copy link
Contributor Author

tmatsuo commented Oct 11, 2016

@bshaffer PTAL
I changed it to forms like "~1.0|~0.10"

@@ -60,9 +61,9 @@ function create_entity(DatastoreClient $datastore)
* @param DatastoreClient $datastore
* @return \Google\Cloud\Datastore\Entity
*/
function upsert_entity(DatastoreClient $datastore)
function upsert(DatastoreClient $datastore)
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer upsert_entity to upsert, and same for below functions. What is the reason for changing it?

@@ -256,7 +257,7 @@ function create_key_with_multi_level_parent(DatastoreClient $datastore)
* @param Key $key
* @return \Google\Cloud\Datastore\Entity
*/
function create_entity_with_option(DatastoreClient $datastore, Key $key)
function properties(DatastoreClient $datastore, Key $key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I think these functions (especially this one and array_value below) are being named too generically. I prefer the older names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically it matches to the region tags. This pattern matches with nodejs samples.

Copy link
Contributor

@bshaffer bshaffer Oct 12, 2016

Choose a reason for hiding this comment

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

I was worried that would be the case :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you really need to change it? The function names here aren't shown to users

* @param Key $lastSeenKey
* @return Query
*/
function kindless_query(DatastoreClient $datastore, Key $lastSeenKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

kindless query? should this be keyless query?

Copy link
Contributor

Choose a reason for hiding this comment

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

As in Kind. Got it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It also matches to other languages, specifically nodejs

* Run a given query.
*
* @param DatastoreClient $datastore
* @return \Generator <\Google\Cloud\Datastore\Entity>
Copy link
Contributor

@bshaffer bshaffer Oct 12, 2016

Choose a reason for hiding this comment

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

We could add use Generator above so that the leading backslash isn't necessary. Same with use Google.

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

@@ -21,6 +21,7 @@
use Google\Cloud\Datastore\DatastoreClient;
// [END datastore_use ]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit extra whitespace

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

@tmatsuo tmatsuo merged commit c239b76 into master Oct 12, 2016
@tmatsuo tmatsuo deleted the more-datastore branch October 12, 2016 19:57
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.

2 participants