google-cloud-firestore 0.24.2 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +26 -0
- data/EMULATOR.md +49 -0
- data/lib/google-cloud-firestore.rb +6 -1
- data/lib/google/cloud/firestore.rb +36 -8
- data/lib/google/cloud/firestore/batch.rb +1 -1
- data/lib/google/cloud/firestore/client.rb +152 -4
- data/lib/google/cloud/firestore/collection_reference.rb +1 -1
- data/lib/google/cloud/firestore/commit_response.rb +1 -1
- data/lib/google/cloud/firestore/convert.rb +53 -38
- data/lib/google/cloud/firestore/credentials.rb +2 -2
- data/lib/google/cloud/firestore/document_reference.rb +2 -1
- data/lib/google/cloud/firestore/document_snapshot.rb +5 -5
- data/lib/google/cloud/firestore/field_path.rb +2 -2
- data/lib/google/cloud/firestore/field_value.rb +139 -9
- data/lib/google/cloud/firestore/query.rb +21 -15
- data/lib/google/cloud/firestore/query_snapshot.rb +1 -1
- data/lib/google/cloud/firestore/service.rb +31 -13
- data/lib/google/cloud/firestore/transaction.rb +39 -5
- data/lib/google/cloud/firestore/v1.rb +152 -0
- data/lib/google/cloud/firestore/v1/credentials.rb +42 -0
- data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/common.rb +64 -0
- data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/document.rb +136 -0
- data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/firestore.rb +574 -0
- data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/query.rb +219 -0
- data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/write.rb +237 -0
- data/lib/google/cloud/firestore/v1/doc/google/protobuf/any.rb +130 -0
- data/lib/google/cloud/firestore/v1/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/firestore/v1/doc/google/protobuf/timestamp.rb +109 -0
- data/lib/google/cloud/firestore/v1/doc/google/protobuf/wrappers.rb +26 -0
- data/lib/google/cloud/firestore/v1/doc/google/rpc/status.rb +84 -0
- data/lib/google/cloud/firestore/v1/firestore_client.rb +1044 -0
- data/lib/google/cloud/firestore/v1/firestore_client_config.json +100 -0
- data/lib/google/cloud/firestore/v1beta1.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/credentials.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +41 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +1 -65
- data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +1 -1
- data/lib/google/cloud/firestore/v1beta1/firestore_client_config.json +1 -1
- data/lib/google/cloud/firestore/version.rb +1 -1
- data/lib/google/cloud/firestore/watch/enumerator_queue.rb +0 -2
- data/lib/google/cloud/firestore/watch/inventory.rb +2 -2
- data/lib/google/cloud/firestore/watch/listener.rb +16 -17
- data/lib/google/cloud/firestore/watch/order.rb +1 -1
- data/lib/google/firestore/v1/common_pb.rb +45 -0
- data/lib/google/firestore/v1/document_pb.rb +50 -0
- data/lib/google/firestore/v1/firestore_pb.rb +220 -0
- data/lib/google/firestore/v1/firestore_services_pb.rb +87 -0
- data/lib/google/firestore/v1/query_pb.rb +105 -0
- data/lib/google/firestore/v1/write_pb.rb +79 -0
- data/lib/google/firestore/v1beta1/firestore_services_pb.rb +2 -1
- data/lib/google/firestore/v1beta1/write_pb.rb +3 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20e48c6792126fe8c5a79b40397c538b31ebc323b14047ffea02469105548a05
|
4
|
+
data.tar.gz: fdc7adba72dfb45c176538777c3c7fcd75d0fe17938b2732589e2f7cae52ff73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b878632115005af9f47874d6ac9655e12a20017786f234c8cf77949a54c3b3a8f67e86d73819e42fc7c0dc62102d5fdee54d3406932e724b4cee6efc99726e1
|
7
|
+
data.tar.gz: feb031af0e58139b0e039e8230c1921f72a91e0cdfe5b31d8d3c39823fa1a30e12f1569f26d29a0623ebf0c6790eb5b49bf164c5405c36b447a0d561d0cbdf34
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.25.0 / 2019-02-01
|
4
|
+
|
5
|
+
* Switch Firestore to use the V1 API:
|
6
|
+
* Add V1 service to the low level API.
|
7
|
+
* Add numeric transform methods
|
8
|
+
* Add the following methods to Client:
|
9
|
+
* Client#field_increment
|
10
|
+
* Client#field_maximum
|
11
|
+
* Client#field_minimum
|
12
|
+
* Add the following methods to FieldValue:
|
13
|
+
* FieldValue.increment
|
14
|
+
* FieldValue.maximum
|
15
|
+
* FieldValue.minimum
|
16
|
+
* Add field_mask argument to get_all method:
|
17
|
+
* Allows specific portions of the document data to be returned.
|
18
|
+
* Add list_collections alias.
|
19
|
+
* Make use of Credentials#project_id
|
20
|
+
* Use Credentials#project_id
|
21
|
+
If a project_id is not provided, use the value on the Credentials object.
|
22
|
+
This value was added in googleauth 0.7.0.
|
23
|
+
* Loosen googleauth dependency
|
24
|
+
Allow for new releases up to 0.10.
|
25
|
+
The googleauth devs have committed to maintanining the current API
|
26
|
+
and will not make backwards compatible changes before 0.10.
|
27
|
+
* Add Firestore emulator support.
|
28
|
+
|
3
29
|
### 0.24.2 / 2018-09-20
|
4
30
|
|
5
31
|
* Add fix for comparing NaN values
|
data/EMULATOR.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Google Cloud Firestore Emulator
|
2
|
+
|
3
|
+
To develop and test your application locally, you can use the [Google Cloud
|
4
|
+
Firestore
|
5
|
+
Emulator](https://cloud.google.com/firestore/docs/security/test-rules-emulator#install_the_emulator),
|
6
|
+
which provides local emulation of the production Google Cloud Firestore
|
7
|
+
environment. You can start the Google Cloud Firestore emulator using the
|
8
|
+
[`firebase` command-line tool](https://firebase.google.com/docs/cli/).
|
9
|
+
|
10
|
+
When you run the Cloud Firestore emulator you will see a message similar to the
|
11
|
+
following printed:
|
12
|
+
|
13
|
+
```
|
14
|
+
$ firebase serve --only firestore
|
15
|
+
API endpoint: http://[::1]:8080
|
16
|
+
API endpoint: http://127.0.0.1:8080
|
17
|
+
Dev App Server is now running.
|
18
|
+
```
|
19
|
+
|
20
|
+
Now you can connect to the emulator using the `FIRESTORE_EMULATOR_HOST`
|
21
|
+
environment variable:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "google/cloud/firestore"
|
25
|
+
|
26
|
+
# Make Firestore use the emulator
|
27
|
+
ENV["FIRESTORE_EMULATOR_HOST"] = "127.0.0.1:8080"
|
28
|
+
|
29
|
+
firestore = Google::Cloud::Firestore.new project_id: "emulator-project-id"
|
30
|
+
|
31
|
+
# Get a document reference
|
32
|
+
nyc_ref = firestore.doc "cities/NYC"
|
33
|
+
|
34
|
+
nyc_ref.set({ name: "New York City" }) # Document created
|
35
|
+
```
|
36
|
+
|
37
|
+
Or by providing the `emulator_host` argument:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require "google/cloud/firestore"
|
41
|
+
|
42
|
+
firestore = Google::Cloud::Firestore.new project_id: "emulator-project-id",
|
43
|
+
emulator_host: "127.0.0.1:8080"
|
44
|
+
|
45
|
+
# Get a document reference
|
46
|
+
nyc_ref = firestore.doc "cities/NYC"
|
47
|
+
|
48
|
+
nyc_ref.set({ name: "New York City" }) # Document created
|
49
|
+
```
|
@@ -119,14 +119,19 @@ Google::Cloud.configure.add_config! :firestore do |config|
|
|
119
119
|
"FIRESTORE_KEYFILE", "FIRESTORE_KEYFILE_JSON"
|
120
120
|
)
|
121
121
|
end
|
122
|
+
default_emulator = Google::Cloud::Config.deferred do
|
123
|
+
ENV["FIRESTORE_EMULATOR_HOST"]
|
124
|
+
end
|
122
125
|
|
123
126
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
124
127
|
config.add_alias! :project, :project_id
|
125
128
|
config.add_field! :credentials, default_creds,
|
126
|
-
match:
|
129
|
+
match: [String, Hash, Google::Auth::Credentials],
|
127
130
|
allow_nil: true
|
128
131
|
config.add_alias! :keyfile, :credentials
|
129
132
|
config.add_field! :scope, nil, match: [String, Array]
|
130
133
|
config.add_field! :timeout, nil, match: Integer
|
131
134
|
config.add_field! :client_config, nil, match: Hash
|
135
|
+
config.add_field! :emulator_host, default_emulator,
|
136
|
+
match: String, allow_nil: true
|
132
137
|
end
|
@@ -32,6 +32,9 @@ module Google
|
|
32
32
|
# See {file:OVERVIEW.md Firestore Overview}.
|
33
33
|
#
|
34
34
|
module Firestore
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
36
|
+
# rubocop:disable Metrics/MethodLength
|
37
|
+
|
35
38
|
##
|
36
39
|
# Creates a new object for connecting to the Firestore service.
|
37
40
|
# Each call creates a new connection.
|
@@ -55,6 +58,8 @@ module Google
|
|
55
58
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
56
59
|
# @param [Hash] client_config A hash of values to override the default
|
57
60
|
# behavior of the API client. Optional.
|
61
|
+
# @param [String] emulator_host Firestore emulator host. Optional.
|
62
|
+
# If the param is nil, uses the value of the `emulator_host` config.
|
58
63
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
59
64
|
# @param [String] keyfile Alias for the `credentials` argument.
|
60
65
|
# Deprecated.
|
@@ -67,28 +72,49 @@ module Google
|
|
67
72
|
# firestore = Google::Cloud::Firestore.new
|
68
73
|
#
|
69
74
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
70
|
-
client_config: nil,
|
71
|
-
|
72
|
-
project_id
|
73
|
-
|
74
|
-
|
75
|
-
scope ||= configure.scope
|
76
|
-
timeout ||= configure.timeout
|
75
|
+
client_config: nil, emulator_host: nil, project: nil,
|
76
|
+
keyfile: nil
|
77
|
+
project_id ||= (project || default_project_id)
|
78
|
+
scope ||= configure.scope
|
79
|
+
timeout ||= configure.timeout
|
77
80
|
client_config ||= configure.client_config
|
81
|
+
emulator_host ||= configure.emulator_host
|
82
|
+
|
83
|
+
if emulator_host
|
84
|
+
project_id = project_id.to_s
|
85
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
86
|
+
|
87
|
+
return Firestore::Client.new(
|
88
|
+
Firestore::Service.new(
|
89
|
+
project_id, :this_channel_is_insecure,
|
90
|
+
host: emulator_host, timeout: timeout,
|
91
|
+
client_config: client_config
|
92
|
+
)
|
93
|
+
)
|
94
|
+
end
|
78
95
|
|
79
96
|
credentials ||= (keyfile || default_credentials(scope: scope))
|
80
97
|
unless credentials.is_a? Google::Auth::Credentials
|
81
98
|
credentials = Firestore::Credentials.new credentials, scope: scope
|
82
99
|
end
|
83
100
|
|
101
|
+
if credentials.respond_to? :project_id
|
102
|
+
project_id ||= credentials.project_id
|
103
|
+
end
|
104
|
+
project_id = project_id.to_s
|
105
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
106
|
+
|
84
107
|
Firestore::Client.new(
|
85
108
|
Firestore::Service.new(
|
86
|
-
project_id, credentials, timeout:
|
109
|
+
project_id, credentials, timeout: timeout,
|
87
110
|
client_config: client_config
|
88
111
|
)
|
89
112
|
)
|
90
113
|
end
|
91
114
|
|
115
|
+
# rubocop:enable Metrics/AbcSize
|
116
|
+
# rubocop:enable Metrics/MethodLength
|
117
|
+
|
92
118
|
##
|
93
119
|
# Configure the Google Cloud Firestore library.
|
94
120
|
#
|
@@ -105,6 +131,8 @@ module Google
|
|
105
131
|
# * `timeout` - (Integer) Default timeout to use in requests.
|
106
132
|
# * `client_config` - (Hash) A hash of values to override the default
|
107
133
|
# behavior of the API client.
|
134
|
+
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
135
|
+
# `ENV["FIRESTORE_EMULATOR_HOST"]`
|
108
136
|
#
|
109
137
|
# @return [Google::Cloud::Config] The configuration object the
|
110
138
|
# Google::Cloud::Firestore library uses.
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/firestore/
|
16
|
+
require "google/cloud/firestore/v1"
|
17
17
|
require "google/cloud/firestore/collection_reference"
|
18
18
|
require "google/cloud/firestore/document_reference"
|
19
19
|
require "google/cloud/firestore/document_snapshot"
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/firestore/
|
16
|
+
require "google/cloud/firestore/v1"
|
17
17
|
require "google/cloud/firestore/service"
|
18
18
|
require "google/cloud/firestore/field_path"
|
19
19
|
require "google/cloud/firestore/field_value"
|
@@ -108,6 +108,7 @@ module Google
|
|
108
108
|
collection_ids.each { |collection_id| yield col(collection_id) }
|
109
109
|
end
|
110
110
|
alias collections cols
|
111
|
+
alias list_collections cols
|
111
112
|
|
112
113
|
##
|
113
114
|
# Retrieves a collection.
|
@@ -173,6 +174,17 @@ module Google
|
|
173
174
|
# @param [String, DocumentReference, Array<String|DocumentReference>]
|
174
175
|
# docs One or more strings representing the path of the document, or
|
175
176
|
# document reference objects.
|
177
|
+
# @param [Array<String|FieldPath>] field_mask One or more field path
|
178
|
+
# values, representing the fields of the document to be returned. If a
|
179
|
+
# document has a field that is not present in this mask, that field
|
180
|
+
# will not be returned in the response. All fields are returned when
|
181
|
+
# the mask is not set.
|
182
|
+
#
|
183
|
+
# A field path can either be a {FieldPath} object, or a dotted string
|
184
|
+
# representing the nested fields. In other words the string represents
|
185
|
+
# individual fields joined by ".". Fields containing `~`, `*`, `/`,
|
186
|
+
# `[`, `]`, and `.` cannot be in a dotted string, and should provided
|
187
|
+
# using a {FieldPath} object instead. (See {#field_path}.)
|
176
188
|
#
|
177
189
|
# @yield [documents] The block for accessing the document snapshots.
|
178
190
|
# @yieldparam [DocumentSnapshot] document A document snapshot.
|
@@ -190,16 +202,37 @@ module Google
|
|
190
202
|
# puts "#{city.document_id} has #{city[:population]} residents."
|
191
203
|
# end
|
192
204
|
#
|
193
|
-
|
205
|
+
# @example Get docs using a field mask:
|
206
|
+
# require "google/cloud/firestore"
|
207
|
+
#
|
208
|
+
# firestore = Google::Cloud::Firestore.new
|
209
|
+
#
|
210
|
+
# # Get and print city documents
|
211
|
+
# cities = ["cities/NYC", "cities/SF", "cities/LA"]
|
212
|
+
# firestore.get_all(cities, field_mask: [:population]).each do |city|
|
213
|
+
# puts "#{city.document_id} has #{city[:population]} residents."
|
214
|
+
# end
|
215
|
+
#
|
216
|
+
def get_all *docs, field_mask: nil
|
194
217
|
ensure_service!
|
195
218
|
|
196
|
-
|
219
|
+
unless block_given?
|
220
|
+
return enum_for(:get_all, docs, field_mask: field_mask)
|
221
|
+
end
|
197
222
|
|
198
223
|
doc_paths = Array(docs).flatten.map do |doc_path|
|
199
224
|
coalesce_doc_path_argument doc_path
|
200
225
|
end
|
226
|
+
mask = Array(field_mask).map do |field_path|
|
227
|
+
if field_path.is_a? FieldPath
|
228
|
+
field_path.formatted_string
|
229
|
+
else
|
230
|
+
FieldPath.parse(field_path).formatted_string
|
231
|
+
end
|
232
|
+
end
|
233
|
+
mask = nil if mask.empty?
|
201
234
|
|
202
|
-
results = service.get_documents doc_paths
|
235
|
+
results = service.get_documents doc_paths, mask: mask
|
203
236
|
results.each do |result|
|
204
237
|
next if result.result.nil?
|
205
238
|
yield DocumentSnapshot.from_batch_result(result, self)
|
@@ -352,6 +385,121 @@ module Google
|
|
352
385
|
FieldValue.array_delete(*values)
|
353
386
|
end
|
354
387
|
|
388
|
+
##
|
389
|
+
# Creates a sentinel value to indicate the addition the given value to
|
390
|
+
# the field's current value.
|
391
|
+
#
|
392
|
+
# If the field's current value is not an integer or a double value
|
393
|
+
# (Numeric), or if the field does not yet exist, the transformation will
|
394
|
+
# set the field to the given value. If either of the given value or the
|
395
|
+
# current field value are doubles, both values will be interpreted as
|
396
|
+
# doubles. Double arithmetic and representation of double values follow
|
397
|
+
# IEEE 754 semantics. If there is positive/negative integer overflow,
|
398
|
+
# the field is resolved to the largest magnitude positive/negative
|
399
|
+
# integer.
|
400
|
+
#
|
401
|
+
# @param [Numeric] value The value to add to the given value. Required.
|
402
|
+
#
|
403
|
+
# @return [FieldValue] The increment field value object.
|
404
|
+
#
|
405
|
+
# @raise [ArgumentError] if the value is not a Numeric.
|
406
|
+
#
|
407
|
+
# @example
|
408
|
+
# require "google/cloud/firestore"
|
409
|
+
#
|
410
|
+
# firestore = Google::Cloud::Firestore.new
|
411
|
+
#
|
412
|
+
# # Get a document reference
|
413
|
+
# nyc_ref = firestore.doc "cities/NYC"
|
414
|
+
#
|
415
|
+
# # Set the population to increment by 1.
|
416
|
+
# increment_value = firestore.field_increment 1
|
417
|
+
#
|
418
|
+
# nyc_ref.update({ name: "New York City",
|
419
|
+
# population: increment_value })
|
420
|
+
#
|
421
|
+
def field_increment value
|
422
|
+
FieldValue.increment value
|
423
|
+
end
|
424
|
+
|
425
|
+
##
|
426
|
+
# Creates a sentinel value to indicate the setting the field to the
|
427
|
+
# maximum of its current value and the given value.
|
428
|
+
#
|
429
|
+
# If the field is not an integer or double (Numeric), or if the field
|
430
|
+
# does not yet exist, the transformation will set the field to the given
|
431
|
+
# value. If a maximum operation is applied where the field and the input
|
432
|
+
# value are of mixed types (that is - one is an integer and one is a
|
433
|
+
# double) the field takes on the type of the larger operand. If the
|
434
|
+
# operands are equivalent (e.g. 3 and 3.0), the field does not change.
|
435
|
+
# 0, 0.0, and -0.0 are all zero. The maximum of a zero stored value and
|
436
|
+
# zero input value is always the stored value. The maximum of any
|
437
|
+
# numeric value x and NaN is NaN.
|
438
|
+
#
|
439
|
+
# @param [Numeric] value The value to compare against the given value to
|
440
|
+
# calculate the maximum value to set. Required.
|
441
|
+
#
|
442
|
+
# @return [FieldValue] The maximum field value object.
|
443
|
+
#
|
444
|
+
# @raise [ArgumentError] if the value is not a Numeric.
|
445
|
+
#
|
446
|
+
# @example
|
447
|
+
# require "google/cloud/firestore"
|
448
|
+
#
|
449
|
+
# firestore = Google::Cloud::Firestore.new
|
450
|
+
#
|
451
|
+
# # Get a document reference
|
452
|
+
# nyc_ref = firestore.doc "cities/NYC"
|
453
|
+
#
|
454
|
+
# # Set the population to be at maximum 4,000,000.
|
455
|
+
# maximum_value = firestore.field_maximum 4000000
|
456
|
+
#
|
457
|
+
# nyc_ref.update({ name: "New York City",
|
458
|
+
# population: maximum_value })
|
459
|
+
#
|
460
|
+
def field_maximum value
|
461
|
+
FieldValue.maximum value
|
462
|
+
end
|
463
|
+
|
464
|
+
##
|
465
|
+
# Creates a sentinel value to indicate the setting the field to the
|
466
|
+
# minimum of its current value and the given value.
|
467
|
+
#
|
468
|
+
# If the field is not an integer or double (Numeric), or if the field
|
469
|
+
# does not yet exist, the transformation will set the field to the input
|
470
|
+
# value. If a minimum operation is applied where the field and the input
|
471
|
+
# value are of mixed types (that is - one is an integer and one is a
|
472
|
+
# double) the field takes on the type of the smaller operand. If the
|
473
|
+
# operands are equivalent (e.g. 3 and 3.0), the field does not change.
|
474
|
+
# 0, 0.0, and -0.0 are all zero. The minimum of a zero stored value and
|
475
|
+
# zero input value is always the stored value. The minimum of any
|
476
|
+
# numeric value x and NaN is NaN.
|
477
|
+
#
|
478
|
+
# @param [Numeric] value The value to compare against the given value to
|
479
|
+
# calculate the minimum value to set. Required.
|
480
|
+
#
|
481
|
+
# @return [FieldValue] The minimum field value object.
|
482
|
+
#
|
483
|
+
# @raise [ArgumentError] if the value is not a Numeric.
|
484
|
+
#
|
485
|
+
# @example
|
486
|
+
# require "google/cloud/firestore"
|
487
|
+
#
|
488
|
+
# firestore = Google::Cloud::Firestore.new
|
489
|
+
#
|
490
|
+
# # Get a document reference
|
491
|
+
# nyc_ref = firestore.doc "cities/NYC"
|
492
|
+
#
|
493
|
+
# # Set the population to be at minimum 1,000,000.
|
494
|
+
# minimum_value = firestore.field_minimum 1000000
|
495
|
+
#
|
496
|
+
# nyc_ref.update({ name: "New York City",
|
497
|
+
# population: minimum_value })
|
498
|
+
#
|
499
|
+
def field_minimum value
|
500
|
+
FieldValue.minimum value
|
501
|
+
end
|
502
|
+
|
355
503
|
# @!endgroup
|
356
504
|
|
357
505
|
# @!group Operations
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/firestore/
|
16
|
+
require "google/cloud/firestore/v1"
|
17
17
|
require "google/cloud/firestore/document_reference"
|
18
18
|
require "google/cloud/firestore/document_snapshot"
|
19
19
|
require "google/cloud/firestore/query"
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/firestore/
|
16
|
+
require "google/cloud/firestore/v1"
|
17
17
|
require "google/cloud/firestore/field_path"
|
18
18
|
require "time"
|
19
19
|
require "stringio"
|
@@ -85,40 +85,40 @@ module Google
|
|
85
85
|
|
86
86
|
def raw_to_value obj
|
87
87
|
if NilClass === obj
|
88
|
-
Google::Firestore::
|
88
|
+
Google::Firestore::V1::Value.new null_value: :NULL_VALUE
|
89
89
|
elsif TrueClass === obj || FalseClass === obj
|
90
|
-
Google::Firestore::
|
90
|
+
Google::Firestore::V1::Value.new boolean_value: obj
|
91
91
|
elsif Integer === obj
|
92
|
-
Google::Firestore::
|
92
|
+
Google::Firestore::V1::Value.new integer_value: obj
|
93
93
|
elsif Numeric === obj # Any number not an integer is a double
|
94
|
-
Google::Firestore::
|
94
|
+
Google::Firestore::V1::Value.new double_value: obj.to_f
|
95
95
|
elsif Time === obj || DateTime === obj || Date === obj
|
96
|
-
Google::Firestore::
|
96
|
+
Google::Firestore::V1::Value.new \
|
97
97
|
timestamp_value: time_to_timestamp(obj.to_time)
|
98
98
|
elsif String === obj || Symbol === obj
|
99
|
-
Google::Firestore::
|
99
|
+
Google::Firestore::V1::Value.new string_value: obj.to_s
|
100
100
|
elsif Google::Cloud::Firestore::DocumentReference === obj
|
101
|
-
Google::Firestore::
|
101
|
+
Google::Firestore::V1::Value.new reference_value: obj.path
|
102
102
|
elsif Array === obj
|
103
103
|
values = obj.map { |o| raw_to_value(o) }
|
104
|
-
Google::Firestore::
|
105
|
-
Google::Firestore::
|
104
|
+
Google::Firestore::V1::Value.new(array_value:
|
105
|
+
Google::Firestore::V1::ArrayValue.new(values: values))
|
106
106
|
elsif Hash === obj
|
107
107
|
# keys have been changed to strings before the hash gets here
|
108
108
|
geo_pairs = hash_is_geo_point? obj
|
109
109
|
if geo_pairs
|
110
|
-
Google::Firestore::
|
110
|
+
Google::Firestore::V1::Value.new(
|
111
111
|
geo_point_value: hash_to_geo_point(obj, geo_pairs)
|
112
112
|
)
|
113
113
|
else
|
114
114
|
fields = hash_to_fields obj
|
115
|
-
Google::Firestore::
|
116
|
-
Google::Firestore::
|
115
|
+
Google::Firestore::V1::Value.new(map_value:
|
116
|
+
Google::Firestore::V1::MapValue.new(fields: fields))
|
117
117
|
end
|
118
118
|
elsif obj.respond_to?(:read) && obj.respond_to?(:rewind)
|
119
119
|
obj.rewind
|
120
120
|
content = obj.read.force_encoding "ASCII-8BIT"
|
121
|
-
Google::Firestore::
|
121
|
+
Google::Firestore::V1::Value.new bytes_value: content
|
122
122
|
else
|
123
123
|
raise ArgumentError,
|
124
124
|
"A value of type #{obj.class} is not supported."
|
@@ -156,11 +156,11 @@ module Google
|
|
156
156
|
data, field_paths_and_values = remove_field_value_from data
|
157
157
|
|
158
158
|
if data.any? || field_paths_and_values.empty?
|
159
|
-
write = Google::Firestore::
|
160
|
-
update: Google::Firestore::
|
159
|
+
write = Google::Firestore::V1::Write.new(
|
160
|
+
update: Google::Firestore::V1::Document.new(
|
161
161
|
name: doc_path,
|
162
162
|
fields: hash_to_fields(data)),
|
163
|
-
current_document: Google::Firestore::
|
163
|
+
current_document: Google::Firestore::V1::Precondition.new(
|
164
164
|
exists: false)
|
165
165
|
)
|
166
166
|
writes << write
|
@@ -171,7 +171,7 @@ module Google
|
|
171
171
|
|
172
172
|
if data.empty?
|
173
173
|
transform_write.current_document = \
|
174
|
-
Google::Firestore::
|
174
|
+
Google::Firestore::V1::Precondition.new(exists: false)
|
175
175
|
end
|
176
176
|
|
177
177
|
writes << transform_write
|
@@ -207,8 +207,8 @@ module Google
|
|
207
207
|
|
208
208
|
data, field_paths_and_values = remove_field_value_from data
|
209
209
|
|
210
|
-
writes << Google::Firestore::
|
211
|
-
update: Google::Firestore::
|
210
|
+
writes << Google::Firestore::V1::Write.new(
|
211
|
+
update: Google::Firestore::V1::Document.new(
|
212
212
|
name: doc_path,
|
213
213
|
fields: hash_to_fields(data))
|
214
214
|
)
|
@@ -278,11 +278,11 @@ module Google
|
|
278
278
|
end
|
279
279
|
|
280
280
|
if data.any? || field_paths.any? || (allow_empty && field_paths_and_values.empty?)
|
281
|
-
writes << Google::Firestore::
|
282
|
-
update: Google::Firestore::
|
281
|
+
writes << Google::Firestore::V1::Write.new(
|
282
|
+
update: Google::Firestore::V1::Document.new(
|
283
283
|
name: doc_path,
|
284
284
|
fields: hash_to_fields(data)),
|
285
|
-
update_mask: Google::Firestore::
|
285
|
+
update_mask: Google::Firestore::V1::DocumentMask.new(
|
286
286
|
field_paths: field_paths.map(&:formatted_string).sort)
|
287
287
|
)
|
288
288
|
end
|
@@ -339,18 +339,18 @@ module Google
|
|
339
339
|
end
|
340
340
|
|
341
341
|
if data.any? || delete_paths.any?
|
342
|
-
write = Google::Firestore::
|
343
|
-
update: Google::Firestore::
|
342
|
+
write = Google::Firestore::V1::Write.new(
|
343
|
+
update: Google::Firestore::V1::Document.new(
|
344
344
|
name: doc_path,
|
345
345
|
fields: hash_to_fields(data)),
|
346
|
-
update_mask: Google::Firestore::
|
346
|
+
update_mask: Google::Firestore::V1::DocumentMask.new(
|
347
347
|
field_paths: (field_paths).map(&:formatted_string).sort),
|
348
|
-
current_document: Google::Firestore::
|
348
|
+
current_document: Google::Firestore::V1::Precondition.new(
|
349
349
|
exists: true)
|
350
350
|
)
|
351
351
|
if update_time
|
352
352
|
write.current_document = \
|
353
|
-
Google::Firestore::
|
353
|
+
Google::Firestore::V1::Precondition.new(
|
354
354
|
update_time: time_to_timestamp(update_time))
|
355
355
|
end
|
356
356
|
writes << write
|
@@ -360,7 +360,7 @@ module Google
|
|
360
360
|
transform_write = transform_write doc_path, field_paths_and_values
|
361
361
|
if data.empty?
|
362
362
|
transform_write.current_document = \
|
363
|
-
Google::Firestore::
|
363
|
+
Google::Firestore::V1::Precondition.new(exists: true)
|
364
364
|
end
|
365
365
|
writes << transform_write
|
366
366
|
end
|
@@ -373,13 +373,13 @@ module Google
|
|
373
373
|
raise ArgumentError, "cannot specify both exists and update_time"
|
374
374
|
end
|
375
375
|
|
376
|
-
write = Google::Firestore::
|
376
|
+
write = Google::Firestore::V1::Write.new(
|
377
377
|
delete: doc_path
|
378
378
|
)
|
379
379
|
|
380
380
|
unless exists.nil? && update_time.nil?
|
381
381
|
write.current_document = \
|
382
|
-
Google::Firestore::
|
382
|
+
Google::Firestore::V1::Precondition.new({
|
383
383
|
exists: exists, update_time: time_to_timestamp(update_time)
|
384
384
|
}.delete_if { |_, v| v.nil? })
|
385
385
|
end
|
@@ -584,8 +584,8 @@ module Google
|
|
584
584
|
to_field_transform field_path, field_value
|
585
585
|
end
|
586
586
|
|
587
|
-
Google::Firestore::
|
588
|
-
transform: Google::Firestore::
|
587
|
+
Google::Firestore::V1::Write.new(
|
588
|
+
transform: Google::Firestore::V1::DocumentTransform.new(
|
589
589
|
document: doc_path,
|
590
590
|
field_transforms: field_transforms
|
591
591
|
)
|
@@ -594,19 +594,34 @@ module Google
|
|
594
594
|
|
595
595
|
def to_field_transform field_path, field_value
|
596
596
|
if field_value.type == :server_time
|
597
|
-
Google::Firestore::
|
597
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
598
598
|
field_path: field_path.formatted_string,
|
599
599
|
set_to_server_value: :REQUEST_TIME
|
600
600
|
)
|
601
601
|
elsif field_value.type == :array_union
|
602
|
-
Google::Firestore::
|
602
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
603
603
|
field_path: field_path.formatted_string,
|
604
|
-
append_missing_elements: raw_to_value(Array(field_value.
|
604
|
+
append_missing_elements: raw_to_value(Array(field_value.value)).array_value
|
605
605
|
)
|
606
606
|
elsif field_value.type == :array_delete
|
607
|
-
Google::Firestore::
|
607
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
608
608
|
field_path: field_path.formatted_string,
|
609
|
-
remove_all_from_array: raw_to_value(Array(field_value.
|
609
|
+
remove_all_from_array: raw_to_value(Array(field_value.value)).array_value
|
610
|
+
)
|
611
|
+
elsif field_value.type == :increment
|
612
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
613
|
+
field_path: field_path.formatted_string,
|
614
|
+
increment: raw_to_value(field_value.value)
|
615
|
+
)
|
616
|
+
elsif field_value.type == :maximum
|
617
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
618
|
+
field_path: field_path.formatted_string,
|
619
|
+
maximum: raw_to_value(field_value.value)
|
620
|
+
)
|
621
|
+
elsif field_value.type == :minimum
|
622
|
+
Google::Firestore::V1::DocumentTransform::FieldTransform.new(
|
623
|
+
field_path: field_path.formatted_string,
|
624
|
+
minimum: raw_to_value(field_value.value)
|
610
625
|
)
|
611
626
|
else
|
612
627
|
raise ArgumentError, "unknown field transform #{field_value.type}"
|