Skip to content

Commit 13621f7

Browse files
authored
feat: update region tags and add missing samples (GoogleCloudPlatform#1363)
1 parent 6996c1b commit 13621f7

File tree

63 files changed

+751
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+751
-413
lines changed

firestore/README.md

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -60,78 +60,13 @@ authentication:
6060

6161
## Samples
6262

63-
To run the Cloud Firestore Samples:
64-
65-
$ php firestore.php
66-
Cloud Firestore
67-
68-
Usage:
69-
command [options] [arguments]
70-
71-
Options:
72-
-h, --help Display this help message
73-
-q, --quiet Do not output any message
74-
-V, --version Display this application version
75-
--ansi Force ANSI output
76-
--no-ansi Disable ANSI output
77-
-n, --no-interaction Do not ask any interactive question
78-
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
79-
80-
Available commands:
81-
add-data Add data to a document.
82-
add-doc-data-after-auto-id Auto-generate an ID for a document, then add document data.
83-
add-doc-data-types Set document data with different data types.
84-
add-doc-data-with-auto-id Add document data with an auto-generated ID.
85-
add-subcollection Add a subcollection by creating a new document.
86-
array-membership Create queries using an an array-contains where clause.
87-
batch-write Batch write.
88-
chained-query Create a query with chained clauses.
89-
collection-ref Get a collection reference.
90-
composite-index-chained-query Create a composite index chained query, which combines an equality operator with a range comparison.
91-
create-query-capital Create a query that gets documents where capital=True.
92-
create-query-state Create a query that gets documents where state=CA.
93-
delete-collection Delete a collection.
94-
delete-document Delete a document.
95-
delete-field Delete a field from a document.
96-
delete-test-collections Delete test collections used in these code samples.
97-
document-path-ref Get a document path reference.
98-
document-ref Get a document reference.
99-
end-at-field-query-cursor Define field end point for a query.
100-
get-all-docs Get all documents in a collection.
101-
get-document Get a document.
102-
get-multiple-docs Get multiple documents from a collection.
103-
help Displays help for a command
104-
initialize Initialize Cloud Firestore with default project ID.
105-
initialize-project-id Initialize Cloud Firestore with given project ID.
106-
invalid-range-order-by-query An invalid range with order by query.
107-
invalid-range-query An example of an invalid range query.
108-
list Lists commands
109-
list-subcollections List subcollections of a document.
110-
multiple-cursor-conditions Set multiple cursor conditions.
111-
order-by-name-desc-limit-query Create an order by name descending with limit query.
112-
order-by-name-limit-query Create an order by name with limit query.
113-
order-by-state-and-population-query Create an order by state and descending population query.
114-
paginated-query-cursor Paginate using cursor queries.
115-
query-create-examples Create an example collection of documents.
116-
range-order-by-query Create a range with order by query.
117-
range-query Create a query with range clauses.
118-
retrieve-all-documents Retrieve all documents from a collection.
119-
retrieve-create-examples Create an example collection of documents.
120-
return-info-transaction Return information from your transaction.
121-
run-simple-transaction Run a simple transaction.
122-
set-document Set document data.
123-
set-document-merge Set document data by merging it into the existing document.
124-
set-requires-id Set document data with a given document ID.
125-
simple-queries Create queries using single where clauses.
126-
start-at-field-query-cursor Define field start point for a query.
127-
start-at-snapshot-query-cursor Define snapshot start point for a query.
128-
subcollection-ref Get a reference to a subcollection document.
129-
update-doc Update a document.
130-
update-doc-array Update a document array field.
131-
update-doc-increment Update a document number field using Increment.
132-
update-nested-fields Update fields in nested data.
133-
update-server-timestamp Update field with server timestamp.
134-
where-order-by-limit-query Combine where with order by and limit in a query.
63+
To run the Firestore Samples, run any of the files in `src/` on the CLI:
64+
65+
```
66+
$ php src/add_data.php
67+
Usage: add_data.php $projectId
68+
@param string $projectId The Google Cloud Project ID
69+
```
13570

13671
## The client library
13772

firestore/composer.json

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,5 @@
22
"require": {
33
"google/cloud-firestore": "^1.13",
44
"symfony/console": "^3.0"
5-
},
6-
"autoload": {
7-
"files": [
8-
"src/add_data.php",
9-
"src/add_doc_data_after_auto_id.php",
10-
"src/add_doc_data_types.php",
11-
"src/add_doc_data_with_auto_id.php",
12-
"src/array_membership.php",
13-
"src/array_membership_any.php",
14-
"src/batch_write.php",
15-
"src/chained_query.php",
16-
"src/collection_group_query.php",
17-
"src/collection_group_query_setup.php",
18-
"src/collection_ref.php",
19-
"src/composite_index_chained_query.php",
20-
"src/create_query_capital.php",
21-
"src/create_query_state.php",
22-
"src/delete_collection.php",
23-
"src/delete_doc.php",
24-
"src/delete_field.php",
25-
"src/document_path_ref.php",
26-
"src/document_ref.php",
27-
"src/end_at_field_query_cursor.php",
28-
"src/get_all.php",
29-
"src/get_all_docs.php",
30-
"src/get_distributed_counter_value.php",
31-
"src/get_document.php",
32-
"src/get_multiple_docs.php",
33-
"src/in_array_query.php",
34-
"src/in_query.php",
35-
"src/initialize.php",
36-
"src/initialize_distributed_counter.php",
37-
"src/initialize_project_id.php",
38-
"src/invalid_range_order_by_query.php",
39-
"src/invalid_range_query.php",
40-
"src/list_subcollections.php",
41-
"src/multiple_cursor_conditions.php",
42-
"src/order_by_name_desc_limit_query.php",
43-
"src/order_by_name_limit_query.php",
44-
"src/order_by_state_and_population_query.php",
45-
"src/paginated_query_cursor.php",
46-
"src/query_create_examples.php",
47-
"src/range_order_by_query.php",
48-
"src/range_query.php",
49-
"src/retrieve_create_examples.php",
50-
"src/return_info_transaction.php",
51-
"src/run_simple_transaction.php",
52-
"src/set_document.php",
53-
"src/set_document_merge.php",
54-
"src/set_requires_id.php",
55-
"src/simple_queries.php",
56-
"src/start_at_field_query_cursor.php",
57-
"src/start_at_snapshot_query_cursor.php",
58-
"src/subcollection_ref.php",
59-
"src/update_distributed_counter.php",
60-
"src/update_doc.php",
61-
"src/update_doc_array.php",
62-
"src/update_nested_fields.php",
63-
"src/update_server_timestamp.php",
64-
"src/where_order_by_limit_query.php"
65-
]
665
}
676
}

