google-cloud-datastore 2.7.1 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/google/cloud/datastore/aggregate_query.rb +118 -7
- data/lib/google/cloud/datastore/dataset/aggregate_query_results.rb +22 -4
- data/lib/google/cloud/datastore/gql_query.rb +3 -4
- data/lib/google/cloud/datastore/key.rb +1 -1
- data/lib/google/cloud/datastore/properties.rb +3 -2
- data/lib/google/cloud/datastore/service.rb +2 -3
- data/lib/google/cloud/datastore/version.rb +1 -1
- data/lib/google/cloud/datastore.rb +1 -1
- data/lib/google-cloud-datastore.rb +5 -2
- metadata +4 -144
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed10b12e2ec3c4588dba12b44b76116605981600f15623e1a4a48af8646424ba
|
4
|
+
data.tar.gz: '095dcff60d7ab782f182264f20f0294be2f01b61278fbd448b307b9d7b922504'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abddd5e808cb0b94c4fd26f5c0a18df08cbf211894e1b732cbbe1f611f225cf311450df52d61c6eca430b74483b222ea48b55a30d8139d92bdc25e355fb1d55a
|
7
|
+
data.tar.gz: 3df7cd4c6ca17d8ab1770ec93a92c4426f67f16eb0fe15335c6986a1f568ca16c2058290605a490984b5598fc266380339ac0b6f613562ceda2fc541d7e24063
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.9.0 (2024-03-10)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Update minimum supported Ruby version to 2.7 ([#25298](https://github.com/googleapis/google-cloud-ruby/issues/25298))
|
8
|
+
|
9
|
+
### 2.8.0 (2023-09-12)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* Support sum & avg aggregate functions ([#22884](https://github.com/googleapis/google-cloud-ruby/issues/22884))
|
14
|
+
|
3
15
|
### 2.7.1 (2023-05-18)
|
4
16
|
|
5
17
|
#### Documentation
|
@@ -56,6 +56,15 @@ module Google
|
|
56
56
|
# puts aggregate_query_results.get('total')
|
57
57
|
#
|
58
58
|
class AggregateQuery
|
59
|
+
# @private
|
60
|
+
DEFAULT_COUNT_AGGREGATE_ALIAS = "count".freeze
|
61
|
+
|
62
|
+
# @private
|
63
|
+
DEFAULT_SUM_AGGREGATE_ALIAS = "sum".freeze
|
64
|
+
|
65
|
+
# @private
|
66
|
+
DEFAULT_AVG_AGGREGATE_ALIAS = "avg".freeze
|
67
|
+
|
59
68
|
##
|
60
69
|
# @private The Google::Cloud::Datastore::V1::AggregationQuery object.
|
61
70
|
attr_reader :grpc
|
@@ -113,7 +122,7 @@ module Google
|
|
113
122
|
# puts aggregate_query_results.get('total')
|
114
123
|
#
|
115
124
|
def add_count aggregate_alias: nil
|
116
|
-
aggregate_alias ||=
|
125
|
+
aggregate_alias ||= DEFAULT_COUNT_AGGREGATE_ALIAS
|
117
126
|
@grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
|
118
127
|
count: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Count.new,
|
119
128
|
alias: aggregate_alias
|
@@ -122,16 +131,118 @@ module Google
|
|
122
131
|
self
|
123
132
|
end
|
124
133
|
|
125
|
-
|
126
|
-
|
127
|
-
|
134
|
+
##
|
135
|
+
# Adds a sum aggregate.
|
136
|
+
#
|
137
|
+
# @param name [String] The property to sum by.
|
138
|
+
# @param aggregate_alias [String] Alias to refer to the aggregate. Optional
|
139
|
+
#
|
140
|
+
# @return [AggregateQuery] The modified aggregate query object with the added SUM aggregate.
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# require "google/cloud/datastore"
|
144
|
+
#
|
145
|
+
# datastore = Google::Cloud::Datastore.new
|
146
|
+
#
|
147
|
+
# query = Google::Cloud::Datastore::Query.new
|
148
|
+
# query.kind("Task")
|
149
|
+
# .where("done", "=", false)
|
150
|
+
#
|
151
|
+
# Create an aggregate query
|
152
|
+
# aggregate_query = query.aggregate_query
|
153
|
+
# .add_sum("score")
|
154
|
+
#
|
155
|
+
# aggregate_query_results = dataset.run_aggregation aggregate_query
|
156
|
+
# puts aggregate_query_results.get
|
157
|
+
#
|
158
|
+
# @example Alias an aggregate SUM query
|
159
|
+
# require "google/cloud/datastore"
|
160
|
+
#
|
161
|
+
# datastore = Google::Cloud::Datastore.new
|
162
|
+
#
|
163
|
+
# query = Google::Cloud::Datastore::Query.new
|
164
|
+
# query.kind("Task")
|
165
|
+
# .where("done", "=", false)
|
166
|
+
#
|
167
|
+
# # Create an aggregate query
|
168
|
+
# aggregate_query = query.aggregate_query
|
169
|
+
# .add_sum("score", aggregate_alias: 'total_score')
|
170
|
+
#
|
171
|
+
# aggregate_query_results = dataset.run_aggregation aggregate_query
|
172
|
+
# puts aggregate_query_results.get('total_score')
|
173
|
+
#
|
174
|
+
def add_sum name, aggregate_alias: nil
|
175
|
+
aggregate_alias ||= DEFAULT_SUM_AGGREGATE_ALIAS
|
176
|
+
@grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
|
177
|
+
sum: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Sum.new(
|
178
|
+
property: Google::Cloud::Datastore::V1::PropertyReference.new(
|
179
|
+
name: name
|
180
|
+
)
|
181
|
+
),
|
182
|
+
alias: aggregate_alias
|
183
|
+
)
|
184
|
+
|
185
|
+
self
|
128
186
|
end
|
129
187
|
|
130
188
|
##
|
189
|
+
# Adds an average aggregate.
|
190
|
+
#
|
191
|
+
# @param name [String] The property to apply average on.
|
192
|
+
# @param aggregate_alias [String] Alias to refer to the aggregate. Optional
|
193
|
+
#
|
194
|
+
# @return [AggregateQuery] The modified aggregate query object with the added AVG aggregate.
|
195
|
+
#
|
196
|
+
# @example
|
197
|
+
# require "google/cloud/datastore"
|
198
|
+
#
|
199
|
+
# datastore = Google::Cloud::Datastore.new
|
200
|
+
#
|
201
|
+
# query = Google::Cloud::Datastore::Query.new
|
202
|
+
# query.kind("Task")
|
203
|
+
# .where("done", "=", false)
|
204
|
+
#
|
205
|
+
# Create an aggregate query
|
206
|
+
# aggregate_query = query.aggregate_query
|
207
|
+
# .add_avg("score")
|
208
|
+
#
|
209
|
+
# aggregate_query_results = dataset.run_aggregation aggregate_query
|
210
|
+
# puts aggregate_query_results.get
|
211
|
+
#
|
212
|
+
# @example Alias an aggregate AVG query
|
213
|
+
# require "google/cloud/datastore"
|
214
|
+
#
|
215
|
+
# datastore = Google::Cloud::Datastore.new
|
216
|
+
#
|
217
|
+
# query = Google::Cloud::Datastore::Query.new
|
218
|
+
# query.kind("Task")
|
219
|
+
# .where("done", "=", false)
|
220
|
+
#
|
221
|
+
# # Create an aggregate query
|
222
|
+
# aggregate_query = query.aggregate_query
|
223
|
+
# .add_avg("score", aggregate_alias: 'avg_score')
|
224
|
+
#
|
225
|
+
# aggregate_query_results = dataset.run_aggregation aggregate_query
|
226
|
+
# puts aggregate_query_results.get('avg_score')
|
227
|
+
#
|
228
|
+
def add_avg name, aggregate_alias: nil
|
229
|
+
aggregate_alias ||= DEFAULT_AVG_AGGREGATE_ALIAS
|
230
|
+
@grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
|
231
|
+
avg: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Avg.new(
|
232
|
+
property: Google::Cloud::Datastore::V1::PropertyReference.new(
|
233
|
+
name: name
|
234
|
+
)
|
235
|
+
),
|
236
|
+
alias: aggregate_alias
|
237
|
+
)
|
238
|
+
|
239
|
+
self
|
240
|
+
end
|
241
|
+
|
131
242
|
# @private
|
132
|
-
|
133
|
-
|
134
|
-
|
243
|
+
def to_grpc
|
244
|
+
@grpc
|
245
|
+
end
|
135
246
|
end
|
136
247
|
end
|
137
248
|
end
|
@@ -39,6 +39,17 @@ module Google
|
|
39
39
|
# puts aggregate_query_results.get
|
40
40
|
#
|
41
41
|
class AggregateQueryResults
|
42
|
+
##
|
43
|
+
# @private Object of type [Hash{String => Object}].
|
44
|
+
#
|
45
|
+
# String can have the following values:
|
46
|
+
# - an aggregate literal "sum", "avg", or "count"
|
47
|
+
# - a custom aggregate alias
|
48
|
+
# Object can have the following types:
|
49
|
+
# - Integer
|
50
|
+
# - Float
|
51
|
+
attr_reader :aggregate_fields
|
52
|
+
|
42
53
|
##
|
43
54
|
# Read timestamp the query was done on the database at.
|
44
55
|
#
|
@@ -52,7 +63,8 @@ module Google
|
|
52
63
|
# the aggregate value. For an AggregateQuery with a
|
53
64
|
# single aggregate field, this parameter can be omitted.
|
54
65
|
#
|
55
|
-
# @return [Integer] The aggregate value.
|
66
|
+
# @return [Integer, Float, nil] The aggregate value. Returns `nil`
|
67
|
+
# if the aggregate_alias does not exist.
|
56
68
|
#
|
57
69
|
# @example
|
58
70
|
# require "google/cloud/datastore"
|
@@ -101,10 +113,16 @@ module Google
|
|
101
113
|
.batch
|
102
114
|
.aggregation_results[0]
|
103
115
|
.aggregate_properties
|
104
|
-
.
|
105
|
-
|
116
|
+
.map do |aggregate_alias, value|
|
117
|
+
if value.has_integer_value?
|
118
|
+
[aggregate_alias, value.integer_value]
|
119
|
+
else
|
120
|
+
[aggregate_alias, value.double_value]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
106
124
|
new.tap do |s|
|
107
|
-
s.instance_variable_set :@aggregate_fields, aggregate_fields
|
125
|
+
s.instance_variable_set :@aggregate_fields, aggregate_fields.to_h
|
108
126
|
s.instance_variable_set :@read_time, aggregate_query_response.batch.read_time
|
109
127
|
end
|
110
128
|
end
|
@@ -127,15 +127,14 @@ module Google
|
|
127
127
|
# query string to valid GQL arguments
|
128
128
|
#
|
129
129
|
def named_bindings
|
130
|
-
|
130
|
+
bindings_elems = @grpc.named_bindings.map do |name, gql_query_param|
|
131
131
|
if gql_query_param.parameter_type == :cursor
|
132
132
|
[name, Cursor.from_grpc(gql_query_param.cursor)]
|
133
133
|
else
|
134
134
|
[name, Convert.from_value(gql_query_param.value)]
|
135
135
|
end
|
136
|
-
end
|
137
|
-
|
138
|
-
bindings
|
136
|
+
end
|
137
|
+
bindings_elems.to_h.freeze
|
139
138
|
end
|
140
139
|
|
141
140
|
##
|
@@ -74,12 +74,13 @@ module Google
|
|
74
74
|
|
75
75
|
def to_grpc
|
76
76
|
# Convert to Hash with Google::Cloud::Datastore::V1::Value values.
|
77
|
-
|
77
|
+
@hash.to_h { |k, v| [k.to_s, Convert.to_value(v)] }
|
78
78
|
end
|
79
79
|
|
80
80
|
def self.from_grpc grpc_map
|
81
81
|
# Convert to Hash of string keys and raw values.
|
82
|
-
|
82
|
+
map_elems = grpc_map.map { |k, v| [k.to_s, Convert.from_value(v)] }
|
83
|
+
new map_elems.to_h
|
83
84
|
end
|
84
85
|
|
85
86
|
protected
|
@@ -117,14 +117,13 @@ module Google
|
|
117
117
|
def begin_transaction read_only: nil, previous_transaction: nil, read_time: nil
|
118
118
|
if read_only
|
119
119
|
transaction_options = Google::Cloud::Datastore::V1::TransactionOptions.new
|
120
|
-
transaction_options.read_only =
|
120
|
+
transaction_options.read_only =
|
121
121
|
Google::Cloud::Datastore::V1::TransactionOptions::ReadOnly.new \
|
122
122
|
read_time: read_time_to_timestamp(read_time)
|
123
123
|
|
124
124
|
end
|
125
125
|
if previous_transaction
|
126
|
-
transaction_options ||=
|
127
|
-
Google::Cloud::Datastore::V1::TransactionOptions.new
|
126
|
+
transaction_options ||= Google::Cloud::Datastore::V1::TransactionOptions.new
|
128
127
|
rw = Google::Cloud::Datastore::V1::TransactionOptions::ReadWrite.new(
|
129
128
|
previous_transaction: previous_transaction.encode("ASCII-8BIT")
|
130
129
|
)
|
@@ -127,7 +127,7 @@ module Google
|
|
127
127
|
)
|
128
128
|
end
|
129
129
|
|
130
|
-
credentials ||=
|
130
|
+
credentials ||= keyfile || default_credentials(scope: scope)
|
131
131
|
unless credentials.is_a? Google::Auth::Credentials
|
132
132
|
credentials = Datastore::Credentials.new credentials, scope: scope
|
133
133
|
end
|
@@ -68,8 +68,10 @@ module Google
|
|
68
68
|
# datastore = gcloud.datastore scope: platform_scope
|
69
69
|
#
|
70
70
|
def datastore scope: nil, timeout: nil, database_id: nil
|
71
|
+
timeout ||= @timeout
|
71
72
|
Google::Cloud.datastore @project, @keyfile,
|
72
|
-
scope: scope,
|
73
|
+
scope: scope,
|
74
|
+
timeout: timeout,
|
73
75
|
database_id: database_id
|
74
76
|
end
|
75
77
|
|
@@ -117,7 +119,8 @@ module Google
|
|
117
119
|
require "google/cloud/datastore"
|
118
120
|
Google::Cloud::Datastore.new project_id: project_id,
|
119
121
|
credentials: credentials,
|
120
|
-
scope: scope,
|
122
|
+
scope: scope,
|
123
|
+
timeout: timeout,
|
121
124
|
database_id: database_id
|
122
125
|
end
|
123
126
|
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.9.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:
|
12
|
+
date: 2024-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -39,146 +39,6 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0.0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: google-style
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 1.25.1
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 1.25.1
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: minitest
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '5.16'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '5.16'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: minitest-autotest
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '1.0'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '1.0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: minitest-focus
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '1.1'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '1.1'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: minitest-rg
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - "~>"
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '5.2'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '5.2'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: autotest-suffix
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '1.1'
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '1.1'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: redcarpet
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
130
|
-
- - "~>"
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '3.0'
|
133
|
-
type: :development
|
134
|
-
prerelease: false
|
135
|
-
version_requirements: !ruby/object:Gem::Requirement
|
136
|
-
requirements:
|
137
|
-
- - "~>"
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version: '3.0'
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
|
-
name: simplecov
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - "~>"
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: '0.9'
|
147
|
-
type: :development
|
148
|
-
prerelease: false
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '0.9'
|
154
|
-
- !ruby/object:Gem::Dependency
|
155
|
-
name: yard
|
156
|
-
requirement: !ruby/object:Gem::Requirement
|
157
|
-
requirements:
|
158
|
-
- - "~>"
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
version: '0.9'
|
161
|
-
type: :development
|
162
|
-
prerelease: false
|
163
|
-
version_requirements: !ruby/object:Gem::Requirement
|
164
|
-
requirements:
|
165
|
-
- - "~>"
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
version: '0.9'
|
168
|
-
- !ruby/object:Gem::Dependency
|
169
|
-
name: yard-doctest
|
170
|
-
requirement: !ruby/object:Gem::Requirement
|
171
|
-
requirements:
|
172
|
-
- - "~>"
|
173
|
-
- !ruby/object:Gem::Version
|
174
|
-
version: 0.1.13
|
175
|
-
type: :development
|
176
|
-
prerelease: false
|
177
|
-
version_requirements: !ruby/object:Gem::Requirement
|
178
|
-
requirements:
|
179
|
-
- - "~>"
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
version: 0.1.13
|
182
42
|
description: google-cloud-datastore is the official library for Google Cloud Datastore.
|
183
43
|
email:
|
184
44
|
- mike@blowmage.com
|
@@ -231,14 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
91
|
requirements:
|
232
92
|
- - ">="
|
233
93
|
- !ruby/object:Gem::Version
|
234
|
-
version: '2.
|
94
|
+
version: '2.7'
|
235
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
96
|
requirements:
|
237
97
|
- - ">="
|
238
98
|
- !ruby/object:Gem::Version
|
239
99
|
version: '0'
|
240
100
|
requirements: []
|
241
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.5.6
|
242
102
|
signing_key:
|
243
103
|
specification_version: 4
|
244
104
|
summary: API Client library for Google Cloud Datastore
|