google-cloud-datastore 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1471082bad6f76859fd0172a40bac47c81c31d3bc7f42e0f5135547f280307a6
4
- data.tar.gz: a182edc1deadbfe697c45fad2bcde90379c58d07985833fd3f4bca64584bfaf2
3
+ metadata.gz: 646ed90d461784d6870d425a6f98271a249338a72696200b3b2707d3e4725098
4
+ data.tar.gz: 963afff082dd55de2dce0f58715bd76c17497e118b0db92b7a542b6dd813b00d
5
5
  SHA512:
6
- metadata.gz: 41ae448187ef6bbd842bcafcb2c6cbd107b81e4dfb55b72bbfb62857af387a82b4361cc3b86cdf00ab2657a5b98bcf6f51c1caf2090b2c922f8f3db03016e19a
7
- data.tar.gz: 25725fc96567a06df8c6b75c4b29f9ff8077e77b59a7bb1c31d0c384a9a0d880d9e0d807653f75986c56d428dbcf7aaf09fa4074f7335eef76dcc520e21c9304
6
+ metadata.gz: 832baf39842dd1261ee5394284a0cc8448bd65fbf08162cc49a95f16654676f4dae76d4cb80be58a2692f7035f613b3b1668bf6e5f7d73f175a3f3ad7d6e3eb0
7
+ data.tar.gz: dd2b0d16cf4727a342e305a6c3dee82add4ce10f5faac8c691216e9e4a88d356d89cb49684cc71b92bfe162bc9aa099abca54c260698ca96722400a729a952e7
data/AUTHENTICATION.md CHANGED
@@ -125,15 +125,6 @@ To configure your system for this, simply:
125
125
  **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
126
126
  *should* only be used during development.
127
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
128
  ## Creating a Service Account
138
129
 
139
130
  Google Cloud requires a **Project ID** and **Service Account Credentials** to
