google-cloud-datastore 1.8.2 → 2.0.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/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +23 -0
- data/lib/google-cloud-datastore.rb +12 -18
- data/lib/google/cloud/datastore.rb +12 -11
- data/lib/google/cloud/datastore/commit.rb +4 -4
- data/lib/google/cloud/datastore/convert.rb +4 -4
- data/lib/google/cloud/datastore/credentials.rb +2 -2
- data/lib/google/cloud/datastore/entity.rb +3 -3
- data/lib/google/cloud/datastore/gql_query.rb +5 -5
- data/lib/google/cloud/datastore/key.rb +5 -5
- data/lib/google/cloud/datastore/properties.rb +1 -1
- data/lib/google/cloud/datastore/query.rb +12 -12
- data/lib/google/cloud/datastore/service.rb +31 -86
- data/lib/google/cloud/datastore/version.rb +1 -1
- metadata +8 -63
- data/lib/google/cloud/datastore/v1.rb +0 -16
- data/lib/google/cloud/datastore/v1/credentials.rb +0 -39
- data/lib/google/cloud/datastore/v1/datastore_client.rb +0 -577
- data/lib/google/cloud/datastore/v1/datastore_client_config.json +0 -61
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/datastore.rb +0 -283
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/entity.rb +0 -189
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/query.rb +0 -297
- data/lib/google/cloud/datastore/v1/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/datastore/v1/doc/google/protobuf/timestamp.rb +0 -109
- data/lib/google/cloud/datastore/v1/doc/google/protobuf/wrappers.rb +0 -26
- data/lib/google/cloud/datastore/v1/doc/google/type/latlng.rb +0 -65
- data/lib/google/datastore/v1/datastore_pb.rb +0 -147
- data/lib/google/datastore/v1/datastore_services_pb.rb +0 -65
- data/lib/google/datastore/v1/entity_pb.rb +0 -64
- data/lib/google/datastore/v1/query_pb.rb +0 -132
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826035219f59542e1883c4bd94ae39ecd846bf15d5449a3494553fdf3f97b1b3
|
4
|
+
data.tar.gz: 4896e0241e4853b98c58ad176fc8d7497c6e48e57ef621227c6feeeadcdd8002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 462c9cea295f6f9c162b69f4b4494bd681928c5970a96eb1de89896535f732de81150fe2b3f7ef35a00396c7a917269c42e0fda6cdc70d974e984d309caf7dec
|
7
|
+
data.tar.gz: 4be0857cc53dab982c5542e04249b66bb2e6475666343623f778b1310e16f2de2f12861345dc2794289bd27beaf8e05269541f9b2f2c1f42f753a3113375a76e
|
data/AUTHENTICATION.md
CHANGED
@@ -76,7 +76,8 @@ The environment variables that google-cloud-datastore checks for project ID are:
|
|
76
76
|
1. `DATASTORE_PROJECT`
|
77
77
|
2. `GOOGLE_CLOUD_PROJECT`
|
78
78
|
|
79
|
-
The environment variables that google-cloud-datastore checks for credentials are configured on
|
79
|
+
The environment variables that google-cloud-datastore checks for credentials are configured on
|
80
|
+
{Google::Cloud::Datastore::Credentials}:
|
80
81
|
|
81
82
|
1. `DATASTORE_CREDENTIALS` - Path to JSON file, or JSON contents
|
82
83
|
2. `DATASTORE_KEYFILE` - Path to JSON file, or JSON contents
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.0.0 / 2020-08-06
|
4
|
+
|
5
|
+
This is a major update that removes the "low-level" client interface code, and
|
6
|
+
instead adds the new `google-cloud-datastore-v1` gem as a dependency.
|
7
|
+
The new dependency is a rewritten low-level client, produced by a next-
|
8
|
+
generation client code generator, with improved performance and stability.
|
9
|
+
|
10
|
+
This change should have no effect on the high-level interface that most users
|
11
|
+
will use. The one exception is that the (mostly undocumented) `client_config`
|
12
|
+
argument, for adjusting low-level parameters such as RPC retry settings on
|
13
|
+
client objects, has been removed. If you need to adjust these parameters, use
|
14
|
+
the configuration interface in `google-cloud-datastore-v1`.
|
15
|
+
|
16
|
+
Substantial changes have been made in the low-level interfaces, however. If you
|
17
|
+
are using the low-level classes under the `Google::Cloud::Datastore::V1` module,
|
18
|
+
please review the docs for the new `google-cloud-datastore-v1` gem. In
|
19
|
+
particular:
|
20
|
+
|
21
|
+
* Some classes have been renamed, notably the client class itself.
|
22
|
+
* The client constructor takes a configuration block instead of configuration
|
23
|
+
keyword arguments.
|
24
|
+
* All RPC method arguments are now keyword arguments.
|
25
|
+
|
3
26
|
### 1.8.2 / 2020-05-28
|
4
27
|
|
5
28
|
#### Documentation
|
@@ -42,8 +42,6 @@ module Google
|
|
42
42
|
#
|
43
43
|
# * `https://www.googleapis.com/auth/datastore`
|
44
44
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
45
|
-
# @param [Hash] client_config A hash of values to override the default
|
46
|
-
# behavior of the API client. See Google::Gax::CallSettings. Optional.
|
47
45
|
#
|
48
46
|
# @return [Google::Cloud::Datastore::Dataset]
|
49
47
|
#
|
@@ -69,10 +67,9 @@ module Google
|
|
69
67
|
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
70
68
|
# datastore = gcloud.datastore scope: platform_scope
|
71
69
|
#
|
72
|
-
def datastore scope: nil, timeout: nil
|
70
|
+
def datastore scope: nil, timeout: nil
|
73
71
|
Google::Cloud.datastore @project, @keyfile,
|
74
|
-
scope: scope, timeout: (timeout || @timeout)
|
75
|
-
client_config: client_config
|
72
|
+
scope: scope, timeout: (timeout || @timeout)
|
76
73
|
end
|
77
74
|
|
78
75
|
##
|
@@ -96,8 +93,6 @@ module Google
|
|
96
93
|
#
|
97
94
|
# * `https://www.googleapis.com/auth/datastore`
|
98
95
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
99
|
-
# @param [Hash] client_config A hash of values to override the default
|
100
|
-
# behavior of the API client. See Google::Gax::CallSettings. Optional.
|
101
96
|
#
|
102
97
|
# @return [Google::Cloud::Datastore::Dataset]
|
103
98
|
#
|
@@ -117,12 +112,11 @@ module Google
|
|
117
112
|
# datastore.save task
|
118
113
|
#
|
119
114
|
def self.datastore project_id = nil, credentials = nil, scope: nil,
|
120
|
-
timeout: nil
|
115
|
+
timeout: nil
|
121
116
|
require "google/cloud/datastore"
|
122
117
|
Google::Cloud::Datastore.new project_id: project_id,
|
123
118
|
credentials: credentials,
|
124
|
-
scope: scope, timeout: timeout
|
125
|
-
client_config: client_config
|
119
|
+
scope: scope, timeout: timeout
|
126
120
|
end
|
127
121
|
end
|
128
122
|
end
|
@@ -141,17 +135,17 @@ Google::Cloud.configure.add_config! :datastore do |config|
|
|
141
135
|
default_emulator = Google::Cloud::Config.deferred do
|
142
136
|
ENV["DATASTORE_EMULATOR_HOST"]
|
143
137
|
end
|
138
|
+
default_scopes = [
|
139
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
140
|
+
"https://www.googleapis.com/auth/datastore"
|
141
|
+
]
|
144
142
|
|
145
143
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
146
144
|
config.add_alias! :project, :project_id
|
147
|
-
config.add_field! :credentials, default_creds,
|
148
|
-
match: [String, Hash, Google::Auth::Credentials],
|
149
|
-
allow_nil: true
|
145
|
+
config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
|
150
146
|
config.add_alias! :keyfile, :credentials
|
151
|
-
config.add_field! :scope,
|
147
|
+
config.add_field! :scope, default_scopes, match: [String, Array]
|
152
148
|
config.add_field! :timeout, nil, match: Integer
|
153
|
-
config.add_field! :
|
154
|
-
config.add_field! :
|
155
|
-
match: String, allow_nil: true
|
156
|
-
config.add_field! :endpoint, nil, match: String
|
149
|
+
config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
|
150
|
+
config.add_field! :endpoint, "datastore.googleapis.com", match: String
|
157
151
|
end
|
@@ -70,8 +70,6 @@ module Google
|
|
70
70
|
#
|
71
71
|
# * `https://www.googleapis.com/auth/datastore`
|
72
72
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
73
|
-
# @param [Hash] client_config A hash of values to override the default
|
74
|
-
# behavior of the API client. See Google::Gax::CallSettings. Optional.
|
75
73
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
76
74
|
# If the param is nil, uses the default endpoint.
|
77
75
|
# @param [String] emulator_host Datastore emulator host. Optional.
|
@@ -99,13 +97,17 @@ module Google
|
|
99
97
|
#
|
100
98
|
# datastore.save task
|
101
99
|
#
|
102
|
-
def self.new project_id: nil,
|
103
|
-
|
104
|
-
|
100
|
+
def self.new project_id: nil,
|
101
|
+
credentials: nil,
|
102
|
+
scope: nil,
|
103
|
+
timeout: nil,
|
104
|
+
endpoint: nil,
|
105
|
+
emulator_host: nil,
|
106
|
+
project: nil,
|
107
|
+
keyfile: nil
|
105
108
|
project_id ||= (project || default_project_id)
|
106
109
|
scope ||= configure.scope
|
107
110
|
timeout ||= configure.timeout
|
108
|
-
client_config ||= configure.client_config
|
109
111
|
endpoint ||= configure.endpoint
|
110
112
|
emulator_host ||= configure.emulator_host
|
111
113
|
|
@@ -116,8 +118,7 @@ module Google
|
|
116
118
|
return Datastore::Dataset.new(
|
117
119
|
Datastore::Service.new(
|
118
120
|
project_id, :this_channel_is_insecure,
|
119
|
-
host: emulator_host, timeout: timeout
|
120
|
-
client_config: client_config
|
121
|
+
host: emulator_host, timeout: timeout
|
121
122
|
)
|
122
123
|
)
|
123
124
|
end
|
@@ -136,7 +137,7 @@ module Google
|
|
136
137
|
Datastore::Dataset.new(
|
137
138
|
Datastore::Service.new(
|
138
139
|
project_id, credentials,
|
139
|
-
host: endpoint, timeout: timeout
|
140
|
+
host: endpoint, timeout: timeout
|
140
141
|
)
|
141
142
|
)
|
142
143
|
end
|
@@ -158,8 +159,6 @@ module Google
|
|
158
159
|
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
159
160
|
# the set of resources and operations that the connection can access.
|
160
161
|
# * `timeout` - (Integer) Default timeout to use in requests.
|
161
|
-
# * `client_config` - (Hash) A hash of values to override the default
|
162
|
-
# behavior of the API client.
|
163
162
|
# * `endpoint` - (String) Override of the endpoint host name, or `nil`
|
164
163
|
# to use the default endpoint.
|
165
164
|
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
@@ -191,4 +190,6 @@ module Google
|
|
191
190
|
end
|
192
191
|
end
|
193
192
|
end
|
193
|
+
## Legacy generated client namespace
|
194
|
+
Datastore = Cloud::Datastore unless const_defined? :Datastore
|
194
195
|
end
|
@@ -136,16 +136,16 @@ module Google
|
|
136
136
|
def mutations
|
137
137
|
mutations = []
|
138
138
|
mutations += @shared_upserts.map do |entity|
|
139
|
-
Google::Datastore::V1::Mutation.new upsert: entity.to_grpc
|
139
|
+
Google::Cloud::Datastore::V1::Mutation.new upsert: entity.to_grpc
|
140
140
|
end
|
141
141
|
mutations += @shared_inserts.map do |entity|
|
142
|
-
Google::Datastore::V1::Mutation.new insert: entity.to_grpc
|
142
|
+
Google::Cloud::Datastore::V1::Mutation.new insert: entity.to_grpc
|
143
143
|
end
|
144
144
|
mutations += @shared_updates.map do |entity|
|
145
|
-
Google::Datastore::V1::Mutation.new update: entity.to_grpc
|
145
|
+
Google::Cloud::Datastore::V1::Mutation.new update: entity.to_grpc
|
146
146
|
end
|
147
147
|
mutations += @shared_deletes.map do |key|
|
148
|
-
Google::Datastore::V1::Mutation.new delete: key.to_grpc
|
148
|
+
Google::Cloud::Datastore::V1::Mutation.new delete: key.to_grpc
|
149
149
|
end
|
150
150
|
mutations
|
151
151
|
end
|
@@ -77,7 +77,7 @@ module Google
|
|
77
77
|
end
|
78
78
|
|
79
79
|
##
|
80
|
-
# Gets an object from a Google::Datastore::V1::Value.
|
80
|
+
# Gets an object from a Google::Cloud::Datastore::V1::Value.
|
81
81
|
def self.from_value grpc_value
|
82
82
|
if grpc_value.value_type == :null_value
|
83
83
|
return nil
|
@@ -110,9 +110,9 @@ module Google
|
|
110
110
|
end
|
111
111
|
|
112
112
|
##
|
113
|
-
# Stores an object into a Google::Datastore::V1::Value.
|
113
|
+
# Stores an object into a Google::Cloud::Datastore::V1::Value.
|
114
114
|
def self.to_value value
|
115
|
-
v = Google::Datastore::V1::Value.new
|
115
|
+
v = Google::Cloud::Datastore::V1::Value.new
|
116
116
|
if NilClass === value
|
117
117
|
v.null_value = :NULL_VALUE
|
118
118
|
elsif TrueClass === value
|
@@ -133,7 +133,7 @@ module Google
|
|
133
133
|
elsif String === value
|
134
134
|
v.string_value = value
|
135
135
|
elsif Array === value
|
136
|
-
v.array_value = Google::Datastore::V1::ArrayValue.new(
|
136
|
+
v.array_value = Google::Cloud::Datastore::V1::ArrayValue.new(
|
137
137
|
values: value.map { |val| to_value val }
|
138
138
|
)
|
139
139
|
elsif value.respond_to? :to_time
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "googleauth"
|
17
|
-
require "google/cloud/datastore/v1/credentials"
|
17
|
+
require "google/cloud/datastore/v1/datastore/credentials"
|
18
18
|
|
19
19
|
module Google
|
20
20
|
module Cloud
|
@@ -38,7 +38,7 @@ module Google
|
|
38
38
|
#
|
39
39
|
# datastore.project_id #=> "my-todo-project"
|
40
40
|
#
|
41
|
-
class Credentials < Google::Cloud::Datastore::V1::Credentials
|
41
|
+
class Credentials < Google::Cloud::Datastore::V1::Datastore::Credentials
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -427,10 +427,10 @@ module Google
|
|
427
427
|
end
|
428
428
|
|
429
429
|
##
|
430
|
-
# @private Convert the Entity to a Google::Datastore::V1::Entity
|
430
|
+
# @private Convert the Entity to a Google::Cloud::Datastore::V1::Entity
|
431
431
|
# object.
|
432
432
|
def to_grpc
|
433
|
-
grpc = Google::Datastore::V1::Entity.new(
|
433
|
+
grpc = Google::Cloud::Datastore::V1::Entity.new(
|
434
434
|
properties: @properties.to_grpc
|
435
435
|
)
|
436
436
|
grpc.key = @key.to_grpc unless @key.nil?
|
@@ -439,7 +439,7 @@ module Google
|
|
439
439
|
end
|
440
440
|
|
441
441
|
##
|
442
|
-
# @private Create a new Entity from a Google::Datastore::V1::Key
|
442
|
+
# @private Create a new Entity from a Google::Cloud::Datastore::V1::Key
|
443
443
|
# object.
|
444
444
|
def self.from_grpc grpc
|
445
445
|
entity = Entity.new
|
@@ -49,7 +49,7 @@ module Google
|
|
49
49
|
# gql_query = Google::Cloud::Datastore::GqlQuery.new
|
50
50
|
#
|
51
51
|
def initialize
|
52
|
-
@grpc = Google::Datastore::V1::GqlQuery.new
|
52
|
+
@grpc = Google::Cloud::Datastore::V1::GqlQuery.new
|
53
53
|
end
|
54
54
|
|
55
55
|
##
|
@@ -159,12 +159,12 @@ module Google
|
|
159
159
|
new_named_bindings.map do |name, value|
|
160
160
|
if value.is_a? Google::Cloud::Datastore::Cursor
|
161
161
|
@grpc.named_bindings[name.to_s] = \
|
162
|
-
Google::Datastore::V1::GqlQueryParameter.new(
|
162
|
+
Google::Cloud::Datastore::V1::GqlQueryParameter.new(
|
163
163
|
cursor: value.to_grpc
|
164
164
|
)
|
165
165
|
else
|
166
166
|
@grpc.named_bindings[name.to_s] = \
|
167
|
-
Google::Datastore::V1::GqlQueryParameter.new(
|
167
|
+
Google::Cloud::Datastore::V1::GqlQueryParameter.new(
|
168
168
|
value: Convert.to_value(value)
|
169
169
|
)
|
170
170
|
end
|
@@ -210,12 +210,12 @@ module Google
|
|
210
210
|
new_positional_bindings.map do |value|
|
211
211
|
if value.is_a? Google::Cloud::Datastore::Cursor
|
212
212
|
@grpc.positional_bindings << \
|
213
|
-
Google::Datastore::V1::GqlQueryParameter.new(
|
213
|
+
Google::Cloud::Datastore::V1::GqlQueryParameter.new(
|
214
214
|
cursor: value.to_grpc
|
215
215
|
)
|
216
216
|
else
|
217
217
|
@grpc.positional_bindings << \
|
218
|
-
Google::Datastore::V1::GqlQueryParameter.new(
|
218
|
+
Google::Cloud::Datastore::V1::GqlQueryParameter.new(
|
219
219
|
value: Convert.to_value(value)
|
220
220
|
)
|
221
221
|
end
|
@@ -268,7 +268,7 @@ module Google
|
|
268
268
|
end
|
269
269
|
|
270
270
|
##
|
271
|
-
# @private Convert the Key to a Google::Datastore::V1::Key object.
|
271
|
+
# @private Convert the Key to a Google::Cloud::Datastore::V1::Key object.
|
272
272
|
def to_grpc
|
273
273
|
grpc_path = path.map do |pe_kind, pe_id_or_name|
|
274
274
|
path_args = { kind: pe_kind }
|
@@ -277,11 +277,11 @@ module Google
|
|
277
277
|
elsif pe_id_or_name.is_a? String
|
278
278
|
path_args[:name] = pe_id_or_name unless pe_id_or_name.empty?
|
279
279
|
end
|
280
|
-
Google::Datastore::V1::Key::PathElement.new path_args
|
280
|
+
Google::Cloud::Datastore::V1::Key::PathElement.new path_args
|
281
281
|
end
|
282
|
-
grpc = Google::Datastore::V1::Key.new path: grpc_path
|
282
|
+
grpc = Google::Cloud::Datastore::V1::Key.new path: grpc_path
|
283
283
|
if project || namespace
|
284
|
-
grpc.partition_id = Google::Datastore::V1::PartitionId.new(
|
284
|
+
grpc.partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
|
285
285
|
project_id: project.to_s, namespace_id: namespace.to_s
|
286
286
|
)
|
287
287
|
end
|
@@ -289,7 +289,7 @@ module Google
|
|
289
289
|
end
|
290
290
|
|
291
291
|
##
|
292
|
-
# @private Create a new Key from a Google::Datastore::V1::Key
|
292
|
+
# @private Create a new Key from a Google::Cloud::Datastore::V1::Key
|
293
293
|
# object.
|
294
294
|
def self.from_grpc grpc
|
295
295
|
return nil if grpc.nil?
|
@@ -61,7 +61,7 @@ module Google
|
|
61
61
|
# query = Google::Cloud::Datastore::Query.new
|
62
62
|
#
|
63
63
|
def initialize
|
64
|
-
@grpc = Google::Datastore::V1::Query.new
|
64
|
+
@grpc = Google::Cloud::Datastore::V1::Query.new
|
65
65
|
end
|
66
66
|
|
67
67
|
##
|
@@ -83,7 +83,7 @@ module Google
|
|
83
83
|
#
|
84
84
|
def kind *kinds
|
85
85
|
kinds.each do |kind|
|
86
|
-
grpc_kind = Google::Datastore::V1::KindExpression.new(
|
86
|
+
grpc_kind = Google::Cloud::Datastore::V1::KindExpression.new(
|
87
87
|
name: kind
|
88
88
|
)
|
89
89
|
@grpc.kind << grpc_kind
|
@@ -177,15 +177,15 @@ module Google
|
|
177
177
|
# tasks = datastore.run query
|
178
178
|
#
|
179
179
|
def where name, operator, value
|
180
|
-
@grpc.filter ||= Google::Datastore::V1::Filter.new(
|
181
|
-
composite_filter: Google::Datastore::V1::CompositeFilter.new(
|
180
|
+
@grpc.filter ||= Google::Cloud::Datastore::V1::Filter.new(
|
181
|
+
composite_filter: Google::Cloud::Datastore::V1::CompositeFilter.new(
|
182
182
|
op: :AND
|
183
183
|
)
|
184
184
|
)
|
185
185
|
@grpc.filter.composite_filter.filters << \
|
186
|
-
Google::Datastore::V1::Filter.new(
|
187
|
-
property_filter: Google::Datastore::V1::PropertyFilter.new(
|
188
|
-
property: Google::Datastore::V1::PropertyReference.new(
|
186
|
+
Google::Cloud::Datastore::V1::Filter.new(
|
187
|
+
property_filter: Google::Cloud::Datastore::V1::PropertyFilter.new(
|
188
|
+
property: Google::Cloud::Datastore::V1::PropertyReference.new(
|
189
189
|
name: name
|
190
190
|
),
|
191
191
|
op: Convert.to_prop_filter_op(operator),
|
@@ -273,8 +273,8 @@ module Google
|
|
273
273
|
# tasks = datastore.run query
|
274
274
|
#
|
275
275
|
def order name, direction = :asc
|
276
|
-
@grpc.order << Google::Datastore::V1::PropertyOrder.new(
|
277
|
-
property: Google::Datastore::V1::PropertyReference.new(
|
276
|
+
@grpc.order << Google::Cloud::Datastore::V1::PropertyOrder.new(
|
277
|
+
property: Google::Cloud::Datastore::V1::PropertyReference.new(
|
278
278
|
name: name
|
279
279
|
),
|
280
280
|
direction: prop_order_direction(direction)
|
@@ -384,8 +384,8 @@ module Google
|
|
384
384
|
#
|
385
385
|
def select *names
|
386
386
|
names.each do |name|
|
387
|
-
grpc_projection = Google::Datastore::V1::Projection.new(
|
388
|
-
property: Google::Datastore::V1::PropertyReference.new(
|
387
|
+
grpc_projection = Google::Cloud::Datastore::V1::Projection.new(
|
388
|
+
property: Google::Cloud::Datastore::V1::PropertyReference.new(
|
389
389
|
name: name
|
390
390
|
)
|
391
391
|
)
|
@@ -414,7 +414,7 @@ module Google
|
|
414
414
|
#
|
415
415
|
def group_by *names
|
416
416
|
names.each do |name|
|
417
|
-
grpc_property = Google::Datastore::V1::PropertyReference.new(
|
417
|
+
grpc_property = Google::Cloud::Datastore::V1::PropertyReference.new(
|
418
418
|
name: name
|
419
419
|
)
|
420
420
|
@grpc.distinct_on << grpc_property
|
@@ -17,7 +17,6 @@ require "google/cloud/errors"
|
|
17
17
|
require "google/cloud/datastore/credentials"
|
18
18
|
require "google/cloud/datastore/version"
|
19
19
|
require "google/cloud/datastore/v1"
|
20
|
-
require "google/gax/errors"
|
21
20
|
|
22
21
|
module Google
|
23
22
|
module Cloud
|
@@ -26,59 +25,35 @@ module Google
|
|
26
25
|
# @private Represents the GAX Datastore service, including all the API
|
27
26
|
# methods.
|
28
27
|
class Service
|
29
|
-
attr_accessor :project, :credentials, :host, :timeout
|
28
|
+
attr_accessor :project, :credentials, :host, :timeout
|
30
29
|
|
31
30
|
##
|
32
31
|
# Creates a new Service instance.
|
33
|
-
def initialize project, credentials, host: nil, timeout: nil
|
34
|
-
client_config: nil
|
32
|
+
def initialize project, credentials, host: nil, timeout: nil
|
35
33
|
@project = project
|
36
34
|
@credentials = credentials
|
37
|
-
@host = host
|
35
|
+
@host = host
|
38
36
|
@timeout = timeout
|
39
|
-
@client_config = client_config || {}
|
40
|
-
end
|
41
|
-
|
42
|
-
def channel
|
43
|
-
require "grpc"
|
44
|
-
GRPC::Core::Channel.new host, chan_args, chan_creds
|
45
|
-
end
|
46
|
-
|
47
|
-
def chan_args
|
48
|
-
{ "grpc.service_config_disable_resolution" => 1 }
|
49
|
-
end
|
50
|
-
|
51
|
-
def chan_creds
|
52
|
-
return credentials if insecure?
|
53
|
-
require "grpc"
|
54
|
-
GRPC::Core::ChannelCredentials.new.compose \
|
55
|
-
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
56
37
|
end
|
57
38
|
|
58
39
|
def service
|
59
40
|
return mocked_service if mocked_service
|
60
|
-
@service ||= V1::
|
61
|
-
credentials
|
62
|
-
timeout
|
63
|
-
|
64
|
-
lib_name
|
65
|
-
lib_version
|
66
|
-
|
41
|
+
@service ||= V1::Datastore::Client.new do |config|
|
42
|
+
config.credentials = credentials if credentials
|
43
|
+
config.timeout = timeout if timeout
|
44
|
+
config.endpoint = host if host
|
45
|
+
config.lib_name = "gccl"
|
46
|
+
config.lib_version = Google::Cloud::Datastore::VERSION
|
47
|
+
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
48
|
+
end
|
67
49
|
end
|
68
50
|
attr_accessor :mocked_service
|
69
51
|
|
70
|
-
def insecure?
|
71
|
-
credentials == :this_channel_is_insecure
|
72
|
-
end
|
73
|
-
|
74
52
|
##
|
75
53
|
# Allocate IDs for incomplete keys.
|
76
54
|
# (This is useful for referencing an entity before it is inserted.)
|
77
55
|
def allocate_ids *incomplete_keys
|
78
|
-
|
79
|
-
service.allocate_ids project, incomplete_keys,
|
80
|
-
options: default_options
|
81
|
-
end
|
56
|
+
service.allocate_ids project_id: project, keys: incomplete_keys
|
82
57
|
end
|
83
58
|
|
84
59
|
##
|
@@ -86,76 +61,61 @@ module Google
|
|
86
61
|
def lookup *keys, consistency: nil, transaction: nil
|
87
62
|
read_options = generate_read_options consistency, transaction
|
88
63
|
|
89
|
-
|
90
|
-
service.lookup project, keys,
|
91
|
-
read_options: read_options, options: default_options
|
92
|
-
end
|
64
|
+
service.lookup project_id: project, keys: keys, read_options: read_options
|
93
65
|
end
|
94
66
|
|
95
67
|
# Query for entities.
|
96
68
|
def run_query query, namespace = nil, consistency: nil, transaction: nil
|
97
69
|
gql_query = nil
|
98
|
-
if query.is_a? Google::Datastore::V1::GqlQuery
|
70
|
+
if query.is_a? Google::Cloud::Datastore::V1::GqlQuery
|
99
71
|
gql_query = query
|
100
72
|
query = nil
|
101
73
|
end
|
102
74
|
read_options = generate_read_options consistency, transaction
|
103
75
|
if namespace
|
104
|
-
partition_id = Google::Datastore::V1::PartitionId.new(
|
76
|
+
partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
|
105
77
|
namespace_id: namespace
|
106
78
|
)
|
107
79
|
end
|
108
80
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
options: default_options
|
115
|
-
end
|
81
|
+
service.run_query project_id: project,
|
82
|
+
partition_id: partition_id,
|
83
|
+
read_options: read_options,
|
84
|
+
query: query,
|
85
|
+
gql_query: gql_query
|
116
86
|
end
|
117
87
|
|
118
88
|
##
|
119
89
|
# Begin a new transaction.
|
120
90
|
def begin_transaction read_only: nil, previous_transaction: nil
|
121
91
|
if read_only
|
122
|
-
transaction_options = Google::Datastore::V1::TransactionOptions.new
|
92
|
+
transaction_options = Google::Cloud::Datastore::V1::TransactionOptions.new
|
123
93
|
transaction_options.read_only = \
|
124
|
-
Google::Datastore::V1::TransactionOptions::ReadOnly.new
|
94
|
+
Google::Cloud::Datastore::V1::TransactionOptions::ReadOnly.new
|
125
95
|
end
|
126
96
|
if previous_transaction
|
127
97
|
transaction_options ||= \
|
128
|
-
Google::Datastore::V1::TransactionOptions.new
|
129
|
-
rw = Google::Datastore::V1::TransactionOptions::ReadWrite.new(
|
98
|
+
Google::Cloud::Datastore::V1::TransactionOptions.new
|
99
|
+
rw = Google::Cloud::Datastore::V1::TransactionOptions::ReadWrite.new(
|
130
100
|
previous_transaction: previous_transaction.encode("ASCII-8BIT")
|
131
101
|
)
|
132
102
|
transaction_options.read_write = rw
|
133
103
|
end
|
134
|
-
|
135
|
-
service.begin_transaction project,
|
136
|
-
transaction_options: transaction_options
|
137
|
-
end
|
104
|
+
service.begin_transaction project_id: project, transaction_options: transaction_options
|
138
105
|
end
|
139
106
|
|
140
107
|
##
|
141
108
|
# Commit a transaction, optionally creating, deleting or modifying
|
142
109
|
# some entities.
|
143
110
|
def commit mutations, transaction: nil
|
144
|
-
mode =
|
145
|
-
|
146
|
-
service.commit project, mode: mode,
|
147
|
-
mutations: mutations,
|
148
|
-
transaction: transaction,
|
149
|
-
options: default_options
|
150
|
-
end
|
111
|
+
mode = transaction.nil? ? :NON_TRANSACTIONAL : :TRANSACTIONAL
|
112
|
+
service.commit project_id: project, mode: mode, mutations: mutations, transaction: transaction
|
151
113
|
end
|
152
114
|
|
153
115
|
##
|
154
116
|
# Roll back a transaction.
|
155
117
|
def rollback transaction
|
156
|
-
|
157
|
-
service.rollback project, transaction, options: default_options
|
158
|
-
end
|
118
|
+
service.rollback project_id: project, transaction: transaction
|
159
119
|
end
|
160
120
|
|
161
121
|
def inspect
|
@@ -166,35 +126,20 @@ module Google
|
|
166
126
|
|
167
127
|
def generate_read_options consistency, transaction
|
168
128
|
if consistency == :eventual
|
169
|
-
return Google::Datastore::V1::ReadOptions.new(
|
129
|
+
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
170
130
|
read_consistency: :EVENTUAL
|
171
131
|
)
|
172
132
|
elsif consistency == :strong
|
173
|
-
return Google::Datastore::V1::ReadOptions.new(
|
133
|
+
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
174
134
|
read_consistency: :STRONG
|
175
135
|
)
|
176
136
|
elsif transaction
|
177
|
-
return Google::Datastore::V1::ReadOptions.new(
|
137
|
+
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
178
138
|
transaction: transaction
|
179
139
|
)
|
180
140
|
end
|
181
141
|
nil
|
182
142
|
end
|
183
|
-
|
184
|
-
def default_headers
|
185
|
-
{ "google-cloud-resource-prefix" => "projects/#{@project}" }
|
186
|
-
end
|
187
|
-
|
188
|
-
def default_options
|
189
|
-
Google::Gax::CallOptions.new kwargs: default_headers
|
190
|
-
end
|
191
|
-
|
192
|
-
def execute
|
193
|
-
yield
|
194
|
-
rescue Google::Gax::GaxError => e
|
195
|
-
# GaxError wraps BadStatus, but exposes it as #cause
|
196
|
-
raise Google::Cloud::Error.from_error(e.cause)
|
197
|
-
end
|
198
143
|
end
|
199
144
|
end
|
200
145
|
end
|