google-cloud-firestore 0.24.0 → 0.24.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00fbe5394269dbb40b8e8927b0d143313a9e6b455896bd92480a5eacb101aee0
4
- data.tar.gz: 6d367282da3a195148e3fbf8b12aa1c9ac8072a173701c4c74a5cd4d6b0e8a13
3
+ metadata.gz: 8fccde9d0d32a88be624c95255dcdcbede69be371428e9f5dc3d7e6e4b59b541
4
+ data.tar.gz: a761abb15eb952a1f555746f8fe2a0ebe2e821954c4f65e55711a270c2c903de
5
5
  SHA512:
6
- metadata.gz: 58a61fa56539fd6c0ca97d25646b6ece469ae060f0a88f7e43e7c9e0bab59aebe26aa8033e0f7b89c410f2b6e5a1a19b6e154264e255feaf8f1794c03018ca50
7
- data.tar.gz: 64080bb166add40d86a2541277c45b77f297115b3b805a458fea896a2dedc873bfbfc0a7d9a6b4501303721a4f03e99016bad64ec998a4dedbdfde547fbfeae5
6
+ metadata.gz: 54d896bf21cffe74009963af0d9a2eebbe187e4e27f1ba4dff85ecc933790e506fb0d3f5729dfc7600dbe3c9a10f14f9729b1e7d494c5944534b1a4444fff33c
7
+ data.tar.gz: 162b854a6bdfe533535b4626b0b3a3669b8c8aa159c21279bb42ec333da840e87d6d32d147e350c5f335aa62a8b883e21491ba46498d9afd1ff1ff84b8d6ae50
data/AUTHENTICATION.md ADDED
@@ -0,0 +1,178 @@
1
+ # Authentication
2
+
3
+ In general, the google-cloud-firestore library uses [Service
4
+ Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5
+ credentials to connect to Google Cloud services. When running on Compute Engine
6
+ the credentials will be discovered automatically. When running on other
7
+ environments, the Service Account credentials can be specified by providing the
8
+ path to the [JSON
9
+ keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
10
+ the account (or the JSON itself) in environment variables. Additionally, Cloud
11
+ SDK credentials can also be discovered automatically, but this is only
12
+ recommended during development.
13
+
14
+ ## Project and Credential Lookup
15
+
16
+ The google-cloud-firestore library aims to make authentication as simple as
17
+ possible, and provides several mechanisms to configure your system without
18
+ providing **Project ID** and **Service Account Credentials** directly in code.
19
+
20
+ **Project ID** is discovered in the following order:
21
+
22
+ 1. Specify project ID in method arguments
23
+ 2. Specify project ID in configuration
24
+ 3. Discover project ID in environment variables
25
+ 4. Discover GCE project ID
26
+
27
+ **Credentials** are discovered in the following order:
28
+
29
+ 1. Specify credentials in method arguments
30
+ 2. Specify credentials in configuration
31
+ 3. Discover credentials path in environment variables
32
+ 4. Discover credentials JSON in environment variables
33
+ 5. Discover credentials file in the Cloud SDK's path
34
+ 6. Discover GCE credentials
35
+
36
+ ### Google Cloud Platform environments
37
+
38
+ While running on Google Cloud Platform environments such as Google Compute
39
+ Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
40
+ The **Project ID** and **Credentials** and are discovered automatically. Code
41
+ should be written as if already authenticated. Just be sure when you [set up the
42
+ GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
43
+ access. For example:
44
+
45
+ * **All APIs**
46
+ * `https://www.googleapis.com/auth/cloud-platform`
47
+ * `https://www.googleapis.com/auth/cloud-platform.read-only`
48
+ * **BigQuery**
49
+ * `https://www.googleapis.com/auth/bigquery`
50
+ * `https://www.googleapis.com/auth/bigquery.insertdata`
51
+ * **Compute Engine**
52
+ * `https://www.googleapis.com/auth/compute`
53
+ * **Datastore**
54
+ * `https://www.googleapis.com/auth/datastore`
55
+ * `https://www.googleapis.com/auth/userinfo.email`
56
+ * **DNS**
57
+ * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
58
+ * **Pub/Sub**
59
+ * `https://www.googleapis.com/auth/pubsub`
60
+ * **Storage**
61
+ * `https://www.googleapis.com/auth/devstorage.full_control`
62
+ * `https://www.googleapis.com/auth/devstorage.read_only`
63
+ * `https://www.googleapis.com/auth/devstorage.read_write`
64
+
65
+ ### Environment Variables
66
+
67
+ The **Project ID** and **Credentials JSON** can be placed in environment
68
+ variables instead of declaring them directly in code. Each service has its own
69
+ environment variable, allowing for different service accounts to be used for
70
+ different services. (See the READMEs for the individual service gems for
71
+ details.) The path to the **Credentials JSON** file can be stored in the
72
+ environment variable, or the **Credentials JSON** itself can be stored for
73
+ environments such as Docker containers where writing files is difficult or not
74
+ encouraged.
75
+
76
+ The environment variables that Firestore checks for project ID are:
77
+
78
+ 1. `FIRESTORE_PROJECT`
79
+ 2. `GOOGLE_CLOUD_PROJECT`
80
+
81
+ The environment variables that Firestore checks for credentials are configured on {Google::Cloud::Firestore::V1beta1::Credentials}:
82
+
83
+ 1. `FIRESTORE_CREDENTIALS` - Path to JSON file, or JSON contents
84
+ 2. `FIRESTORE_KEYFILE` - Path to JSON file, or JSON contents
85
+ 3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
86
+ 4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
87
+ 5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
88
+
89
+ ```ruby
90
+ require "google/cloud/firestore"
91
+
92
+ ENV["FIRESTORE_PROJECT"] = "my-project-id"
93
+ ENV["FIRESTORE_CREDENTIALS"] = "path/to/keyfile.json"
94
+
95
+ firestore = Google::Cloud::Firestore.new
96
+ ```
97
+
98
+ ### Configuration
99
+
100
+ The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
101
+
102
+ ```ruby
103
+ require "google/cloud/firestore"
104
+
105
+ Google::Cloud::Firestore.configure do |config|
106
+ config.project_id = "my-project-id"
107
+ config.credentials = "path/to/keyfile.json"
108
+ end
109
+
110
+ firestore = Google::Cloud::Firestore.new
111
+ ```
112
+
113
+ ### Cloud SDK
114
+
115
+ This option allows for an easy way to authenticate during development. If
116
+ credentials are not provided in code or in environment variables, then Cloud SDK
117
+ credentials are discovered.
118
+
119
+ To configure your system for this, simply:
120
+
121
+ 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
122
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
123
+ 3. Write code as if already authenticated.
124
+
125
+ **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
126
+ *should* only be used during development.
127
+
128
+ [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
129
+ [dev-console]: https://console.cloud.google.com/project
130
+
131
+ [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
132
+
133
+ [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
134
+ [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
135
+ [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
136
+
137
+ ## Creating a Service Account
138
+
139
+ Google Cloud requires a **Project ID** and **Service Account Credentials** to
140
+ connect to the APIs. You will use the **Project ID** and **JSON key file** to
141
+ connect to most services with google-cloud-firestore.
142
+
143
+ If you are not running this client on Google Compute Engine, you need a Google
144
+ Developers service account.
145
+
146
+ 1. Visit the [Google Developers Console][dev-console].
147
+ 1. Create a new project or click on an existing project.
148
+ 1. Activate the slide-out navigation tray and select **API Manager**. From
149
+ here, you will enable the APIs that your application requires.
150
+
151
+ ![Enable the APIs that your application requires][enable-apis]
152
+
153
+ *Note: You may need to enable billing in order to use these services.*
154
+
155
+ 1. Select **Credentials** from the side navigation.
156
+
157
+ You should see a screen like one of the following.
158
+
159
+ ![Create a new service account][create-new-service-account]
160
+
161
+ ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
162
+
163
+ Find the "Add credentials" drop down and select "Service account" to be
164
+ guided through downloading a new JSON key file.
165
+
166
+ If you want to re-use an existing service account, you can easily generate a
167
+ new key file. Just select the account you wish to re-use, and click "Generate
168
+ new JSON key":
169
+
170
+ ![Re-use an existing service account][reuse-service-account]
171
+
172
+ The key file you download will be used by this library to authenticate API
173
+ requests and should be stored in a secure location.
174
+
175
+ ## Troubleshooting
176
+
177
+ If you're having trouble authenticating you can ask for help by following the
178
+ {file:TROUBLESHOOTING.md Troubleshooting Guide}.
data/CHANGELOG.md ADDED
@@ -0,0 +1,50 @@
1
+ # Release History
2
+
3
+ ### 0.24.1 / 2018-09-12
4
+
5
+ * Add missing documentation files to package.
6
+
7
+ ### 0.24.0 / 2018-09-10
8
+
9
+ * Add array_union and array_delete FieldValue configuration.
10
+ * Add array-contains as an operator to the Query#where method.
11
+ * Update documentation.
12
+
13
+ ### 0.23.0 / 2018-08-17
14
+
15
+ * Add Firestore Watch
16
+ * A document reference or a collection reference/query can now be
17
+ listened to for changes.
18
+ * The following methods were added:
19
+ * DocumentReference#listen
20
+ * Query#listen
21
+ * The following classes were added:
22
+ * DocumentSnapshot
23
+ * DocumentChange
24
+ * DocumentListener
25
+ * QuerySnapshot
26
+ * QueryListener
27
+ * Support DocumentSnapshot objects as cursors.
28
+ * Fix mapping of geo Hash to GeoPoint resource.
29
+ * Query#select is no longer additive, it now replaces any previously
30
+ selected fields.
31
+ * Documentation updates.
32
+
33
+ ### 0.22.0 / 2018-07-05
34
+
35
+ * Remove Base64 encoding for BYTES values, as it is unnecessary for gRPC endpoints.
36
+ * Add documentation for enabling gRPC logging.
37
+
38
+ ### 0.21.1 / 2018-05-24
39
+
40
+ * Fix bug where some DocumentReference/DocumentSnapshot actions
41
+ were failing due to a bad object configuration.
42
+ * Updates to documentation and code examples.
43
+
44
+ ### 0.21.0 / 2018-02-27
45
+
46
+ * Add Shared Configuration.
47
+
48
+ ### 0.20.0 / 2018-01-10
49
+
50
+ * First release
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,188 @@
1
+ # Contributing to Google Cloud Firestore
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud-firestore console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud-firestore requires Ruby 2.3+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Firestore dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-firestore/
48
+ $ bundle exec rake bundleupdate
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud-firestore and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-firestore/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Firestore Tests
65
+
66
+ Tests are very important part of google-cloud-firestore. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-firestore/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Firestore Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Firestore unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-firestore/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Firestore Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Firestore documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-firestore/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ### Firestore Acceptance Tests
120
+
121
+ The Firestore acceptance tests interact with the live service API. Follow the
122
+ instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
123
+ the Firestore API. Occasionally, some API features may not yet be generally
124
+ available, making it difficult for some contributors to successfully run the
125
+ entire acceptance test suite. However, please ensure that you do successfully
126
+ run acceptance tests for any code areas covered by your pull request.
127
+
128
+ To run the acceptance tests, first create and configure a project in the Google
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
+ guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
+ the KEYFILE location on your system.
132
+
133
+ Before you can run the Firestore acceptance tests, you must first create indexes
134
+ used in the tests.
135
+
136
+ #### Running the Firestore acceptance tests
137
+
138
+ To run the Firestore acceptance tests:
139
+
140
+ ``` sh
141
+ $ cd google-cloud-firestore/
142
+ $ bundle exec rake acceptance[\\{my-project-id},\\{/path/to/keyfile.json}]
143
+ ```
144
+
145
+ Or, if you prefer you can store the values in the `GCLOUD_TEST_PROJECT` and
146
+ `GCLOUD_TEST_KEYFILE` environment variables:
147
+
148
+ ``` sh
149
+ $ cd google-cloud-firestore/
150
+ $ export GCLOUD_TEST_PROJECT=\\{my-project-id}
151
+ $ export GCLOUD_TEST_KEYFILE=\\{/path/to/keyfile.json}
152
+ $ bundle exec rake acceptance
153
+ ```
154
+
155
+ If you want to use a different project and credentials for acceptance tests, you
156
+ can use the more specific `FIRESTORE_TEST_PROJECT` and `FIRESTORE_TEST_KEYFILE`
157
+ environment variables:
158
+
159
+ ``` sh
160
+ $ cd google-cloud-firestore/
161
+ $ export FIRESTORE_TEST_PROJECT=\\{my-project-id}
162
+ $ export FIRESTORE_TEST_KEYFILE=\\{/path/to/keyfile.json}
163
+ $ bundle exec rake acceptance
164
+ ```
165
+
166
+ ## Coding Style
167
+
168
+ Please follow the established coding style in the library. The style is is
169
+ largely based on [The Ruby Style
170
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
171
+ on seattle-style:
172
+
173
+ * Avoid parenthesis when possible, including in method definitions.
174
+ * Always use double quotes strings. ([Option
175
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
176
+
177
+ You can check your code against these rules by running Rubocop like so:
178
+
179
+ ```sh
180
+ $ cd google-cloud-firestore/
181
+ $ bundle exec rake rubocop
182
+ ```
183
+
184
+ ## Code of Conduct
185
+
186
+ Please note that this project is released with a Contributor Code of Conduct. By
187
+ participating in this project you agree to abide by its terms. See
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/LOGGING.md ADDED
@@ -0,0 +1,32 @@
1
+ # Enabling gRPC Logging
2
+
3
+ To enable logging for this library, set the logger for the underlying
4
+ [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
+ that you set may be a Ruby stdlib
6
+ [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
7
+ shown below, or a
8
+ [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger)
9
+ that will write logs to [Stackdriver
10
+ Logging](https://cloud.google.com/logging/). See
11
+ [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
12
+ and the gRPC
13
+ [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
14
+ for additional information.
15
+
16
+ Configuring a Ruby stdlib logger:
17
+
18
+ ```ruby
19
+ require "logger"
20
+
21
+ module MyLogger
22
+ LOGGER = Logger.new $stderr, level: Logger::WARN
23
+ def logger
24
+ LOGGER
25
+ end
26
+ end
27
+
28
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
29
+ module GRPC
30
+ extend MyLogger
31
+ end
32
+ ```
data/OVERVIEW.md ADDED
@@ -0,0 +1,491 @@
1
+ # Cloud Firestore
2
+
3
+ Cloud Firestore is a NoSQL document database built for automatic scaling, high
4
+ performance, and ease of application development. While the Cloud Firestore
5
+ interface has many of the same features as traditional databases, as a NoSQL
6
+ database it differs from them in the way it describes relationships between data
7
+ objects.
8
+
9
+ For more information about Cloud Firestore, read the [Cloud Firestore
10
+ Documentation](https://cloud.google.com/firestore/docs/).
11
+
12
+ The goal of google-cloud is to provide an API that is comfortable to Rubyists.
13
+ Authentication is handled by {Google::Cloud::Firestore.new Firestore.new}. You
14
+ can provide the project and credential information to connect to the Cloud
15
+ Firestore service, or if you are running on Google Compute Engine this
16
+ configuration is taken care of for you. You can read more about the options for
17
+ connecting in the {file:AUTHENTICATION.md Authentication Guide}.
18
+
19
+ ## Adding data
20
+
21
+ Cloud Firestore stores data in Documents, which are stored in Collections. Cloud
22
+ Firestore creates collections and documents implicitly the first time you add
23
+ data to the document. (For more information, see [Adding Data to Cloud
24
+ Firestore](https://cloud.google.com/firestore/docs/manage-data/add-data).
25
+
26
+ To create or overwrite a single document, use
27
+ {Google::Cloud::Firestore::Client#doc Client#doc} to obtain a document
28
+ reference. (This does not create a document in Cloud Firestore.) Then, call
29
+ {Google::Cloud::Firestore::DocumentReference#set DocumentReference#set} to
30
+ create the document or overwrite an existing document:
31
+
32
+ ```ruby
33
+ require "google/cloud/firestore"
34
+
35
+ firestore = Google::Cloud::Firestore.new
36
+
37
+ # Get a document reference
38
+ nyc_ref = firestore.doc "cities/NYC"
39
+
40
+ nyc_ref.set({ name: "New York City" }) # Document created
41
+ ```
42
+
43
+ When you use this combination of `doc` and `set` to create a new document, you
44
+ must specify an ID for the document. (In the example above, the ID is "NYC".)
45
+ However, if you do not have a meaningful ID for the document, you may omit the
46
+ ID from a call to {Google::Cloud::Firestore::CollectionReference#doc
47
+ CollectionReference#doc}, and Cloud Firestore will auto-generate an ID for you.
48
+
49
+ ```ruby
50
+ require "google/cloud/firestore"
51
+
52
+ firestore = Google::Cloud::Firestore.new
53
+
54
+ # Get a collection reference
55
+ cities_col = firestore.col "cities"
56
+
57
+ # Get a document reference with data
58
+ random_ref = cities_col.doc
59
+ random_ref.set({ name: "New York City" })
60
+
61
+ # The document ID is randomly generated
62
+ random_ref.document_id #=> "RANDOMID123XYZ"
63
+ ```
64
+
65
+ You can perform both of the operations shown above, auto-generating an ID and
66
+ creating the document, in a single call to
67
+ {Google::Cloud::Firestore::CollectionReference#add CollectionReference#add}.
68
+
69
+ ```ruby
70
+ require "google/cloud/firestore"
71
+
72
+ firestore = Google::Cloud::Firestore.new
73
+
74
+ # Get a collection reference
75
+ cities_col = firestore.col "cities"
76
+
77
+ # Get a document reference with data
78
+ random_ref = cities_col.add({ name: "New York City" })
79
+
80
+ # The document ID is randomly generated
81
+ random_ref.document_id #=> "RANDOMID123XYZ"
82
+ ```
83
+
84
+ You can also use `add` to create an empty document:
85
+
86
+ ```ruby
87
+ require "google/cloud/firestore"
88
+
89
+ firestore = Google::Cloud::Firestore.new
90
+
91
+ # Get a collection reference
92
+ cities_col = firestore.col "cities"
93
+
94
+ # Create a document without data
95
+ random_ref = cities_col.add
96
+
97
+ # The document ID is randomly generated
98
+ random_ref.document_id #=> "RANDOMID123XYZ"
99
+ ```
100
+
101
+ ## Retrieving collection references
102
+
103
+ Collections are simply named containers for documents. A collection contains
104
+ documents and nothing else. It can't directly contain raw fields with values,
105
+ and it can't contain other collections. You do not need to "create" or "delete"
106
+ collections. After you create the first document in a collection, the collection
107
+ exists. If you delete all of the documents in a collection, it no longer exists.
108
+ (For more information, see [Cloud Firestore Data
109
+ Model](https://cloud.google.com/firestore/docs/data-model).
110
+
111
+ Use {Google::Cloud::Firestore::Client#cols Client#cols} to list the root-level
112
+ collections:
113
+
114
+ ```ruby
115
+ require "google/cloud/firestore"
116
+
117
+ firestore = Google::Cloud::Firestore.new
118
+
119
+ # Get the root collections
120
+ firestore.cols.each do |col|
121
+ puts col.collection_id
122
+ end
123
+ ```
124
+
125
+ Retrieving a reference to a single root-level collection is similar:
126
+
127
+ ```ruby
128
+ require "google/cloud/firestore"
129
+
130
+ firestore = Google::Cloud::Firestore.new
131
+
132
+ # Get the cities collection
133
+ cities_col = firestore.col "cities"
134
+ ```
135
+
136
+ To list the collections in a document, first get the document reference, then
137
+ use {Google::Cloud::Firestore::DocumentReference#cols DocumentReference#cols}:
138
+
139
+ ```ruby
140
+ require "google/cloud/firestore"
141
+
142
+ firestore = Google::Cloud::Firestore.new
143
+
144
+ # Get a document reference
145
+ nyc_ref = firestore.doc "cities/NYC"
146
+
147
+ nyc_ref.cols.each do |col|
148
+ puts col.collection_id
149
+ end
150
+ ```
151
+
152
+ Again, retrieving a reference to a single collection is similar::
153
+
154
+ ```ruby
155
+ require "google/cloud/firestore"
156
+
157
+ firestore = Google::Cloud::Firestore.new
158
+
159
+ # Get a document reference
160
+ nyc_ref = firestore.doc "cities/NYC"
161
+
162
+ # Get precincts sub-collection
163
+ precincts_col = nyc_ref.col "precincts"
164
+ ```
165
+
166
+ ## Reading data
167
+
168
+ You can retrieve a snapshot of the data in a single document with
169
+ {Google::Cloud::Firestore::DocumentReference#get DocumentReference#get}, which
170
+ returns an instance of {Google::Cloud::Firestore::DocumentSnapshot
171
+ DocumentSnapshot}:
172
+
173
+ ```ruby
174
+ require "google/cloud/firestore"
175
+
176
+ firestore = Google::Cloud::Firestore.new
177
+
178
+ # Get a document reference
179
+ nyc_ref = firestore.doc "cities/NYC"
180
+
181
+ nyc_snap = nyc_ref.get
182
+ nyc_snap[:population] #=> 1000000
183
+ ```
184
+
185
+ In the example above, {Google::Cloud::Firestore::DocumentSnapshot#[]
186
+ DocumentSnapshot#[]} is used to access a top-level field. To access nested
187
+ fields, use {Google::Cloud::Firestore::FieldPath FieldPath}:
188
+
189
+ ```ruby
190
+ require "google/cloud/firestore"
191
+
192
+ firestore = Google::Cloud::Firestore.new
193
+
194
+ user_snap = firestore.doc("users/frank").get
195
+
196
+ nested_field_path = firestore.field_path :favorites, :food
197
+ user_snap.get(nested_field_path) #=> "Pizza"
198
+ ```
199
+
200
+ Or, use {Google::Cloud::Firestore::Client#get_all Client#get_all} to retrieve a
201
+ list of document snapshots (data):
202
+
203
+ ```ruby
204
+ require "google/cloud/firestore"
205
+
206
+ firestore = Google::Cloud::Firestore.new
207
+
208
+ # Get and print city documents
209
+ cities = ["cities/NYC", "cities/SF", "cities/LA"]
210
+ firestore.get_all(cities).each do |city|
211
+ puts "#{city.document_id} has #{city[:population]} residents."
212
+ end
213
+ ```
214
+
215
+ To retrieve all of the document snapshots in a collection, use
216
+ {Google::Cloud::Firestore::CollectionReference#get CollectionReference#get}:
217
+
218
+ ```ruby
219
+ require "google/cloud/firestore"
220
+
221
+ firestore = Google::Cloud::Firestore.new
222
+
223
+ # Get a collection reference
224
+ cities_col = firestore.col "cities"
225
+
226
+ # Get and print all city documents
227
+ cities_col.get do |city|
228
+ puts "#{city.document_id} has #{city[:population]} residents."
229
+ end
230
+ ```
231
+
232
+ The example above is actually a simple query without filters. Let's look at some
233
+ other queries for Cloud Firestore.
234
+
235
+ ## Querying data
236
+
237
+ Use {Google::Cloud::Firestore::Query#where Query#where} to filter queries on a
238
+ field:
239
+
240
+ ```ruby
241
+ require "google/cloud/firestore"
242
+
243
+ firestore = Google::Cloud::Firestore.new
244
+
245
+ # Get a collection reference
246
+ cities_col = firestore.col "cities"
247
+
248
+ # Create a query
249
+ query = cities_col.where(:population, :>=, 1000000)
250
+
251
+ query.get do |city|
252
+ puts "#{city.document_id} has #{city[:population]} residents."
253
+ end
254
+ ```
255
+
256
+ You can order the query results with {Google::Cloud::Firestore::Query#order
257
+ Query#order}:
258
+
259
+ ```ruby
260
+ require "google/cloud/firestore"
261
+
262
+ firestore = Google::Cloud::Firestore.new
263
+
264
+ # Get a collection reference
265
+ cities_col = firestore.col "cities"
266
+
267
+ # Create a query
268
+ query = cities_col.order(:name, :desc)
269
+
270
+ query.get do |city|
271
+ puts "#{city.document_id} has #{city[:population]} residents."
272
+ end
273
+ ```
274
+
275
+ Query methods may be chained, as in this example using
276
+ {Google::Cloud::Firestore::Query#limit Query#limit} and
277
+ {Google::Cloud::Firestore::Query#offset Query#offset} to perform pagination:
278
+
279
+ ```ruby
280
+ require "google/cloud/firestore"
281
+
282
+ firestore = Google::Cloud::Firestore.new
283
+
284
+ # Get a collection reference
285
+ cities_col = firestore.col "cities"
286
+
287
+ # Create a query
288
+ query = cities_col.limit(5).offset(10)
289
+
290
+ query.get do |city|
291
+ puts "#{city.document_id} has #{city[:population]} residents."
292
+ end
293
+ ```
294
+
295
+ See [Managing Indexes in Cloud
296
+ Firestore](https://cloud.google.com/firestore/docs/query-data/indexing) to
297
+ ensure the best performance for your queries.
298
+
299
+ ## Updating data
300
+
301
+ You can use {Google::Cloud::Firestore::DocumentReference#set
302
+ DocumentReference#set} to completely overwrite an existing document:
303
+
304
+ ```ruby
305
+ require "google/cloud/firestore"
306
+
307
+ firestore = Google::Cloud::Firestore.new
308
+
309
+ # Get a document reference
310
+ nyc_ref = firestore.doc "cities/NYC"
311
+
312
+ nyc_ref.set({ name: "New York City" })
313
+ ```
314
+
315
+ Or, to selectively update only the fields appearing in your `data` argument, set
316
+ the `merge` option to `true`:
317
+
318
+ ```ruby
319
+ require "google/cloud/firestore"
320
+
321
+ firestore = Google::Cloud::Firestore.new
322
+
323
+ # Get a document reference
324
+ nyc_ref = firestore.doc "cities/NYC"
325
+
326
+ nyc_ref.set({ name: "New York City" }, merge: true)
327
+ ```
328
+
329
+ Use {Google::Cloud::Firestore::DocumentReference#update
330
+ DocumentReference#update} to directly update a deeply-nested field with a
331
+ {Google::Cloud::Firestore::FieldPath}:
332
+
333
+ ```ruby
334
+ require "google/cloud/firestore"
335
+
336
+ firestore = Google::Cloud::Firestore.new
337
+
338
+ user_ref = firestore.doc "users/frank"
339
+
340
+ nested_field_path = firestore.field_path :favorites, :food
341
+ user_ref.update({ nested_field_path => "Pasta" })
342
+ ```
343
+
344
+ ### Listening for changes
345
+
346
+ You can listen to a document reference or a collection reference/query for
347
+ changes. The current document snapshot or query results snapshot will be yielded
348
+ first, and each time the contents change.
349
+
350
+ You can use {Google::Cloud::Firestore::DocumentReference#listen
351
+ DocumentReference#listen} to be notified of changes to a single document:
352
+
353
+ ```ruby
354
+ require "google/cloud/firestore"
355
+
356
+ firestore = Google::Cloud::Firestore.new
357
+
358
+ # Get a document reference
359
+ nyc_ref = firestore.doc "cities/NYC"
360
+
361
+ listener = nyc_ref.listen do |snapshot|
362
+ puts "The population of #{snapshot[:name]} "
363
+ puts "is #{snapshot[:population]}."
364
+ end
365
+
366
+ # When ready, stop the listen operation and close the stream.
367
+ listener.stop
368
+ ```
369
+
370
+ You can use {Google::Cloud::Firestore::Query#listen Query#listen} to be notified
371
+ of changes to any document contained in the query:
372
+
373
+ ```ruby
374
+ require "google/cloud/firestore"
375
+
376
+ firestore = Google::Cloud::Firestore.new
377
+
378
+ # Create a query
379
+ query = firestore.col(:cities).order(:population, :desc)
380
+
381
+ listener = query.listen do |snapshot|
382
+ puts "The query snapshot has #{snapshot.docs.count} documents "
383
+ puts "and has #{snapshot.changes.count} changes."
384
+ end
385
+
386
+ # When ready, stop the listen operation and close the stream.
387
+ listener.stop
388
+ ```
389
+
390
+ ## Using transactions and batched writes
391
+
392
+ Cloud Firestore supports atomic operations for reading and writing data. In a
393
+ set of atomic operations, either all of the operations succeed, or none of them
394
+ are applied. There are two types of atomic operations in Cloud Firestore: A
395
+ transaction is a set of read and write operations on one or more documents,
396
+ while a batched write is a set of only write operations on one or more
397
+ documents. (For more information, see [Transactions and Batched
398
+ Writes](https://cloud.google.com/firestore/docs/manage-data/transactions).
399
+
400
+ ### Transactions
401
+
402
+ A transaction consists of any number of read operations followed by any number
403
+ of write operations. (Read operations must always come before write operations.)
404
+ In the case of a concurrent update by another client, Cloud Firestore runs the
405
+ entire transaction again. Therefore, transaction blocks should be idempotent and
406
+ should not not directly modify application state.
407
+
408
+ ```ruby
409
+ require "google/cloud/firestore"
410
+
411
+ firestore = Google::Cloud::Firestore.new
412
+
413
+ city = firestore.col("cities").doc("SF")
414
+ city.set({ name: "San Francisco",
415
+ state: "CA",
416
+ country: "USA",
417
+ capital: false,
418
+ population: 860000 })
419
+
420
+ firestore.transaction do |tx|
421
+ new_population = tx.get(city).data[:population] + 1
422
+ tx.update(city, { population: new_population })
423
+ end
424
+ ```
425
+
426
+ ### Batched writes
427
+
428
+ If you do not need to read any documents in your operation set, you can execute
429
+ multiple write operations as a single batch. A batch of writes completes
430
+ atomically and can write to multiple documents. Batched writes are also useful
431
+ for migrating large data sets to Cloud Firestore.
432
+
433
+ ```ruby
434
+ require "google/cloud/firestore"
435
+
436
+ firestore = Google::Cloud::Firestore.new
437
+
438
+ firestore.batch do |b|
439
+ # Set the data for NYC
440
+ b.set("cities/NYC", { name: "New York City" })
441
+
442
+ # Update the population for SF
443
+ b.update("cities/SF", { population: 1000000 })
444
+
445
+ # Delete LA
446
+ b.delete("cities/LA")
447
+ end
448
+ ```
449
+
450
+ ## Deleting data
451
+
452
+ Use {Google::Cloud::Firestore::DocumentReference#delete
453
+ DocumentReference#delete} to delete a document from Cloud Firestore:
454
+
455
+ ```ruby
456
+ require "google/cloud/firestore"
457
+
458
+ firestore = Google::Cloud::Firestore.new
459
+
460
+ # Get a document reference
461
+ nyc_ref = firestore.doc "cities/NYC"
462
+
463
+ nyc_ref.delete
464
+ ```
465
+
466
+ To delete specific fields from a document, use the
467
+ {Google::Cloud::Firestore::Client.field_delete Client.field_delete} method when
468
+ you update a document:
469
+
470
+ ```ruby
471
+ require "google/cloud/firestore"
472
+
473
+ firestore = Google::Cloud::Firestore.new
474
+
475
+ # Get a document reference
476
+ nyc_ref = firestore.doc "cities/NYC"
477
+
478
+ nyc_ref.update({ name: "New York City",
479
+ trash: firestore.field_delete })
480
+ ```
481
+
482
+ To delete an entire collection or sub-collection in Cloud Firestore, retrieve
483
+ all the documents within the collection or sub-collection and delete them. If
484
+ you have larger collections, you may want to delete the documents in smaller
485
+ batches to avoid out-of-memory errors. Repeat the process until you've deleted
486
+ the entire collection or sub-collection.
487
+
488
+ ## Additional information
489
+
490
+ Google Firestore can be configured to use gRPC's logging. To learn more, see the
491
+ {file:LOGGING.md Logging guide}.
@@ -0,0 +1,37 @@
1
+ # Troubleshooting
2
+
3
+ ## Where can I get more help?
4
+
5
+ ### Ask the Community
6
+
7
+ If you have a question about how to use a Google Cloud client library in your
8
+ project or are stuck in the Developer's console and don't know where to turn,
9
+ it's possible your questions have already been addressed by the community.
10
+
11
+ First, check out the appropriate tags on StackOverflow:
12
+ - [`google-cloud-platform+ruby+firestore`][so-ruby]
13
+
14
+ Next, try searching through the issues on GitHub:
15
+
16
+ - [`api:firestore` issues][gh-search-ruby]
17
+
18
+ Still nothing?
19
+
20
+ ### Ask the Developers
21
+
22
+ If you're experiencing a bug with the code, or have an idea for how it can be
23
+ improved, *please* create a new issue on GitHub so we can talk about it.
24
+
25
+ - [New issue][gh-ruby]
26
+
27
+ Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
+ can use the "ruby" channel for general Ruby questions, or use the
29
+ "google-cloud-ruby" channel if you have questions about this gem in particular.
30
+
31
+ [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+firestore
32
+
33
+ [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+firestore%22
34
+
35
+ [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
+
37
+ [slack-ruby]: https://gcp-slack.appspot.com/
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Firestore
19
- VERSION = "0.24.0".freeze
19
+ VERSION = "0.24.1".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-firestore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-10 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-core
@@ -214,8 +214,14 @@ extensions: []
214
214
  extra_rdoc_files: []
215
215
  files:
216
216
  - ".yardopts"
217
+ - AUTHENTICATION.md
218
+ - CHANGELOG.md
219
+ - CODE_OF_CONDUCT.md
220
+ - CONTRIBUTING.md
217
221
  - LICENSE
218
- - README.md
222
+ - LOGGING.md
223
+ - OVERVIEW.md
224
+ - TROUBLESHOOTING.md
219
225
  - lib/google-cloud-firestore.rb
220
226
  - lib/google/cloud/firestore.rb
221
227
  - lib/google/cloud/firestore/batch.rb
data/README.md DELETED
@@ -1,63 +0,0 @@
1
- # Ruby Client for Google Cloud Firestore API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
2
-
3
- [Google Cloud Firestore API][Product Documentation]:
4
-
5
- - [Client Library Documentation][]
6
- - [Product Documentation][]
7
-
8
- ## Quick Start
9
- In order to use this library, you first need to go through the following
10
- steps:
11
-
12
- 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
13
- 2. [Enable the Google Cloud Firestore API.](https://console.cloud.google.com/apis/api/firestore)
14
- 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-firestore/latest/file.AUTHENTICATION)
15
-
16
- ### Installation
17
- ```
18
- $ gem install google-cloud-firestore
19
- ```
20
-
21
- ### Next Steps
22
- - Read the [Client Library Documentation][] for Google Cloud Firestore API
23
- to see other available methods on the client.
24
- - Read the [Google Cloud Firestore API Product documentation][Product Documentation]
25
- to learn more about the product and see How-to Guides.
26
- - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
27
- to see the full list of Cloud APIs that we cover.
28
-
29
- ## Enabling Logging
30
-
31
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
32
-
33
- Configuring a Ruby stdlib logger:
34
-
35
- ```ruby
36
- require "logger"
37
-
38
- module MyLogger
39
- LOGGER = Logger.new $stderr, level: Logger::WARN
40
- def logger
41
- LOGGER
42
- end
43
- end
44
-
45
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
46
- module GRPC
47
- extend MyLogger
48
- end
49
- ```
50
-
51
- ## Supported Ruby Versions
52
-
53
- This library is supported on Ruby 2.3+.
54
-
55
- Google provides official support for Ruby versions that are actively supported
56
- by Ruby Core—that is, Ruby versions that are either in normal maintenance or
57
- in security maintenance, and not end of life. Currently, this means Ruby 2.3
58
- and later. Older versions of Ruby _may_ still work, but are unsupported and not
59
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
60
- about the Ruby support schedule.
61
-
62
- [Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-firestore/latest
63
- [Product Documentation]: https://cloud.google.com/firestore