Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions datastore/api/src/ancestor_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create an ancestor query.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function ancestor_query(DatastoreClient $datastore)
function ancestor_query(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_ancestor_query]
$ancestorKey = $datastore->key('TaskList', 'default');
$query = $datastore->query()
Expand Down
9 changes: 5 additions & 4 deletions datastore/api/src/array_value.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
namespace Google\Cloud\Samples\Datastore;

use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Key;

/**
* Create a Datastore entity with some array properties.
*
* @param DatastoreClient $datastore
* @param Key $key
* @param string $keyId
* @param string $namespaceId
*/
function array_value(DatastoreClient $datastore, Key $key)
function array_value(string $keyId, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
$key = $datastore->key('Task', $keyId);
// [START datastore_array_value]
$task = $datastore->entity(
$key,
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/array_value_equality.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with equality filters.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function array_value_equality(DatastoreClient $datastore)
function array_value_equality(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_array_value_equality]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/array_value_inequality_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with inequality filters.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function array_value_inequality_range(DatastoreClient $datastore)
function array_value_inequality_range(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_array_value_inequality_range]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/ascending_sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with ascending sort.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function ascending_sort(DatastoreClient $datastore)
function ascending_sort(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_ascending_sort]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/basic_entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
/**
* Create a Datastore entity.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function basic_entity(DatastoreClient $datastore)
function basic_entity(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_basic_entity]
$task = $datastore->entity('Task', [
'category' => 'Personal',
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/basic_gql_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a basic Datastore Gql query.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function basic_gql_query(DatastoreClient $datastore)
function basic_gql_query(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_basic_gql_query]
$gql = <<<EOF
SELECT * from Task
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/basic_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a basic Datastore query.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function basic_query(DatastoreClient $datastore)
function basic_query(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_basic_query]
$query = $datastore->query()
->kind('Task')
Expand Down
9 changes: 5 additions & 4 deletions datastore/api/src/batch_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
namespace Google\Cloud\Samples\Datastore;

use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Key;

/**
* Delete multiple Datastore entities with the given keys.
*
* @param DatastoreClient $datastore
* @param array<Key> $keys
* @param array<string> $keyIds
* @param string $namespaceId
*/
function batch_delete(DatastoreClient $datastore, array $keys)
function batch_delete(array $keyIds, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
$keys = array_map(fn ($keyId) => $datastore->key('Task', $keyId), $keyIds);
// [START datastore_batch_delete]
$result = $datastore->deleteBatch($keys);
// [END datastore_batch_delete]
Expand Down
9 changes: 5 additions & 4 deletions datastore/api/src/batch_lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
namespace Google\Cloud\Samples\Datastore;

use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Key;

/**
* Lookup multiple entities.
*
* @param DatastoreClient $datastore
* @param array<Key> $keys
* @param array<string> $keyIds
* @param string $namespaceId
*/
function batch_lookup(DatastoreClient $datastore, array $keys)
function batch_lookup(array $keyIds, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
$keys = array_map(fn ($keyId) => $datastore->key('Task', $keyId), $keyIds);
// [START datastore_batch_lookup]
$result = $datastore->lookupBatch($keys);
if (isset($result['found'])) {
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/batch_upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
/**
* Upsert multiple Datastore entities.
*
* @param DatastoreClient $datastore
* @param array<EntityInterface> $tasks
* @param string $namespaceId
*/
function batch_upsert(DatastoreClient $datastore, array $tasks)
function batch_upsert(array $tasks, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_batch_upsert]
$result = $datastore->upsertBatch($tasks);
// [END datastore_batch_upsert]
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/composite_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with a composite filter.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function composite_filter(DatastoreClient $datastore)
function composite_filter(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_composite_filter]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/cursor_paging.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
/**
* Fetch a query cursor.
*
* @param DatastoreClient $datastore
* @param int $pageSize
* @param string $pageCursor
* @param string $namespaceId
*/
function cursor_paging(DatastoreClient $datastore, int $pageSize, string $pageCursor = '')
function cursor_paging(int $pageSize, string $pageCursor = '', string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
$query = $datastore->query()
->kind('Task')
->limit($pageSize)
Expand Down
8 changes: 5 additions & 3 deletions datastore/api/src/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
/**
* Delete a Datastore entity with the given key.
*
* @param DatastoreClient $datastore
* @param Key $taskKey
* @param string $namespaceId
* @param string $keyId
*/
function delete(DatastoreClient $datastore, Key $taskKey)
function delete(string $keyId, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
$taskKey = $datastore->key('Task', $keyId);
// [START datastore_delete]
$datastore->delete($taskKey);
// [END datastore_delete]
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/descending_sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with descending sort.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function descending_sort(DatastoreClient $datastore)
function descending_sort(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_descending_sort]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/distinct_on.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create a query with distinctOn.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function distinct_on(DatastoreClient $datastore)
function distinct_on(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_distinct_on_query]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/entity_with_parent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create an entity with a parent key.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function entity_with_parent(DatastoreClient $datastore)
function entity_with_parent(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_entity_with_parent]
$parentKey = $datastore->key('TaskList', 'default');
$key = $datastore->key('Task')->ancestorKey($parentKey);
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/equal_and_inequality_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
* Create a query with equality filters and inequality range filters on a
* single property.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function equal_and_inequality_range(DatastoreClient $datastore)
function equal_and_inequality_range(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_equal_and_inequality_range]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/eventual_consistent_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create and run a query with readConsistency option.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function eventual_consistent_query(DatastoreClient $datastore)
function eventual_consistent_query(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_eventual_consistent_query]
$query = $datastore->query()
->kind('Task')
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/exploding_properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create an entity with two array properties.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function exploding_properties(DatastoreClient $datastore)
function exploding_properties(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_exploding_properties]
$task = $datastore->entity(
$datastore->key('Task'),
Expand Down
6 changes: 4 additions & 2 deletions datastore/api/src/get_or_create.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
/**
* Insert an entity only if there is no entity with the same key.
*
* @param DatastoreClient $datastore
* @param EntityInterface $task
* @param string $namespaceId
*/
function get_or_create(DatastoreClient $datastore, EntityInterface $task)
function get_or_create(EntityInterface $task, string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_transactional_get_or_create]
$transaction = $datastore->transaction();
$entity = $transaction->lookup($task->key());
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/get_task_list_entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Run a query with an ancestor inside a transaction.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function get_task_list_entities(DatastoreClient $datastore)
function get_task_list_entities(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_transactional_single_entity_group_read_only]
$transaction = $datastore->readOnlyTransaction();
$taskListKey = $datastore->key('TaskList', 'default');
Expand Down
5 changes: 3 additions & 2 deletions datastore/api/src/incomplete_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* Create an incomplete Datastore key.
*
* @param DatastoreClient $datastore
* @param string $namespaceId
*/
function incomplete_key(DatastoreClient $datastore)
function incomplete_key(string $namespaceId = null)
{
$datastore = new DatastoreClient(['namespaceId' => $namespaceId]);
// [START datastore_incomplete_key]
$taskKey = $datastore->key('Task');
// [END datastore_incomplete_key]
Expand Down
Loading