firestore/src/batch_write.php renamed to firestore/src/data_batch_writes.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,41 @@
2828
/**
2929
* Batch write.
3030
* ```
31-
* batch_write('your-project-id');
31+
* data_batch_writes('your-project-id');
3232
* ```
3333
*/
34-
function batch_write($projectId)
34+
function data_batch_writes($projectId)
3535
{
3636
// Create the Cloud Firestore client
3737
$db = new FirestoreClient([
3838
'projectId' => $projectId,
3939
]);
4040
# [START fs_batch_write]
41+
# [START firestore_data_batch_writes]
4142
$batch = $db->batch();
4243

4344
# Set the data for NYC
44-
$nycRef = $db->collection('cities')->document('NYC');
45+
$nycRef = $db->collection('samples/php/cities')->document('NYC');
4546
$batch->set($nycRef, [
4647
'name' => 'New York City'
4748
]);
4849

4950
# Update the population for SF
50-
$sfRef = $db->collection('cities')->document('SF');
51+
$sfRef = $db->collection('samples/php/cities')->document('SF');
5152
$batch->update($sfRef, [
5253
['path' => 'population', 'value' => 1000000]
5354
]);
5455

5556
# Delete LA
56-
$laRef = $db->collection('cities')->document('LA');
57+
$laRef = $db->collection('samples/php/cities')->document('LA');
5758
$batch->delete($laRef);
5859

5960
# Commit the batch
6061
$batch->commit();
62+
# [END firestore_data_batch_writes]
6163
# [END fs_batch_write]
6264
printf('Batch write successfully completed.' . PHP_EOL);
6365
}
66+
67+
require_once __DIR__ . '/../../testing/sample_helpers.php';
68+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/delete_collection.php renamed to firestore/src/data_delete_collection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
/**
2727
* Delete a collection.
2828
* ```
29-
* delete_collection($collectionReference, $batchSize);
29+
* data_delete_collection($collectionReference, $batchSize);
3030
* ```
3131
*/
32-
3332
# [START fs_delete_collection]
34-
function delete_collection($collectionReference, $batchSize)
33+
# [START firestore_data_delete_collection]
34+
function data_delete_collection($collectionReference, $batchSize)
3535
{
3636
$documents = $collectionReference->limit($batchSize)->documents();
3737
while (!$documents->isEmpty()) {
@@ -42,4 +42,8 @@ function delete_collection($collectionReference, $batchSize)
4242
$documents = $collectionReference->limit($batchSize)->documents();
4343
}
4444
}
45+
# [END firestore_data_delete_collection]
4546
# [END fs_delete_collection]
47+
48+
require_once __DIR__ . '/../../testing/sample_helpers.php';
49+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/delete_doc.php renamed to firestore/src/data_delete_doc.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@
2828
/**
2929
* Delete a document.
3030
* ```
31-
* delete_doc('your-project-id');
31+
* data_delete_doc('your-project-id');
3232
* ```
3333
*/
34-
function delete_doc($projectId)
34+
function data_delete_doc($projectId)
3535
{
3636
// Create the Cloud Firestore client
3737
$db = new FirestoreClient([
3838
'projectId' => $projectId,
3939
]);
4040
# [START fs_delete_doc]
41-
$db->collection('cities')->document('DC')->delete();
41+
# [START firestore_data_delete_doc]
42+
$db->collection('samples/php/cities')->document('DC')->delete();
43+
# [END firestore_data_delete_doc]
4244
# [END fs_delete_doc]
4345
printf('Deleted the DC document in the cities collection.' . PHP_EOL);
4446
}
47+
48+
require_once __DIR__ . '/../../testing/sample_helpers.php';
49+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/delete_field.php renamed to firestore/src/data_delete_field.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,25 @@
2929
/**
3030
* Delete a field from a document.
3131
* ```
32-
* delete_field('your-project-id');
32+
* data_delete_field('your-project-id');
3333
* ```
3434
*/
35-
function delete_field($projectId)
35+
function data_delete_field($projectId)
3636
{
3737
// Create the Cloud Firestore client
3838
$db = new FirestoreClient([
3939
'projectId' => $projectId,
4040
]);
4141
# [START fs_delete_field]
42-
$cityRef = $db->collection('cities')->document('BJ');
42+
# [START firestore_data_delete_field]
43+
$cityRef = $db->collection('samples/php/cities')->document('BJ');
4344
$cityRef->update([
4445
['path' => 'capital', 'value' => FieldValue::deleteField()]
4546
]);
47+
# [END firestore_data_delete_field]
4648
# [END fs_delete_field]
4749
printf('Deleted the capital field from the BJ document in the cities collection.' . PHP_EOL);
4850
}
51+
52+
require_once __DIR__ . '/../../testing/sample_helpers.php';
53+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/get_all_docs.php renamed to firestore/src/data_get_all_documents.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,31 @@
2828
/**
2929
* Get all documents in a collection.
3030
* ```
31-
* get_all_docs('your-project-id');
31+
* data_get_all_documents('your-project-id');
3232
* ```
3333
*/
34-
function get_all_docs($projectId)
34+
function data_get_all_documents($projectId)
3535
{
3636
// Create the Cloud Firestore client
3737
$db = new FirestoreClient([
3838
'projectId' => $projectId,
3939
]);
4040
# [START fs_get_all_docs]
41-
$citiesRef = $db->collection('cities');
41+
# [START firestore_data_get_all_documents]
42+
$citiesRef = $db->collection('samples/php/cities');
4243
$documents = $citiesRef->documents();
4344
foreach ($documents as $document) {
4445
if ($document->exists()) {
4546
printf('Document data for document %s:' . PHP_EOL, $document->id());
4647
print_r($document->data());
4748
printf(PHP_EOL);
4849
} else {
49-
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
50+
printf('Document %s does not exist!' . PHP_EOL, $document->id());
5051
}
5152
}
53+
# [END firestore_data_get_all_documents]
5254
# [END fs_get_all_docs]
5355
}
56+
57+
require_once __DIR__ . '/../../testing/sample_helpers.php';
58+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/get_document.php renamed to firestore/src/data_get_as_map.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@
2828
/**
2929
* Get a single document.
3030
* ```
31-
* get_document('your-project-id');
31+
* data_get_as_map('your-project-id');
3232
* ```
3333
*/
34-
function get_document($projectId)
34+
function data_get_as_map($projectId)
3535
{
3636
// Create the Cloud Firestore client
3737
$db = new FirestoreClient([
3838
'projectId' => $projectId,
3939
]);
4040
# [START fs_get_document]
41-
$docRef = $db->collection('cities')->document('SF');
41+
# [START firestore_data_get_as_map]
42+
$docRef = $db->collection('samples/php/cities')->document('SF');
4243
$snapshot = $docRef->snapshot();
4344

4445
if ($snapshot->exists()) {
@@ -47,5 +48,9 @@ function get_document($projectId)
4748
} else {
4849
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
4950
}
51+
# [END firestore_data_get_as_map]
5052
# [END fs_get_document]
5153
}
54+
55+
require_once __DIR__ . '/../../testing/sample_helpers.php';
56+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

firestore/src/retrieve_create_examples.php renamed to firestore/src/data_get_dataset.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@
2828
/**
2929
* Create an example collection of documents.
3030
* ```
31-
* retrieve_create_examples('your-project-id');
31+
* data_get_dataset('your-project-id');
3232
* ```
3333
*/
34-
function retrieve_create_examples($projectId)
34+
function data_get_dataset($projectId)
3535
{
3636
// Create the Cloud Firestore client
3737
$db = new FirestoreClient([
3838
'projectId' => $projectId,
3939
]);
4040
# [START fs_retrieve_create_examples]
41-
$citiesRef = $db->collection('cities');
41+
# [START firestore_data_get_dataset]
42+
$citiesRef = $db->collection('samples/php/cities');
4243
$citiesRef->document('SF')->set([
4344
'name' => 'San Francisco',
4445
'state' => 'CA',
@@ -75,5 +76,9 @@ function retrieve_create_examples($projectId)
7576
'population' => 21500000
7677
]);
7778
printf('Added example cities data to the cities collection.' . PHP_EOL);
79+
# [END firestore_data_get_dataset]
7880
# [END fs_retrieve_create_examples]
7981
}
82+
83+
require_once __DIR__ . '/../../testing/sample_helpers.php';
84+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)