google-cloud-firestore 0.23.0 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +10 -2
- data/README.md +4 -4
- data/lib/google-cloud-firestore.rb +5 -4
- data/lib/google/cloud/firestore.rb +2 -505
- data/lib/google/cloud/firestore/client.rb +50 -0
- data/lib/google/cloud/firestore/convert.rb +69 -50
- data/lib/google/cloud/firestore/field_value.rb +96 -1
- data/lib/google/cloud/firestore/query.rb +34 -14
- data/lib/google/cloud/firestore/v1beta1.rb +6 -0
- data/lib/google/cloud/firestore/v1beta1/credentials.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +3 -2
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +21 -20
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +2 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +14 -8
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/empty.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +9 -6
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +1 -0
- data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +16 -14
- data/lib/google/cloud/firestore/version.rb +1 -1
- data/lib/google/firestore/v1beta1/common_pb.rb +1 -0
- data/lib/google/firestore/v1beta1/document_pb.rb +1 -0
- data/lib/google/firestore/v1beta1/firestore_pb.rb +1 -0
- data/lib/google/firestore/v1beta1/firestore_services_pb.rb +1 -0
- data/lib/google/firestore/v1beta1/query_pb.rb +1 -0
- data/lib/google/firestore/v1beta1/write_pb.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00fbe5394269dbb40b8e8927b0d143313a9e6b455896bd92480a5eacb101aee0
|
4
|
+
data.tar.gz: 6d367282da3a195148e3fbf8b12aa1c9ac8072a173701c4c74a5cd4d6b0e8a13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a61fa56539fd6c0ca97d25646b6ece469ae060f0a88f7e43e7c9e0bab59aebe26aa8033e0f7b89c410f2b6e5a1a19b6e154264e255feaf8f1794c03018ca50
|
7
|
+
data.tar.gz: 64080bb166add40d86a2541277c45b77f297115b3b805a458fea896a2dedc873bfbfc0a7d9a6b4501303721a4f03e99016bad64ec998a4dedbdfde547fbfeae5
|
data/.yardopts
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
--no-private
|
2
2
|
--title=Google Cloud Firestore API
|
3
|
-
--exclude
|
3
|
+
--exclude _pb\.rb$
|
4
4
|
--markup markdown
|
5
5
|
--markup-provider redcarpet
|
6
|
+
--main OVERVIEW.md
|
6
7
|
|
7
8
|
./lib/**/*.rb
|
8
9
|
-
|
9
|
-
|
10
|
+
OVERVIEW.md
|
11
|
+
AUTHENTICATION.md
|
12
|
+
LOGGING.md
|
13
|
+
CONTRIBUTING.md
|
14
|
+
TROUBLESHOOTING.md
|
15
|
+
CHANGELOG.md
|
16
|
+
CODE_OF_CONDUCT.md
|
17
|
+
LICENSE
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ steps:
|
|
11
11
|
|
12
12
|
1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
|
13
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
|
14
|
+
3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-firestore/latest/file.AUTHENTICATION)
|
15
15
|
|
16
16
|
### Installation
|
17
17
|
```
|
@@ -28,7 +28,7 @@ $ gem install google-cloud-firestore
|
|
28
28
|
|
29
29
|
## Enabling Logging
|
30
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
|
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
32
|
|
33
33
|
Configuring a Ruby stdlib logger:
|
34
34
|
|
@@ -59,5 +59,5 @@ and later. Older versions of Ruby _may_ still work, but are unsupported and not
|
|
59
59
|
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
60
60
|
about the Ruby support schedule.
|
61
61
|
|
62
|
-
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby
|
63
|
-
[Product Documentation]: https://cloud.google.com/firestore
|
62
|
+
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-firestore/latest
|
63
|
+
[Product Documentation]: https://cloud.google.com/firestore
|
@@ -12,6 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
|
15
16
|
##
|
16
17
|
# This file is here to be autorequired by bundler, so that the .firestore and
|
17
18
|
# #firestore methods can be available, but the library and all dependencies
|
@@ -29,8 +30,8 @@ module Google
|
|
29
30
|
# Creates a new object for connecting to the Firestore service.
|
30
31
|
# Each call creates a new connection.
|
31
32
|
#
|
32
|
-
# For more information on connecting to Google Cloud see the
|
33
|
-
# Guide
|
33
|
+
# For more information on connecting to Google Cloud see the
|
34
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
34
35
|
#
|
35
36
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
36
37
|
# set of resources and operations that the connection can access. See
|
@@ -69,8 +70,8 @@ module Google
|
|
69
70
|
# Creates a new object for connecting to the Firestore service.
|
70
71
|
# Each call creates a new connection.
|
71
72
|
#
|
72
|
-
# For more information on connecting to Google Cloud see the
|
73
|
-
# Guide
|
73
|
+
# For more information on connecting to Google Cloud see the
|
74
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
74
75
|
#
|
75
76
|
# @param [String] project_id Identifier for a Firestore project. If not
|
76
77
|
# present, the default project for the credentials is used.
|
@@ -29,509 +29,7 @@ module Google
|
|
29
29
|
# databases, as a NoSQL database it differs from them in the way it
|
30
30
|
# describes relationships between data objects.
|
31
31
|
#
|
32
|
-
#
|
33
|
-
# Firestore Documentation](https://cloud.google.com/firestore/docs/).
|
34
|
-
#
|
35
|
-
# The goal of google-cloud is to provide an API that is comfortable to
|
36
|
-
# Rubyists. Authentication is handled by {Google::Cloud#firestore}. You can
|
37
|
-
# provide the project and credential information to connect to the Cloud
|
38
|
-
# Firestore service, or if you are running on Google Compute Engine this
|
39
|
-
# configuration is taken care of for you. You can read more about the
|
40
|
-
# options for connecting in the [Authentication
|
41
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
42
|
-
#
|
43
|
-
# ## Enabling Logging
|
44
|
-
#
|
45
|
-
# To enable logging for this library, set the logger for the underlying
|
46
|
-
# [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The
|
47
|
-
# logger that you set may be a Ruby stdlib
|
48
|
-
# [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html)
|
49
|
-
# as shown below, or a
|
50
|
-
# [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
|
51
|
-
# that will write logs to [Stackdriver
|
52
|
-
# Logging](https://cloud.google.com/logging/). See
|
53
|
-
# [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
|
54
|
-
# and the gRPC
|
55
|
-
# [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
|
56
|
-
# for additional information.
|
57
|
-
#
|
58
|
-
# Configuring a Ruby stdlib logger:
|
59
|
-
#
|
60
|
-
# ```ruby
|
61
|
-
# require "logger"
|
62
|
-
#
|
63
|
-
# module MyLogger
|
64
|
-
# LOGGER = Logger.new $stderr, level: Logger::WARN
|
65
|
-
# def logger
|
66
|
-
# LOGGER
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
71
|
-
# module GRPC
|
72
|
-
# extend MyLogger
|
73
|
-
# end
|
74
|
-
# ```
|
75
|
-
#
|
76
|
-
# ## Adding data
|
77
|
-
#
|
78
|
-
# Cloud Firestore stores data in Documents, which are stored in Collections.
|
79
|
-
# Cloud Firestore creates collections and documents implicitly the first
|
80
|
-
# time you add data to the document. (For more information, see [Adding Data
|
81
|
-
# to Cloud Firestore](https://cloud.google.com/firestore/docs/manage-data/add-data).
|
82
|
-
#
|
83
|
-
# To create or overwrite a single document, use {Firestore::Client#doc} to
|
84
|
-
# obtain a document reference. (This does not create a document in Cloud
|
85
|
-
# Firestore.) Then, call {Firestore::DocumentReference#set} to create the
|
86
|
-
# document or overwrite an existing document:
|
87
|
-
#
|
88
|
-
# ```ruby
|
89
|
-
# require "google/cloud/firestore"
|
90
|
-
#
|
91
|
-
# firestore = Google::Cloud::Firestore.new
|
92
|
-
#
|
93
|
-
# # Get a document reference
|
94
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
95
|
-
#
|
96
|
-
# nyc_ref.set({ name: "New York City" }) # Document created
|
97
|
-
# ```
|
98
|
-
#
|
99
|
-
# When you use this combination of `doc` and `set` to create a new document,
|
100
|
-
# you must specify an ID for the document. (In the example above, the ID is
|
101
|
-
# "NYC".) However, if you do not have a meaningful ID for the document, you
|
102
|
-
# may omit the ID from a call to {Firestore::CollectionReference#doc}, and
|
103
|
-
# Cloud Firestore will auto-generate an ID for you.
|
104
|
-
#
|
105
|
-
# ```ruby
|
106
|
-
# require "google/cloud/firestore"
|
107
|
-
#
|
108
|
-
# firestore = Google::Cloud::Firestore.new
|
109
|
-
#
|
110
|
-
# # Get a collection reference
|
111
|
-
# cities_col = firestore.col "cities"
|
112
|
-
#
|
113
|
-
# # Get a document reference with data
|
114
|
-
# random_ref = cities_col.doc
|
115
|
-
# random_ref.set({ name: "New York City" })
|
116
|
-
#
|
117
|
-
# # The document ID is randomly generated
|
118
|
-
# random_ref.document_id #=> "RANDOMID123XYZ"
|
119
|
-
# ```
|
120
|
-
#
|
121
|
-
# You can perform both of the operations shown above, auto-generating
|
122
|
-
# an ID and creating the document, in a single call to
|
123
|
-
# {Firestore::CollectionReference#add}.
|
124
|
-
#
|
125
|
-
# ```ruby
|
126
|
-
# require "google/cloud/firestore"
|
127
|
-
#
|
128
|
-
# firestore = Google::Cloud::Firestore.new
|
129
|
-
#
|
130
|
-
# # Get a collection reference
|
131
|
-
# cities_col = firestore.col "cities"
|
132
|
-
#
|
133
|
-
# # Get a document reference with data
|
134
|
-
# random_ref = cities_col.add({ name: "New York City" })
|
135
|
-
#
|
136
|
-
# # The document ID is randomly generated
|
137
|
-
# random_ref.document_id #=> "RANDOMID123XYZ"
|
138
|
-
# ```
|
139
|
-
#
|
140
|
-
# You can also use `add` to create an empty document:
|
141
|
-
#
|
142
|
-
# ```ruby
|
143
|
-
# require "google/cloud/firestore"
|
144
|
-
#
|
145
|
-
# firestore = Google::Cloud::Firestore.new
|
146
|
-
#
|
147
|
-
# # Get a collection reference
|
148
|
-
# cities_col = firestore.col "cities"
|
149
|
-
#
|
150
|
-
# # Create a document without data
|
151
|
-
# random_ref = cities_col.add
|
152
|
-
#
|
153
|
-
# # The document ID is randomly generated
|
154
|
-
# random_ref.document_id #=> "RANDOMID123XYZ"
|
155
|
-
# ```
|
156
|
-
#
|
157
|
-
# ## Retrieving collection references
|
158
|
-
#
|
159
|
-
# Collections are simply named containers for documents. A collection
|
160
|
-
# contains documents and nothing else. It can't directly contain raw fields
|
161
|
-
# with values, and it can't contain other collections. You do not need to
|
162
|
-
# "create" or "delete" collections. After you create the first document in a
|
163
|
-
# collection, the collection exists. If you delete all of the documents in a
|
164
|
-
# collection, it no longer exists. (For more information, see [Cloud
|
165
|
-
# Firestore Data Model](https://cloud.google.com/firestore/docs/data-model).
|
166
|
-
#
|
167
|
-
# Use {Firestore::Client#cols} to list the root-level collections:
|
168
|
-
#
|
169
|
-
# ```ruby
|
170
|
-
# require "google/cloud/firestore"
|
171
|
-
#
|
172
|
-
# firestore = Google::Cloud::Firestore.new
|
173
|
-
#
|
174
|
-
# # Get the root collections
|
175
|
-
# firestore.cols.each do |col|
|
176
|
-
# puts col.collection_id
|
177
|
-
# end
|
178
|
-
# ```
|
179
|
-
#
|
180
|
-
# Retrieving a reference to a single root-level collection is similar:
|
181
|
-
#
|
182
|
-
# ```ruby
|
183
|
-
# require "google/cloud/firestore"
|
184
|
-
#
|
185
|
-
# firestore = Google::Cloud::Firestore.new
|
186
|
-
#
|
187
|
-
# # Get the cities collection
|
188
|
-
# cities_col = firestore.col "cities"
|
189
|
-
# ```
|
190
|
-
#
|
191
|
-
# To list the collections in a document, first get the document reference,
|
192
|
-
# then use {Firestore::DocumentReference#cols}:
|
193
|
-
#
|
194
|
-
# ```ruby
|
195
|
-
# require "google/cloud/firestore"
|
196
|
-
#
|
197
|
-
# firestore = Google::Cloud::Firestore.new
|
198
|
-
#
|
199
|
-
# # Get a document reference
|
200
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
201
|
-
#
|
202
|
-
# nyc_ref.cols.each do |col|
|
203
|
-
# puts col.collection_id
|
204
|
-
# end
|
205
|
-
# ```
|
206
|
-
#
|
207
|
-
# Again, retrieving a reference to a single collection is similar::
|
208
|
-
#
|
209
|
-
# ```ruby
|
210
|
-
# require "google/cloud/firestore"
|
211
|
-
#
|
212
|
-
# firestore = Google::Cloud::Firestore.new
|
213
|
-
#
|
214
|
-
# # Get a document reference
|
215
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
216
|
-
#
|
217
|
-
# # Get precincts sub-collection
|
218
|
-
# precincts_col = nyc_ref.col "precincts"
|
219
|
-
# ```
|
220
|
-
#
|
221
|
-
# ## Reading data
|
222
|
-
#
|
223
|
-
# You can retrieve a snapshot of the data in a single document with
|
224
|
-
# {Firestore::DocumentReference#get}, which returns an instance of
|
225
|
-
# {Firestore::DocumentSnapshot}:
|
226
|
-
#
|
227
|
-
# ```ruby
|
228
|
-
# require "google/cloud/firestore"
|
229
|
-
#
|
230
|
-
# firestore = Google::Cloud::Firestore.new
|
231
|
-
#
|
232
|
-
# # Get a document reference
|
233
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
234
|
-
#
|
235
|
-
# nyc_snap = nyc_ref.get
|
236
|
-
# nyc_snap[:population] #=> 1000000
|
237
|
-
# ```
|
238
|
-
# In the example above, {Firestore::DocumentSnapshot#[]} is used to access a
|
239
|
-
# top-level field. To access nested fields, use {Firestore::FieldPath}:
|
240
|
-
#
|
241
|
-
# ```ruby
|
242
|
-
# require "google/cloud/firestore"
|
243
|
-
#
|
244
|
-
# firestore = Google::Cloud::Firestore.new
|
245
|
-
#
|
246
|
-
# user_snap = firestore.doc("users/frank").get
|
247
|
-
#
|
248
|
-
# nested_field_path = firestore.field_path :favorites, :food
|
249
|
-
# user_snap.get(nested_field_path) #=> "Pizza"
|
250
|
-
# ```
|
251
|
-
#
|
252
|
-
# Or, use {Firestore::Client#get_all} to retrieve a list of document
|
253
|
-
# snapshots (data):
|
254
|
-
#
|
255
|
-
# ```ruby
|
256
|
-
# require "google/cloud/firestore"
|
257
|
-
#
|
258
|
-
# firestore = Google::Cloud::Firestore.new
|
259
|
-
#
|
260
|
-
# # Get and print city documents
|
261
|
-
# cities = ["cities/NYC", "cities/SF", "cities/LA"]
|
262
|
-
# firestore.get_all(cities).each do |city|
|
263
|
-
# puts "#{city.document_id} has #{city[:population]} residents."
|
264
|
-
# end
|
265
|
-
# ```
|
266
|
-
#
|
267
|
-
# To retrieve all of the document snapshots in a collection, use
|
268
|
-
# {Firestore::CollectionReference#get}:
|
269
|
-
#
|
270
|
-
# ```ruby
|
271
|
-
# require "google/cloud/firestore"
|
272
|
-
#
|
273
|
-
# firestore = Google::Cloud::Firestore.new
|
274
|
-
#
|
275
|
-
# # Get a collection reference
|
276
|
-
# cities_col = firestore.col "cities"
|
277
|
-
#
|
278
|
-
# # Get and print all city documents
|
279
|
-
# cities_col.get do |city|
|
280
|
-
# puts "#{city.document_id} has #{city[:population]} residents."
|
281
|
-
# end
|
282
|
-
# ```
|
283
|
-
#
|
284
|
-
# The example above is actually a simple query without filters. Let's look
|
285
|
-
# at some other queries for Cloud Firestore.
|
286
|
-
#
|
287
|
-
# ## Querying data
|
288
|
-
#
|
289
|
-
# Use {Firestore::Query#where} to filter queries on a field:
|
290
|
-
#
|
291
|
-
# ```ruby
|
292
|
-
# require "google/cloud/firestore"
|
293
|
-
#
|
294
|
-
# firestore = Google::Cloud::Firestore.new
|
295
|
-
#
|
296
|
-
# # Get a collection reference
|
297
|
-
# cities_col = firestore.col "cities"
|
298
|
-
#
|
299
|
-
# # Create a query
|
300
|
-
# query = cities_col.where(:population, :>=, 1000000)
|
301
|
-
#
|
302
|
-
# query.get do |city|
|
303
|
-
# puts "#{city.document_id} has #{city[:population]} residents."
|
304
|
-
# end
|
305
|
-
# ```
|
306
|
-
#
|
307
|
-
# You can order the query results with {Firestore::Query#order}:
|
308
|
-
#
|
309
|
-
# ```ruby
|
310
|
-
# require "google/cloud/firestore"
|
311
|
-
#
|
312
|
-
# firestore = Google::Cloud::Firestore.new
|
313
|
-
#
|
314
|
-
# # Get a collection reference
|
315
|
-
# cities_col = firestore.col "cities"
|
316
|
-
#
|
317
|
-
# # Create a query
|
318
|
-
# query = cities_col.order(:name, :desc)
|
319
|
-
#
|
320
|
-
# query.get do |city|
|
321
|
-
# puts "#{city.document_id} has #{city[:population]} residents."
|
322
|
-
# end
|
323
|
-
# ```
|
324
|
-
#
|
325
|
-
# Query methods may be chained, as in this example using
|
326
|
-
# {Firestore::Query#limit} and {Firestore::Query#offset} to perform
|
327
|
-
# pagination:
|
328
|
-
#
|
329
|
-
# ```ruby
|
330
|
-
# require "google/cloud/firestore"
|
331
|
-
#
|
332
|
-
# firestore = Google::Cloud::Firestore.new
|
333
|
-
#
|
334
|
-
# # Get a collection reference
|
335
|
-
# cities_col = firestore.col "cities"
|
336
|
-
#
|
337
|
-
# # Create a query
|
338
|
-
# query = cities_col.limit(5).offset(10)
|
339
|
-
#
|
340
|
-
# query.get do |city|
|
341
|
-
# puts "#{city.document_id} has #{city[:population]} residents."
|
342
|
-
# end
|
343
|
-
# ```
|
344
|
-
#
|
345
|
-
# See [Managing Indexes in Cloud
|
346
|
-
# Firestore](https://cloud.google.com/firestore/docs/query-data/indexing) to
|
347
|
-
# ensure the best performance for your queries.
|
348
|
-
#
|
349
|
-
# ## Updating data
|
350
|
-
#
|
351
|
-
# You can use {Firestore::DocumentReference#set} to completely overwrite an
|
352
|
-
# existing document:
|
353
|
-
#
|
354
|
-
# ```ruby
|
355
|
-
# require "google/cloud/firestore"
|
356
|
-
#
|
357
|
-
# firestore = Google::Cloud::Firestore.new
|
358
|
-
#
|
359
|
-
# # Get a document reference
|
360
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
361
|
-
#
|
362
|
-
# nyc_ref.set({ name: "New York City" })
|
363
|
-
# ```
|
364
|
-
#
|
365
|
-
# Or, to selectively update only the fields appearing in your `data`
|
366
|
-
# argument, set the `merge` option to `true`:
|
367
|
-
#
|
368
|
-
# ```ruby
|
369
|
-
# require "google/cloud/firestore"
|
370
|
-
#
|
371
|
-
# firestore = Google::Cloud::Firestore.new
|
372
|
-
#
|
373
|
-
# # Get a document reference
|
374
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
375
|
-
#
|
376
|
-
# nyc_ref.set({ name: "New York City" }, merge: true)
|
377
|
-
# ```
|
378
|
-
#
|
379
|
-
# Use {Firestore::DocumentReference#update} to directly update a
|
380
|
-
# deeply-nested field with a {Firestore::FieldPath}:
|
381
|
-
#
|
382
|
-
# ```ruby
|
383
|
-
# require "google/cloud/firestore"
|
384
|
-
#
|
385
|
-
# firestore = Google::Cloud::Firestore.new
|
386
|
-
#
|
387
|
-
# user_ref = firestore.doc "users/frank"
|
388
|
-
#
|
389
|
-
# nested_field_path = firestore.field_path :favorites, :food
|
390
|
-
# user_ref.update({ nested_field_path => "Pasta" })
|
391
|
-
# ```
|
392
|
-
#
|
393
|
-
# ### Listening for changes
|
394
|
-
#
|
395
|
-
# You can listen to a document reference or a collection reference/query for
|
396
|
-
# changes. The current document snapshot or query results snapshot will be
|
397
|
-
# yielded first, and each time the contents change.
|
398
|
-
#
|
399
|
-
# You can use {Firestore::DocumentReference#listen} to be notified of
|
400
|
-
# changes to a single document:
|
401
|
-
#
|
402
|
-
# ```ruby
|
403
|
-
# require "google/cloud/firestore"
|
404
|
-
#
|
405
|
-
# firestore = Google::Cloud::Firestore.new
|
406
|
-
#
|
407
|
-
# # Get a document reference
|
408
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
409
|
-
#
|
410
|
-
# listener = nyc_ref.listen do |snapshot|
|
411
|
-
# puts "The population of #{snapshot[:name]} "
|
412
|
-
# puts "is #{snapshot[:population]}."
|
413
|
-
# end
|
414
|
-
#
|
415
|
-
# # When ready, stop the listen operation and close the stream.
|
416
|
-
# listener.stop
|
417
|
-
# ```
|
418
|
-
#
|
419
|
-
# You can use {Firestore::Query#listen} to be notified of changes to any
|
420
|
-
# document contained in the query:
|
421
|
-
#
|
422
|
-
# ```ruby
|
423
|
-
# require "google/cloud/firestore"
|
424
|
-
#
|
425
|
-
# firestore = Google::Cloud::Firestore.new
|
426
|
-
#
|
427
|
-
# # Create a query
|
428
|
-
# query = firestore.col(:cities).order(:population, :desc)
|
429
|
-
#
|
430
|
-
# listener = query.listen do |snapshot|
|
431
|
-
# puts "The query snapshot has #{snapshot.docs.count} documents "
|
432
|
-
# puts "and has #{snapshot.changes.count} changes."
|
433
|
-
# end
|
434
|
-
#
|
435
|
-
# # When ready, stop the listen operation and close the stream.
|
436
|
-
# listener.stop
|
437
|
-
# ```
|
438
|
-
#
|
439
|
-
# ## Using transactions and batched writes
|
440
|
-
#
|
441
|
-
# Cloud Firestore supports atomic operations for reading and writing data.
|
442
|
-
# In a set of atomic operations, either all of the operations succeed, or
|
443
|
-
# none of them are applied. There are two types of atomic operations in
|
444
|
-
# Cloud Firestore: A transaction is a set of read and write operations on
|
445
|
-
# one or more documents, while a batched write is a set of only write
|
446
|
-
# operations on one or more documents. (For more information, see
|
447
|
-
# [Transactions and Batched Writes](https://cloud.google.com/firestore/docs/manage-data/transactions).
|
448
|
-
#
|
449
|
-
# ### Transactions
|
450
|
-
#
|
451
|
-
# A transaction consists of any number of read operations followed by any
|
452
|
-
# number of write operations. (Read operations must always come before write
|
453
|
-
# operations.) In the case of a concurrent update by another client, Cloud
|
454
|
-
# Firestore runs the entire transaction again. Therefore, transaction blocks
|
455
|
-
# should be idempotent and should not not directly modify application state.
|
456
|
-
#
|
457
|
-
# ```ruby
|
458
|
-
# require "google/cloud/firestore"
|
459
|
-
#
|
460
|
-
# firestore = Google::Cloud::Firestore.new
|
461
|
-
#
|
462
|
-
# city = firestore.col("cities").doc("SF")
|
463
|
-
# city.set({ name: "San Francisco",
|
464
|
-
# state: "CA",
|
465
|
-
# country: "USA",
|
466
|
-
# capital: false,
|
467
|
-
# population: 860000 })
|
468
|
-
#
|
469
|
-
# firestore.transaction do |tx|
|
470
|
-
# new_population = tx.get(city).data[:population] + 1
|
471
|
-
# tx.update(city, { population: new_population })
|
472
|
-
# end
|
473
|
-
# ```
|
474
|
-
#
|
475
|
-
# ### Batched writes
|
476
|
-
#
|
477
|
-
# If you do not need to read any documents in your operation set, you can
|
478
|
-
# execute multiple write operations as a single batch. A batch of writes
|
479
|
-
# completes atomically and can write to multiple documents. Batched writes
|
480
|
-
# are also useful for migrating large data sets to Cloud Firestore.
|
481
|
-
#
|
482
|
-
# ```ruby
|
483
|
-
# require "google/cloud/firestore"
|
484
|
-
#
|
485
|
-
# firestore = Google::Cloud::Firestore.new
|
486
|
-
#
|
487
|
-
# firestore.batch do |b|
|
488
|
-
# # Set the data for NYC
|
489
|
-
# b.set("cities/NYC", { name: "New York City" })
|
490
|
-
#
|
491
|
-
# # Update the population for SF
|
492
|
-
# b.update("cities/SF", { population: 1000000 })
|
493
|
-
#
|
494
|
-
# # Delete LA
|
495
|
-
# b.delete("cities/LA")
|
496
|
-
# end
|
497
|
-
# ```
|
498
|
-
#
|
499
|
-
# ## Deleting data
|
500
|
-
#
|
501
|
-
# Use {Firestore::DocumentReference#delete} to delete a document from Cloud
|
502
|
-
# Firestore:
|
503
|
-
#
|
504
|
-
# ```ruby
|
505
|
-
# require "google/cloud/firestore"
|
506
|
-
#
|
507
|
-
# firestore = Google::Cloud::Firestore.new
|
508
|
-
#
|
509
|
-
# # Get a document reference
|
510
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
511
|
-
#
|
512
|
-
# nyc_ref.delete
|
513
|
-
# ```
|
514
|
-
#
|
515
|
-
# To delete specific fields from a document, use the
|
516
|
-
# {Firestore::Client.field_delete} method when you update a document:
|
517
|
-
#
|
518
|
-
# ```ruby
|
519
|
-
# require "google/cloud/firestore"
|
520
|
-
#
|
521
|
-
# firestore = Google::Cloud::Firestore.new
|
522
|
-
#
|
523
|
-
# # Get a document reference
|
524
|
-
# nyc_ref = firestore.doc "cities/NYC"
|
525
|
-
#
|
526
|
-
# nyc_ref.update({ name: "New York City",
|
527
|
-
# trash: firestore.field_delete })
|
528
|
-
# ```
|
529
|
-
#
|
530
|
-
# To delete an entire collection or sub-collection in Cloud Firestore,
|
531
|
-
# retrieve all the documents within the collection or sub-collection and
|
532
|
-
# delete them. If you have larger collections, you may want to delete the
|
533
|
-
# documents in smaller batches to avoid out-of-memory errors. Repeat the
|
534
|
-
# process until you've deleted the entire collection or sub-collection.
|
32
|
+
# See {file:OVERVIEW.md Firestore Overview}.
|
535
33
|
#
|
536
34
|
module Firestore
|
537
35
|
##
|
@@ -539,8 +37,7 @@ module Google
|
|
539
37
|
# Each call creates a new connection.
|
540
38
|
#
|
541
39
|
# For more information on connecting to Google Cloud see the
|
542
|
-
#
|
543
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
40
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
544
41
|
#
|
545
42
|
# @param [String] project_id Identifier for a Firestore project. If not
|
546
43
|
# present, the default project for the credentials is used.
|