-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
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 |
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 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
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.
Not necessary because @return
states it's a generator
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.
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) { |
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.
We should make this PHPUnit_Framework_ExpectationFailedException
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 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. |
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.
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 can be pulled in with php-tools v0.5.0
The tests should fail now, but they should pass once the following PRs are submitted. (of course, and also we update the google-cloud-php) |
c4d12e7
to
0eddc3e
Compare
Now the tests are passing with @bshaffer PTAL |
Oh logging test is failing
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" |
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.
Would prefer something closer to semantic versioning here, i.e. ~0.5
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.
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 whengoogle/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.
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.
Unfortunately ~1.0
and ^1.0
don't work because the latest version of google/cloud
is still 0.10.2
.
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 it more intuitive if I do "~1.0|~0.10"
or something like that?
51bc831
to
b710d07
Compare
@bshaffer PTAL |
@@ -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) |
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 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) |
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.
Again, I think these functions (especially this one and array_value
below) are being named too generically. I prefer the older names.
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.
Specifically it matches to the region tags. This pattern matches with nodejs samples.
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 was worried that would be the case :-/
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.
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) |
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.
kindless query? should this be keyless query?
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.
As in Kind
. Got it 👍
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.
It also matches to other languages, specifically nodejs
* Run a given query. | ||
* | ||
* @param DatastoreClient $datastore | ||
* @return \Generator <\Google\Cloud\Datastore\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.
We could add use Generator
above so that the leading backslash isn't necessary. Same with use Google
.
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
@@ -21,6 +21,7 @@ | |||
use Google\Cloud\Datastore\DatastoreClient; | |||
// [END datastore_use ] |
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 extra whitespace
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
Snippets on: https://cloud.google.com/datastore/docs/concepts/queries Also renames for consistensy with other languages.
b710d07
to
4a271b2
Compare
No description provided.