@@ -144,31 +135,22 @@ If you are not running this client within [Google Cloud Platform
144
135
  environments](#google-cloud-platform-environments), you need a Google
145
136
  Developers service account.
146
137
 
147
- 1. Visit the [Google Developers Console][dev-console].
138
+ 1. Visit the [Google Cloud Console](https://console.cloud.google.com/project).
148
139
  1. Create a new project or click on an existing project.
149
- 1. Activate the slide-out navigation tray and select **API Manager**. From
140
+ 1. Activate the menu in the upper left and select **APIs & Services**. From
150
141
  here, you will enable the APIs that your application requires.
151
142
 
152
- ![Enable the APIs that your application requires][enable-apis]
153
-
154
143
  *Note: You may need to enable billing in order to use these services.*
155
144
 
156
145
  1. Select **Credentials** from the side navigation.
157
146
 
158
- You should see a screen like one of the following.
159
-
160
- ![Create a new service account][create-new-service-account]
161
-
162
- ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
163
-
164
- Find the "Add credentials" drop down and select "Service account" to be
165
- guided through downloading a new JSON key file.
166
-
167
- If you want to re-use an existing service account, you can easily generate a
168
- new key file. Just select the account you wish to re-use, and click "Generate
169
- new JSON key":
147
+ Find the "Create credentials" drop down near the top of the page, and select
148
+ "Service account" to be guided through downloading a new JSON key file.
170
149
 
171
- ![Re-use an existing service account][reuse-service-account]
150
+ If you want to re-use an existing service account, you can easily generate
151
+ a new key file. Just select the account you wish to re-use click the pencil
152
+ tool on the right side to edit the service account, select the **Keys** tab,
153
+ and then select **Add Key**.
172
154
 
173
155
  The key file you download will be used by this library to authenticate API
174
156
  requests and should be stored in a secure location.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 2.7.1 (2023-05-18)
4
+
5
+ #### Documentation
6
+
7
+ * Fixed broken links in authentication documentation ([#21619](https://github.com/googleapis/google-cloud-ruby/issues/21619))
8
+
9
+ ### 2.7.0 (2023-04-12)
10
+
11
+ #### Features
12
+
13
+ * Support OR filter ([#21002](https://github.com/googleapis/google-cloud-ruby/issues/21002))
14
+
3
15
  ### 2.6.0 (2023-02-13)
4
16
 
5
17
  #### Features
@@ -57,18 +57,20 @@ module Google
57
57
  #
58
58
  class AggregateQuery
59
59
  ##
60
- # @private The Google::Cloud::Datastore::V1::Query object.
61
- attr_reader :query
60
+ # @private The Google::Cloud::Datastore::V1::AggregationQuery object.
61
+ attr_reader :grpc
62
62
 
63
63
  ##
64
- # @private Array of Google::Cloud::Datastore::V1::AggregationQuery::Aggregation objects
65
- attr_reader :aggregates
66
-
67
- ##
68
- # @private Creates a new AggregateQuery
64
+ # @private
65
+ #
66
+ # Returns a new AggregateQuery object
67
+ #
68
+ # @param query [Google::Cloud::Datastore::V1::Query]
69
69
  def initialize query
70
- @query = query
71
- @aggregates = []
70
+ @grpc = Google::Cloud::Datastore::V1::AggregationQuery.new(
71
+ nested_query: query,
72
+ aggregations: []
73
+ )
72
74
  end
73
75
 
74
76
  ##
@@ -112,7 +114,7 @@ module Google
112
114
  #
113
115
  def add_count aggregate_alias: nil
114
116
  aggregate_alias ||= ALIASES[:count]
115
- aggregates << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
117
+ @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
116
118
  count: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Count.new,
117
119
  alias: aggregate_alias
118
120
  )
@@ -122,10 +124,7 @@ module Google
122
124
 
123
125
  # @private
124
126
  def to_grpc
125
- Google::Cloud::Datastore::V1::AggregationQuery.new(
126
- nested_query: query,
127
- aggregations: aggregates
128
- )
127
+ @grpc
129
128
  end
130
129
 
131
130
  ##
@@ -981,6 +981,38 @@ module Google
981
981
  entity
982
982
  end
983
983
 
984
+ ##
985
+ # Create a new Filter instance. This is a convenience method to make the
986
+ # creation of Filter objects easier.
987
+ #
988
+ # @param name [String] The property to filter by.
989
+ # @param operator [String] The operator to filter by. Defaults to nil.
990
+ # @param value [Object] The value to compare the property to. Defaults
991
+ # to nil. Possible values are:
992
+ # - Integer
993
+ # - Float/BigDecimal
994
+ # - String
995
+ # - Boolean
996
+ # - Array
997
+ # - Date/Time
998
+ # - StringIO
999
+ # - Google::Cloud::Datastore::Key
1000
+ # - Google::Cloud::Datastore::Entity
1001
+ # - nil
1002
+ #
1003
+ # @return [Google::Cloud::Datastore::Filter]
1004
+ #
1005
+ # @example
1006
+ # require "google/cloud/datastore"
1007
+ #
1008
+ # datastore = Google::Cloud::Datastore.new
1009
+ #
1010
+ # filter = datastore.filter("done", "=", false)
1011
+ #
1012
+ def filter name, operator, value
1013
+ Filter.new name, operator, value
1014
+ end
1015
+
984
1016
  protected
985
1017
 
986
1018
  ##
@@ -0,0 +1,222 @@
1
+ # Copyright 2023 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "google/cloud/datastore/v1"
16
+
17
+ module Google
18
+ module Cloud
19
+ module Datastore
20
+ ##
21
+ # Filter
22
+ #
23
+ # Represents the filter criteria for a datastore query.
24
+ #
25
+ # @example Run a query with a simple property filter.
26
+ # require "google/cloud/datastore"
27
+ #
28
+ # datastore = Google::Cloud::Datastore.new
29
+ #
30
+ # filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")
31
+ #
32
+ # query = Google::Cloud::Datastore::Query.new
33
+ # query.kind("Task")
34
+ # .where(filter)
35
+ #
36
+ # tasks = datastore.run query
37
+ #
38
+ # @example Construct a composite filter with a logical OR.
39
+ # require "google/cloud/datastore"
40
+ #
41
+ # datastore = Google::Cloud::Datastore.new
42
+ #
43
+ # filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")
44
+ # .or("priority", ">=", "4")
45
+ #
46
+ # query = Google::Cloud::Datastore::Query.new
47
+ # query.kind("Task")
48
+ # .where(filter)
49
+ #
50
+ # tasks = datastore.run query
51
+ #
52
+ # @example Construct a composite filter by combining multiple filters.
53
+ # require "google/cloud/datastore"
54
+ #
55
+ # datastore = Google::Cloud::Datastore.new
56
+ #
57
+ # filter_1 = Google::Cloud::Datastore::Filter.new("done", "=", "false")
58
+ # filter_2 = Google::Cloud::Datastore::Filter.new("priority", ">=", "4")
59
+ # filter = filter_1.or(filter_2)
60
+ #
61
+ # query = Google::Cloud::Datastore::Query.new
62
+ # query.kind("Task")
63
+ # .where(filter)
64
+ #
65
+ # tasks = datastore.run query
66
+ #
67
+ class Filter
68
+ ##
69
+ # @private Object of type
70
+ # Google::Cloud::Datastore::V1::Filter
71
+ attr_accessor :grpc
72
+
73
+ ##
74
+ # Creates a new Filter.
75
+ #
76
+ # @example
77
+ # require "google/cloud/datastore"
78
+ #
79
+ # filter = Google::Cloud::Datastore::Filter.new("done", "=", "false")
80
+ #
81
+ def initialize name, operator, value
82
+ @grpc = create_property_filter name, operator, value
83
+ end
84
+
85
+ ##
86
+ # Joins two filters with an AND operator.
87
+ #
88
+ # @overload and(name, operator, value)
89
+ # Joins the filter with a property filter
90
+ # @param name [String]
91
+ # @param operator [String]
92
+ # @param value
93
+ #
94
+ # @overload and(filter)
95
+ # Joins the filter with a Filter object
96
+ # @param filter [Filter]
97
+ #
98
+ # @example Join the filter with a property filter
99
+ # require "google/cloud/datastore"
100
+ #
101
+ # datastore = Google::Cloud::Datastore.new
102
+ #
103
+ # filter = Google::Cloud::Filter.new("done", "=", false)
104
+ # .and("priority", ">=", 4)
105
+ #
106
+ # @example Join the filter with a filter object
107
+ # require "google/cloud/datastore"
108
+ #
109
+ # datastore = Google::Cloud::Datastore.new
110
+ #
111
+ # filter_1 = Google::Cloud::Filter.new("done", "=", false)
112
+ # filter_2 = Google::Cloud::Filter.new("priority", ">=", 4)
113
+ #
114
+ # filter = filter_1.and(filter_2)
115
+ #
116
+ def and name_or_filter, operator = nil, value = nil
117
+ combine_filters composite_filter_and, name_or_filter, operator, value
118
+ end
119
+
120
+ ##
121
+ # Joins two filters with an OR operator.
122
+ #
123
+ # @overload or(name, operator, value)
124
+ # Joins the filter with a property filter
125
+ # @param name [String] The property to filter by.
126
+ # @param operator [String] The operator to filter by. Defaults to nil.
127
+ # @param value [Object] The value to compare the property to. Defaults to nil.
128
+ # Possible values are:
129
+ # - Integer
130
+ # - Float/BigDecimal
131
+ # - String
132
+ # - Boolean
133
+ # - Array
134
+ # - Date/Time
135
+ # - StringIO
136
+ # - Google::Cloud::Datastore::Key
137
+ # - Google::Cloud::Datastore::Entity
138
+ # - nil
139
+ #
140
+ # @overload or(filter)
141
+ # Joins the filter with a Filter object
142
+ # @param flter [Filter]
143
+ #
144
+ # @example Join the filter with a property filter
145
+ # require "google/cloud/datastore"
146
+ #
147
+ # datastore = Google::Cloud::Datastore.new
148
+ #
149
+ # filter = Google::Cloud::Filter.new("done", "=", false)
150
+ # .or("priority", ">=", 4)
151
+ #
152
+ # @example Join the filter with a filter object
153
+ # require "google/cloud/datastore"
154
+ #
155
+ # datastore = Google::Cloud::Datastore.new
156
+ #
157
+ # filter_1 = Google::Cloud::Filter.new("done", "=", false)
158
+ # filter_2 = Google::Cloud::Filter.new("priority", ">=", 4)
159
+ #
160
+ # filter = filter_1.or(filter_2)
161
+ #
162
+ def or name_or_filter, operator = nil, value = nil
163
+ combine_filters composite_filter_or, name_or_filter, operator, value
164
+ end
165
+
166
+ # @private
167
+ def to_grpc
168
+ @grpc
169
+ end
170
+
171
+ protected
172
+
173
+ ##
174
+ # @private
175
+ #
176
+ # Combines self.grpc and (name_or_filter, operator, value)
177
+ # into the new_filter object with the specified AND/OR operator
178
+ def combine_filters new_filter, name_or_filter, operator, value
179
+ new_filter.composite_filter.filters << to_grpc
180
+ new_filter.composite_filter.filters << if name_or_filter.is_a? Google::Cloud::Datastore::Filter
181
+ name_or_filter.to_grpc
182
+ else
183
+ create_property_filter name_or_filter, operator, value
184
+ end
185
+ dup.tap do |f|
186
+ f.grpc = new_filter
187
+ end
188
+ end
189
+
190
+ ##
191
+ # @private
192
+ def composite_filter_and
193
+ Google::Cloud::Datastore::V1::Filter.new(
194
+ composite_filter: Google::Cloud::Datastore::V1::CompositeFilter.new(op: :AND)
195
+ )
196
+ end
197
+
198
+ ##
199
+ # @private
200
+ def composite_filter_or
201
+ Google::Cloud::Datastore::V1::Filter.new(
202
+ composite_filter: Google::Cloud::Datastore::V1::CompositeFilter.new(op: :OR)
203
+ )
204
+ end
205
+
206
+ ##
207
+ # @private
208
+ def create_property_filter name, operator, value
209
+ Google::Cloud::Datastore::V1::Filter.new(
210
+ property_filter: Google::Cloud::Datastore::V1::PropertyFilter.new(
211
+ property: Google::Cloud::Datastore::V1::PropertyReference.new(
212
+ name: name
213
+ ),
214
+ op: Convert.to_prop_filter_op(operator),
215
+ value: Convert.to_value(value)
216
+ )
217
+ )
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
@@ -16,6 +16,7 @@
16
16
  require "google/cloud/datastore/entity"
17
17
  require "google/cloud/datastore/key"
18
18
  require "google/cloud/datastore/aggregate_query"
19
+ require "google/cloud/datastore/filter"
19
20
 
20
21
  module Google
21
22
  module Cloud
@@ -96,6 +97,27 @@ module Google
96
97
  ##
97
98
  # Add a property filter to the query.
98
99
  #
100
+ # @overload and(name, operator, value)
101
+ # Joins the filter with a property filter
102
+ # @param name [String] The property to filter by.
103
+ # @param operator [String] The operator to filter by. Defaults to nil.
104
+ # @param value [Object] The value to compare the property to. Defaults to nil.
105
+ # Possible values are:
106
+ # - Integer
107
+ # - Float/BigDecimal
108
+ # - String
109
+ # - Boolean
110
+ # - Array
111
+ # - Date/Time
112
+ # - StringIO
113
+ # - Google::Cloud::Datastore::Key
114
+ # - Google::Cloud::Datastore::Entity
115
+ # - nil
116
+ #
117
+ # @overload and(filter)
118
+ # Joins the filter with a Filter object
119
+ # @param filter [Filter]
120
+ #
99
121
  # @example
100
122
  # require "google/cloud/datastore"
101
123
  #
@@ -119,6 +141,34 @@ module Google
119
141
  #
120
142
  # tasks = datastore.run query
121
143
  #
144
+ # @example Add a composite "AND" filter:
145
+ # require "google/cloud/datastore"
146
+ #
147
+ # datastore = Google::Cloud::Datastore.new
148
+ #
149
+ # filter = Google::Cloud::Filter.new("done", "=", false)
150
+ # .and("priority", ">=", 4)
151
+ #
152
+ # query = Google::Cloud::Datastore::Query.new
153
+ # query.kind("Task")
154
+ # .where(filter)
155
+ #
156
+ # tasks = datastore.run query
157
+ #
158
+ # @example Add a composite "OR" filter:
159
+ # require "google/cloud/datastore"
160
+ #
161
+ # datastore = Google::Cloud::Datastore.new
162
+ #
163
+ # filter = Google::Cloud::Filter.new("done", "=", false)
164
+ # .or("priority", ">=", 4)
165
+ #
166
+ # query = Google::Cloud::Datastore::Query.new
167
+ # query.kind("Task")
168
+ # .where(filter)
169
+ #
170
+ # tasks = datastore.run query
171
+ #
122
172
  # @example Add an inequality filter on a **single** property only:
123
173
  # require "google/cloud/datastore"
124
174
  #
@@ -177,22 +227,18 @@ module Google
177
227
  #
178
228
  # tasks = datastore.run query
179
229
  #
180
- def where name, operator, value
230
+ def where name_or_filter, operator = nil, value = nil
181
231
  @grpc.filter ||= Google::Cloud::Datastore::V1::Filter.new(
182
232
  composite_filter: Google::Cloud::Datastore::V1::CompositeFilter.new(
183
233
  op: :AND
184
234
  )
185
235
  )
186
- @grpc.filter.composite_filter.filters << \
187
- Google::Cloud::Datastore::V1::Filter.new(
188
- property_filter: Google::Cloud::Datastore::V1::PropertyFilter.new(
189
- property: Google::Cloud::Datastore::V1::PropertyReference.new(
190
- name: name
191
- ),
192
- op: Convert.to_prop_filter_op(operator),
193
- value: Convert.to_value(value)
194
- )
195
- )
236
+ if name_or_filter.is_a? Google::Cloud::Datastore::Filter
237
+ @grpc.filter.composite_filter.filters << name_or_filter.to_grpc
238
+ else
239
+ @grpc.filter.composite_filter.filters << \
240
+ Google::Cloud::Datastore::Filter.new(name_or_filter, operator, value).to_grpc
241
+ end
196
242
 
197
243
  self
198
244
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Datastore
19
- VERSION = "2.6.0".freeze
19
+ VERSION = "2.7.1".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-13 00:00:00.000000000 Z
12
+ date: 2023-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -210,6 +210,7 @@ files:
210
210
  - lib/google/cloud/datastore/dataset/query_results.rb
211
211
  - lib/google/cloud/datastore/entity.rb
212
212
  - lib/google/cloud/datastore/errors.rb
213
+ - lib/google/cloud/datastore/filter.rb
213
214
  - lib/google/cloud/datastore/gql_query.rb
214
215
  - lib/google/cloud/datastore/key.rb
215
216
  - lib/google/cloud/datastore/properties.rb