google-cloud-datastore 2.6.0 → 2.7.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/google/cloud/datastore/dataset.rb +32 -0
- data/lib/google/cloud/datastore/filter.rb +222 -0
- data/lib/google/cloud/datastore/query.rb +57 -11
- data/lib/google/cloud/datastore/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b372b670c25604994c20b79779906b9a7c00b21bdf3ada9a23eb2cbb5968d053
|
|
4
|
+
data.tar.gz: 2cb8cac3d2de7b1b631d1c9ee7332b7391a73a720968bf09dc0608430de2a472
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dba07c333a2230e08f4c315dce2b8e28c748a082561c0692d9e419ba47565496b4b47463912e6cebea34ca3c33732df257ec6b4bcd9419b664cc16a4338b9b76
|
|
7
|
+
data.tar.gz: e817d031036cefd768ccf202a291435c6a710f69292ea61f2349bd5456732b3e0253ce94c75006abbcbc231c6c6e664bd4340dd2836f20978542dc2bb30b3b45
|
data/CHANGELOG.md
CHANGED
|
@@ -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 The value to compare the property to. Defaults to nil.
|
|
991
|
+
# 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
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
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.
|
|
4
|
+
version: 2.7.0
|
|
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-
|
|
12
|
+
date: 2023-04-12 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
|