-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of Google Cloud Datastore (#101)
* Implementation of Google Cloud Datastore * Refactor API * Implement __get and __set on Datastore\Entity * Datastore entity properties can now be referenced by their names as if they were properties on the instantiated object. Example: ```php $key = $datastore->key('Person', 'Bob'); $entity = $datastore->entity($key, [ 'firstName' => 'Bob', 'lastName' => 'Testguy' ]); $firstName = $entity['firstName']; // is equivalent to $firstName = $entity->firstName; ``` * IDs are allocated in `insertBatch()` rather than `keys()` * Updating entities is now safer. When running `updateBatch()` or `upsertBatch(), manually created entities will not save unless the `allowOverwrite` flag is set. This prevents accidental overwrite of existing data. * DateTime fields now transform back and forth as expected/ * `excludeFromIndexes` is now supported for entity keys. * Transactions have been refactored and improved. * Operation still exists, but it works as an underlying internal API for code reuse, rather than for direct interaction. It supplies functionality to DatastoreClient and Transaction. * Fix namespace propogation and map keys in entity save/fetch * Return useful response from mutate methods * Support concurrency control with baseVersion * Update to API v1 * Code review resolutions * Reorder filter parameters, add short comparison operators * Refactor, support Geopoints * Code review fixes * Update entity mapping * Support mapping different kinds to types
- Loading branch information
Showing
33 changed files
with
8,333 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ This client supports the following Google Cloud Platform services: | |
* [Google BigQuery](#google-bigquery) | ||
* [Google Stackdriver Logging](#google-stackdriver-logging) | ||
* [Google Translate](#google-translate) | ||
* [Google Cloud Datastore](#google-cloud-datastore) | ||
* [Google Cloud Natural Language](#google-cloud-natural-language) | ||
* [Google Cloud Pub/Sub](#google-cloud-pubsub) | ||
* [Google Cloud Storage](#google-cloud-storage) | ||
|
@@ -145,6 +146,37 @@ foreach ($languages as $language) { | |
} | ||
``` | ||
|
||
## Google Cloud Datastore | ||
|
||
- [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/datastore/datastoreclient) | ||
- [Official Documentation](https://cloud.google.com/datastore/docs/) | ||
|
||
#### Preview | ||
|
||
```php | ||
require 'vendor/autoload.php'; | ||
|
||
use Google\Cloud\Datastore\DatastoreClient; | ||
|
||
$datastore = new DatastoreClient([ | ||
'projectId' => 'my_project' | ||
]); | ||
|
||
// Create an entity | ||
$bob = $datastore->entity('Person'); | ||
$bob['firstName'] = 'Bob'; | ||
$bob['email'] = '[email protected]'; | ||
$datastore->insert($bob); | ||
|
||
// Fetch an entity | ||
$key = $datastore->key('Person', 'Bob'); | ||
$bob = $datastore->lookup($key); | ||
|
||
// Update an entity | ||
$bob['email'] = '[email protected]'; | ||
$datastore->update($bob); | ||
``` | ||
|
||
## Google Cloud Natural Language | ||
|
||
- [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/naturallanguage/naturallanguageclient) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Datastore\Connection; | ||
|
||
/** | ||
* Represents a connection to | ||
* [Datastore](https://cloud.google.com/datastore/). | ||
*/ | ||
interface ConnectionInterface | ||
{ | ||
/** | ||
* @param array $args | ||
*/ | ||
public function allocateIds(array $args); | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function beginTransaction(array $args); | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function commit(array $args); | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function lookup(array $args); | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function rollback(array $args); | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function runQuery(array $args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Datastore\Connection; | ||
|
||
use Google\Cloud\RequestBuilder; | ||
use Google\Cloud\RequestWrapper; | ||
use Google\Cloud\RestTrait; | ||
use Google\Cloud\UriTrait; | ||
|
||
/** | ||
* Implementation of the | ||
* [Google Datastore JSON API](https://cloud.google.com/datastore/reference/rest/). | ||
*/ | ||
class Rest implements ConnectionInterface | ||
{ | ||
use RestTrait; | ||
use UriTrait; | ||
|
||
const BASE_URI = 'https://datastore.googleapis.com/'; | ||
|
||
/** | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config = []) | ||
{ | ||
$this->setRequestWrapper(new RequestWrapper($config)); | ||
$this->setRequestBuilder(new RequestBuilder( | ||
__DIR__ . '/ServiceDefinition/datastore-v1.json', | ||
self::BASE_URI | ||
)); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function allocateIds(array $args) | ||
{ | ||
return $this->send('projects', 'allocateIds', $args); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function beginTransaction(array $args) | ||
{ | ||
return $this->send('projects', 'beginTransaction', $args); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function commit(array $args) | ||
{ | ||
return $this->send('projects', 'commit', $args); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function lookup(array $args) | ||
{ | ||
return $this->send('projects', 'lookup', $args); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function rollback(array $args) | ||
{ | ||
return $this->send('projects', 'rollback', $args); | ||
} | ||
|
||
/** | ||
* @param array $args | ||
*/ | ||
public function runQuery(array $args) | ||
{ | ||
return $this->send('projects', 'runQuery', $args); | ||
} | ||
} |
Oops, something went wrong.