google-cloud-datastore 1.7.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +2 -1
  3. data/CHANGELOG.md +47 -0
  4. data/TROUBLESHOOTING.md +2 -8
  5. data/lib/google-cloud-datastore.rb +12 -18
  6. data/lib/google/cloud/datastore.rb +12 -11
  7. data/lib/google/cloud/datastore/commit.rb +4 -4
  8. data/lib/google/cloud/datastore/convert.rb +4 -4
  9. data/lib/google/cloud/datastore/credentials.rb +2 -2
  10. data/lib/google/cloud/datastore/entity.rb +3 -3
  11. data/lib/google/cloud/datastore/gql_query.rb +5 -5
  12. data/lib/google/cloud/datastore/key.rb +5 -5
  13. data/lib/google/cloud/datastore/properties.rb +1 -1
  14. data/lib/google/cloud/datastore/query.rb +12 -12
  15. data/lib/google/cloud/datastore/service.rb +31 -86
  16. data/lib/google/cloud/datastore/version.rb +1 -1
  17. metadata +10 -65
  18. data/lib/google/cloud/datastore/v1.rb +0 -16
  19. data/lib/google/cloud/datastore/v1/credentials.rb +0 -39
  20. data/lib/google/cloud/datastore/v1/datastore_client.rb +0 -574
  21. data/lib/google/cloud/datastore/v1/datastore_client_config.json +0 -61
  22. data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/datastore.rb +0 -283
  23. data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/entity.rb +0 -189
  24. data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/query.rb +0 -297
  25. data/lib/google/cloud/datastore/v1/doc/google/protobuf/struct.rb +0 -74
  26. data/lib/google/cloud/datastore/v1/doc/google/protobuf/timestamp.rb +0 -109
  27. data/lib/google/cloud/datastore/v1/doc/google/protobuf/wrappers.rb +0 -26
  28. data/lib/google/cloud/datastore/v1/doc/google/type/latlng.rb +0 -65
  29. data/lib/google/datastore/v1/datastore_pb.rb +0 -147
  30. data/lib/google/datastore/v1/datastore_services_pb.rb +0 -65
  31. data/lib/google/datastore/v1/entity_pb.rb +0 -64
  32. data/lib/google/datastore/v1/query_pb.rb +0 -132
@@ -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, :client_config
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 || V1::DatastoreClient::SERVICE_ADDRESS
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::DatastoreClient.new(
61
- credentials: channel,
62
- timeout: timeout,
63
- client_config: client_config,
64
- lib_name: "gccl",
65
- lib_version: Google::Cloud::Datastore::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
- execute do
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
- execute do
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
- execute do
110
- service.run_query project, partition_id: partition_id,
111
- read_options: read_options,
112
- query: query,
113
- gql_query: gql_query,
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
- execute do
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 = transaction.nil? ? :NON_TRANSACTIONAL : :TRANSACTIONAL
145
- execute do
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
- execute do
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
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Datastore
19
- VERSION = "1.7.2".freeze
19
+ VERSION = "2.0.0".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: 1.7.2
4
+ version: 2.0.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: 2019-12-12 00:00:00.000000000 Z
12
+ date: 2020-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,68 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.2'
20
+ version: '1.5'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.2'
27
+ version: '1.5'
28
28
  - !ruby/object:Gem::Dependency
29
- name: google-gax
29
+ name: google-cloud-datastore-v1
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.8'
34
+ version: '0.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.8'
42
- - !ruby/object:Gem::Dependency
43
- name: googleapis-common-protos
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 1.3.9
49
- - - "<"
50
- - !ruby/object:Gem::Version
51
- version: '2.0'
52
- type: :runtime
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: 1.3.9
59
- - - "<"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- - !ruby/object:Gem::Dependency
63
- name: googleapis-common-protos-types
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 1.0.4
69
- - - "<"
70
- - !ruby/object:Gem::Version
71
- version: '2.0'
72
- type: :runtime
73
- prerelease: false
74
- version_requirements: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 1.0.4
79
- - - "<"
80
- - !ruby/object:Gem::Version
81
- version: '2.0'
41
+ version: '0.0'
82
42
  - !ruby/object:Gem::Dependency
83
43
  name: google-style
84
44
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +59,14 @@ dependencies:
99
59
  requirements:
100
60
  - - "~>"
101
61
  - !ruby/object:Gem::Version
102
- version: '5.10'
62
+ version: '5.14'
103
63
  type: :development
104
64
  prerelease: false
105
65
  version_requirements: !ruby/object:Gem::Requirement
106
66
  requirements:
107
67
  - - "~>"
108
68
  - !ruby/object:Gem::Version
109
- version: '5.10'
69
+ version: '5.14'
110
70
  - !ruby/object:Gem::Dependency
111
71
  name: minitest-autotest
112
72
  requirement: !ruby/object:Gem::Requirement
@@ -255,22 +215,7 @@ files:
255
215
  - lib/google/cloud/datastore/read_only_transaction.rb
256
216
  - lib/google/cloud/datastore/service.rb
257
217
  - lib/google/cloud/datastore/transaction.rb
258
- - lib/google/cloud/datastore/v1.rb
259
- - lib/google/cloud/datastore/v1/credentials.rb
260
- - lib/google/cloud/datastore/v1/datastore_client.rb
261
- - lib/google/cloud/datastore/v1/datastore_client_config.json
262
- - lib/google/cloud/datastore/v1/doc/google/datastore/v1/datastore.rb
263
- - lib/google/cloud/datastore/v1/doc/google/datastore/v1/entity.rb
264
- - lib/google/cloud/datastore/v1/doc/google/datastore/v1/query.rb
265
- - lib/google/cloud/datastore/v1/doc/google/protobuf/struct.rb
266
- - lib/google/cloud/datastore/v1/doc/google/protobuf/timestamp.rb
267
- - lib/google/cloud/datastore/v1/doc/google/protobuf/wrappers.rb
268
- - lib/google/cloud/datastore/v1/doc/google/type/latlng.rb
269
218
  - lib/google/cloud/datastore/version.rb
270
- - lib/google/datastore/v1/datastore_pb.rb
271
- - lib/google/datastore/v1/datastore_services_pb.rb
272
- - lib/google/datastore/v1/entity_pb.rb
273
- - lib/google/datastore/v1/query_pb.rb
274
219
  homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-datastore
275
220
  licenses:
276
221
  - Apache-2.0
@@ -290,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
235
  - !ruby/object:Gem::Version
291
236
  version: '0'
292
237
  requirements: []
293
- rubygems_version: 3.0.6
238
+ rubygems_version: 3.1.3
294
239
  signing_key:
295
240
  specification_version: 4
296
241
  summary: API Client library for Google Cloud Datastore
@@ -1,16 +0,0 @@
1
- # Copyright 2016 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
-
16
- require "google/cloud/datastore/v1/datastore_client"
@@ -1,39 +0,0 @@
1
- # Copyright 2019 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
-
16
- require "googleauth"
17
-
18
- module Google
19
- module Cloud
20
- module Datastore
21
- module V1
22
- class Credentials < Google::Auth::Credentials
23
- SCOPE = ["https://www.googleapis.com/auth/datastore"].freeze
24
- PATH_ENV_VARS = %w(DATASTORE_CREDENTIALS
25
- DATASTORE_KEYFILE
26
- GOOGLE_CLOUD_CREDENTIALS
27
- GOOGLE_CLOUD_KEYFILE
28
- GCLOUD_KEYFILE)
29
- JSON_ENV_VARS = %w(DATASTORE_CREDENTIALS_JSON
30
- DATASTORE_KEYFILE_JSON
31
- GOOGLE_CLOUD_CREDENTIALS_JSON
32
- GOOGLE_CLOUD_KEYFILE_JSON
33
- GCLOUD_KEYFILE_JSON)
34
- DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,574 +0,0 @@
1
- # Copyright 2019 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
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/datastore/v1/datastore.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/datastore/v1/datastore_pb"
29
- require "google/cloud/datastore/v1/credentials"
30
- require "google/cloud/datastore/version"
31
-
32
- module Google
33
- module Cloud
34
- module Datastore
35
- module V1
36
- # Each RPC normalizes the partition IDs of the keys in its input entities,
37
- # and always returns entities with keys with normalized partition IDs.
38
- # This applies to all keys and entities, including those in values, except keys
39
- # with both an empty path and an empty or unset partition ID. Normalization of
40
- # input keys sets the project ID (if not already set) to the project ID from
41
- # the request.
42
- #
43
- # @!attribute [r] datastore_stub
44
- # @return [Google::Datastore::V1::Datastore::Stub]
45
- class DatastoreClient
46
- # @private
47
- attr_reader :datastore_stub
48
-
49
- # The default address of the service.
50
- SERVICE_ADDRESS = "datastore.googleapis.com".freeze
51
-
52
- # The default port of the service.
53
- DEFAULT_SERVICE_PORT = 443
54
-
55
- # The default set of gRPC interceptors.
56
- GRPC_INTERCEPTORS = []
57
-
58
- DEFAULT_TIMEOUT = 30
59
-
60
- # The scopes needed to make gRPC calls to all of the methods defined in
61
- # this service.
62
- ALL_SCOPES = [
63
- "https://www.googleapis.com/auth/cloud-platform",
64
- "https://www.googleapis.com/auth/datastore"
65
- ].freeze
66
-
67
-
68
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
69
- # Provides the means for authenticating requests made by the client. This parameter can
70
- # be many types.
71
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
72
- # authenticating requests made by this client.
73
- # A `String` will be treated as the path to the keyfile to be used for the construction of
74
- # credentials for this client.
75
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
76
- # credentials for this client.
77
- # A `GRPC::Core::Channel` will be used to make calls through.
78
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
79
- # should already be composed with a `GRPC::Core::CallCredentials` object.
80
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
81
- # metadata for requests, generally, to give OAuth credentials.
82
- # @param scopes [Array<String>]
83
- # The OAuth scopes for this service. This parameter is ignored if
84
- # an updater_proc is supplied.
85
- # @param client_config [Hash]
86
- # A Hash for call options for each method. See
87
- # Google::Gax#construct_settings for the structure of
88
- # this data. Falls back to the default config if not specified
89
- # or the specified config is missing data points.
90
- # @param timeout [Numeric]
91
- # The default timeout, in seconds, for calls made through this client.
92
- # @param metadata [Hash]
93
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
94
- # @param service_address [String]
95
- # Override for the service hostname, or `nil` to leave as the default.
96
- # @param service_port [Integer]
97
- # Override for the service port, or `nil` to leave as the default.
98
- # @param exception_transformer [Proc]
99
- # An optional proc that intercepts any exceptions raised during an API call to inject
100
- # custom error handling.
101
- def initialize \
102
- credentials: nil,
103
- scopes: ALL_SCOPES,
104
- client_config: {},
105
- timeout: DEFAULT_TIMEOUT,
106
- metadata: nil,
107
- service_address: nil,
108
- service_port: nil,
109
- exception_transformer: nil,
110
- lib_name: nil,
111
- lib_version: ""
112
- # These require statements are intentionally placed here to initialize
113
- # the gRPC module only when it's required.
114
- # See https://github.com/googleapis/toolkit/issues/446
115
- require "google/gax/grpc"
116
- require "google/datastore/v1/datastore_services_pb"
117
-
118
- credentials ||= Google::Cloud::Datastore::V1::Credentials.default
119
-
120
- if credentials.is_a?(String) || credentials.is_a?(Hash)
121
- updater_proc = Google::Cloud::Datastore::V1::Credentials.new(credentials).updater_proc
122
- end
123
- if credentials.is_a?(GRPC::Core::Channel)
124
- channel = credentials
125
- end
126
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
127
- chan_creds = credentials
128
- end
129
- if credentials.is_a?(Proc)
130
- updater_proc = credentials
131
- end
132
- if credentials.is_a?(Google::Auth::Credentials)
133
- updater_proc = credentials.updater_proc
134
- end
135
-
136
- package_version = Google::Cloud::Datastore::VERSION
137
-
138
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
139
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
140
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
141
- google_api_client << " grpc/#{GRPC::VERSION}"
142
- google_api_client.freeze
143
-
144
- headers = { :"x-goog-api-client" => google_api_client }
145
- headers.merge!(metadata) unless metadata.nil?
146
- client_config_file = Pathname.new(__dir__).join(
147
- "datastore_client_config.json"
148
- )
149
- defaults = client_config_file.open do |f|
150
- Google::Gax.construct_settings(
151
- "google.datastore.v1.Datastore",
152
- JSON.parse(f.read),
153
- client_config,
154
- Google::Gax::Grpc::STATUS_CODE_NAMES,
155
- timeout,
156
- errors: Google::Gax::Grpc::API_ERRORS,
157
- metadata: headers
158
- )
159
- end
160
-
161
- # Allow overriding the service path/port in subclasses.
162
- service_path = service_address || self.class::SERVICE_ADDRESS
163
- port = service_port || self.class::DEFAULT_SERVICE_PORT
164
- interceptors = self.class::GRPC_INTERCEPTORS
165
- @datastore_stub = Google::Gax::Grpc.create_stub(
166
- service_path,
167
- port,
168
- chan_creds: chan_creds,
169
- channel: channel,
170
- updater_proc: updater_proc,
171
- scopes: scopes,
172
- interceptors: interceptors,
173
- &Google::Datastore::V1::Datastore::Stub.method(:new)
174
- )
175
-
176
- @lookup = Google::Gax.create_api_call(
177
- @datastore_stub.method(:lookup),
178
- defaults["lookup"],
179
- exception_transformer: exception_transformer,
180
- params_extractor: proc do |request|
181
- {'project_id' => request.project_id}
182
- end
183
- )
184
- @run_query = Google::Gax.create_api_call(
185
- @datastore_stub.method(:run_query),
186
- defaults["run_query"],
187
- exception_transformer: exception_transformer,
188
- params_extractor: proc do |request|
189
- {'project_id' => request.project_id}
190
- end
191
- )
192
- @begin_transaction = Google::Gax.create_api_call(
193
- @datastore_stub.method(:begin_transaction),
194
- defaults["begin_transaction"],
195
- exception_transformer: exception_transformer,
196
- params_extractor: proc do |request|
197
- {'project_id' => request.project_id}
198
- end
199
- )
200
- @commit = Google::Gax.create_api_call(
201
- @datastore_stub.method(:commit),
202
- defaults["commit"],
203
- exception_transformer: exception_transformer,
204
- params_extractor: proc do |request|
205
- {'project_id' => request.project_id}
206
- end
207
- )
208
- @rollback = Google::Gax.create_api_call(
209
- @datastore_stub.method(:rollback),
210
- defaults["rollback"],
211
- exception_transformer: exception_transformer,
212
- params_extractor: proc do |request|
213
- {'project_id' => request.project_id}
214
- end
215
- )
216
- @allocate_ids = Google::Gax.create_api_call(
217
- @datastore_stub.method(:allocate_ids),
218
- defaults["allocate_ids"],
219
- exception_transformer: exception_transformer,
220
- params_extractor: proc do |request|
221
- {'project_id' => request.project_id}
222
- end
223
- )
224
- @reserve_ids = Google::Gax.create_api_call(
225
- @datastore_stub.method(:reserve_ids),
226
- defaults["reserve_ids"],
227
- exception_transformer: exception_transformer,
228
- params_extractor: proc do |request|
229
- {'project_id' => request.project_id}
230
- end
231
- )
232
- end
233
-
234
- # Service calls
235
-
236
- # Looks up entities by key.
237
- #
238
- # @param project_id [String]
239
- # Required. The ID of the project against which to make the request.
240
- # @param keys [Array<Google::Datastore::V1::Key | Hash>]
241
- # Required. Keys of entities to look up.
242
- # A hash of the same form as `Google::Datastore::V1::Key`
243
- # can also be provided.
244
- # @param read_options [Google::Datastore::V1::ReadOptions | Hash]
245
- # The options for this lookup request.
246
- # A hash of the same form as `Google::Datastore::V1::ReadOptions`
247
- # can also be provided.
248
- # @param options [Google::Gax::CallOptions]
249
- # Overrides the default settings for this call, e.g, timeout,
250
- # retries, etc.
251
- # @yield [result, operation] Access the result along with the RPC operation
252
- # @yieldparam result [Google::Datastore::V1::LookupResponse]
253
- # @yieldparam operation [GRPC::ActiveCall::Operation]
254
- # @return [Google::Datastore::V1::LookupResponse]
255
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
256
- # @example
257
- # require "google/cloud/datastore"
258
- #
259
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
260
- #
261
- # # TODO: Initialize `project_id`:
262
- # project_id = ''
263
- #
264
- # # TODO: Initialize `keys`:
265
- # keys = []
266
- # response = datastore_client.lookup(project_id, keys)
267
-
268
- def lookup \
269
- project_id,
270
- keys,
271
- read_options: nil,
272
- options: nil,
273
- &block
274
- req = {
275
- project_id: project_id,
276
- keys: keys,
277
- read_options: read_options
278
- }.delete_if { |_, v| v.nil? }
279
- req = Google::Gax::to_proto(req, Google::Datastore::V1::LookupRequest)
280
- @lookup.call(req, options, &block)
281
- end
282
-
283
- # Queries for entities.
284
- #
285
- # @param project_id [String]
286
- # Required. The ID of the project against which to make the request.
287
- # @param partition_id [Google::Datastore::V1::PartitionId | Hash]
288
- # Entities are partitioned into subsets, identified by a partition ID.
289
- # Queries are scoped to a single partition.
290
- # This partition ID is normalized with the standard default context
291
- # partition ID.
292
- # A hash of the same form as `Google::Datastore::V1::PartitionId`
293
- # can also be provided.
294
- # @param read_options [Google::Datastore::V1::ReadOptions | Hash]
295
- # The options for this query.
296
- # A hash of the same form as `Google::Datastore::V1::ReadOptions`
297
- # can also be provided.
298
- # @param query [Google::Datastore::V1::Query | Hash]
299
- # The query to run.
300
- # A hash of the same form as `Google::Datastore::V1::Query`
301
- # can also be provided.
302
- # @param gql_query [Google::Datastore::V1::GqlQuery | Hash]
303
- # The GQL query to run.
304
- # A hash of the same form as `Google::Datastore::V1::GqlQuery`
305
- # can also be provided.
306
- # @param options [Google::Gax::CallOptions]
307
- # Overrides the default settings for this call, e.g, timeout,
308
- # retries, etc.
309
- # @yield [result, operation] Access the result along with the RPC operation
310
- # @yieldparam result [Google::Datastore::V1::RunQueryResponse]
311
- # @yieldparam operation [GRPC::ActiveCall::Operation]
312
- # @return [Google::Datastore::V1::RunQueryResponse]
313
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
314
- # @example
315
- # require "google/cloud/datastore"
316
- #
317
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
318
- #
319
- # # TODO: Initialize `project_id`:
320
- # project_id = ''
321
- # response = datastore_client.run_query(project_id)
322
-
323
- def run_query \
324
- project_id,
325
- partition_id: nil,
326
- read_options: nil,
327
- query: nil,
328
- gql_query: nil,
329
- options: nil,
330
- &block
331
- req = {
332
- project_id: project_id,
333
- partition_id: partition_id,
334
- read_options: read_options,
335
- query: query,
336
- gql_query: gql_query
337
- }.delete_if { |_, v| v.nil? }
338
- req = Google::Gax::to_proto(req, Google::Datastore::V1::RunQueryRequest)
339
- @run_query.call(req, options, &block)
340
- end
341
-
342
- # Begins a new transaction.
343
- #
344
- # @param project_id [String]
345
- # Required. The ID of the project against which to make the request.
346
- # @param transaction_options [Google::Datastore::V1::TransactionOptions | Hash]
347
- # Options for a new transaction.
348
- # A hash of the same form as `Google::Datastore::V1::TransactionOptions`
349
- # can also be provided.
350
- # @param options [Google::Gax::CallOptions]
351
- # Overrides the default settings for this call, e.g, timeout,
352
- # retries, etc.
353
- # @yield [result, operation] Access the result along with the RPC operation
354
- # @yieldparam result [Google::Datastore::V1::BeginTransactionResponse]
355
- # @yieldparam operation [GRPC::ActiveCall::Operation]
356
- # @return [Google::Datastore::V1::BeginTransactionResponse]
357
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
358
- # @example
359
- # require "google/cloud/datastore"
360
- #
361
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
362
- #
363
- # # TODO: Initialize `project_id`:
364
- # project_id = ''
365
- # response = datastore_client.begin_transaction(project_id)
366
-
367
- def begin_transaction \
368
- project_id,
369
- transaction_options: nil,
370
- options: nil,
371
- &block
372
- req = {
373
- project_id: project_id,
374
- transaction_options: transaction_options
375
- }.delete_if { |_, v| v.nil? }
376
- req = Google::Gax::to_proto(req, Google::Datastore::V1::BeginTransactionRequest)
377
- @begin_transaction.call(req, options, &block)
378
- end
379
-
380
- # Commits a transaction, optionally creating, deleting or modifying some
381
- # entities.
382
- #
383
- # @param project_id [String]
384
- # Required. The ID of the project against which to make the request.
385
- # @param mode [Google::Datastore::V1::CommitRequest::Mode]
386
- # The type of commit to perform. Defaults to `TRANSACTIONAL`.
387
- # @param transaction [String]
388
- # The identifier of the transaction associated with the commit. A
389
- # transaction identifier is returned by a call to
390
- # {Google::Datastore::V1::Datastore::BeginTransaction Datastore::BeginTransaction}.
391
- # @param mutations [Array<Google::Datastore::V1::Mutation | Hash>]
392
- # The mutations to perform.
393
- #
394
- # When mode is `TRANSACTIONAL`, mutations affecting a single entity are
395
- # applied in order. The following sequences of mutations affecting a single
396
- # entity are not permitted in a single `Commit` request:
397
- #
398
- # * `insert` followed by `insert`
399
- # * `update` followed by `insert`
400
- # * `upsert` followed by `insert`
401
- # * `delete` followed by `update`
402
- #
403
- # When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single
404
- # entity.
405
- # A hash of the same form as `Google::Datastore::V1::Mutation`
406
- # can also be provided.
407
- # @param options [Google::Gax::CallOptions]
408
- # Overrides the default settings for this call, e.g, timeout,
409
- # retries, etc.
410
- # @yield [result, operation] Access the result along with the RPC operation
411
- # @yieldparam result [Google::Datastore::V1::CommitResponse]
412
- # @yieldparam operation [GRPC::ActiveCall::Operation]
413
- # @return [Google::Datastore::V1::CommitResponse]
414
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
415
- # @example
416
- # require "google/cloud/datastore"
417
- #
418
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
419
- #
420
- # # TODO: Initialize `project_id`:
421
- # project_id = ''
422
- # response = datastore_client.commit(project_id)
423
-
424
- def commit \
425
- project_id,
426
- mode: nil,
427
- transaction: nil,
428
- mutations: nil,
429
- options: nil,
430
- &block
431
- req = {
432
- project_id: project_id,
433
- mode: mode,
434
- transaction: transaction,
435
- mutations: mutations
436
- }.delete_if { |_, v| v.nil? }
437
- req = Google::Gax::to_proto(req, Google::Datastore::V1::CommitRequest)
438
- @commit.call(req, options, &block)
439
- end
440
-
441
- # Rolls back a transaction.
442
- #
443
- # @param project_id [String]
444
- # Required. The ID of the project against which to make the request.
445
- # @param transaction [String]
446
- # Required. The transaction identifier, returned by a call to
447
- # {Google::Datastore::V1::Datastore::BeginTransaction Datastore::BeginTransaction}.
448
- # @param options [Google::Gax::CallOptions]
449
- # Overrides the default settings for this call, e.g, timeout,
450
- # retries, etc.
451
- # @yield [result, operation] Access the result along with the RPC operation
452
- # @yieldparam result [Google::Datastore::V1::RollbackResponse]
453
- # @yieldparam operation [GRPC::ActiveCall::Operation]
454
- # @return [Google::Datastore::V1::RollbackResponse]
455
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
456
- # @example
457
- # require "google/cloud/datastore"
458
- #
459
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
460
- #
461
- # # TODO: Initialize `project_id`:
462
- # project_id = ''
463
- #
464
- # # TODO: Initialize `transaction`:
465
- # transaction = ''
466
- # response = datastore_client.rollback(project_id, transaction)
467
-
468
- def rollback \
469
- project_id,
470
- transaction,
471
- options: nil,
472
- &block
473
- req = {
474
- project_id: project_id,
475
- transaction: transaction
476
- }.delete_if { |_, v| v.nil? }
477
- req = Google::Gax::to_proto(req, Google::Datastore::V1::RollbackRequest)
478
- @rollback.call(req, options, &block)
479
- end
480
-
481
- # Allocates IDs for the given keys, which is useful for referencing an entity
482
- # before it is inserted.
483
- #
484
- # @param project_id [String]
485
- # Required. The ID of the project against which to make the request.
486
- # @param keys [Array<Google::Datastore::V1::Key | Hash>]
487
- # Required. A list of keys with incomplete key paths for which to allocate IDs.
488
- # No key may be reserved/read-only.
489
- # A hash of the same form as `Google::Datastore::V1::Key`
490
- # can also be provided.
491
- # @param options [Google::Gax::CallOptions]
492
- # Overrides the default settings for this call, e.g, timeout,
493
- # retries, etc.
494
- # @yield [result, operation] Access the result along with the RPC operation
495
- # @yieldparam result [Google::Datastore::V1::AllocateIdsResponse]
496
- # @yieldparam operation [GRPC::ActiveCall::Operation]
497
- # @return [Google::Datastore::V1::AllocateIdsResponse]
498
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
499
- # @example
500
- # require "google/cloud/datastore"
501
- #
502
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
503
- #
504
- # # TODO: Initialize `project_id`:
505
- # project_id = ''
506
- #
507
- # # TODO: Initialize `keys`:
508
- # keys = []
509
- # response = datastore_client.allocate_ids(project_id, keys)
510
-
511
- def allocate_ids \
512
- project_id,
513
- keys,
514
- options: nil,
515
- &block
516
- req = {
517
- project_id: project_id,
518
- keys: keys
519
- }.delete_if { |_, v| v.nil? }
520
- req = Google::Gax::to_proto(req, Google::Datastore::V1::AllocateIdsRequest)
521
- @allocate_ids.call(req, options, &block)
522
- end
523
-
524
- # Prevents the supplied keys' IDs from being auto-allocated by Cloud
525
- # Datastore.
526
- #
527
- # @param project_id [String]
528
- # Required. The ID of the project against which to make the request.
529
- # @param keys [Array<Google::Datastore::V1::Key | Hash>]
530
- # Required. A list of keys with complete key paths whose numeric IDs should not be
531
- # auto-allocated.
532
- # A hash of the same form as `Google::Datastore::V1::Key`
533
- # can also be provided.
534
- # @param database_id [String]
535
- # If not empty, the ID of the database against which to make the request.
536
- # @param options [Google::Gax::CallOptions]
537
- # Overrides the default settings for this call, e.g, timeout,
538
- # retries, etc.
539
- # @yield [result, operation] Access the result along with the RPC operation
540
- # @yieldparam result [Google::Datastore::V1::ReserveIdsResponse]
541
- # @yieldparam operation [GRPC::ActiveCall::Operation]
542
- # @return [Google::Datastore::V1::ReserveIdsResponse]
543
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
544
- # @example
545
- # require "google/cloud/datastore"
546
- #
547
- # datastore_client = Google::Cloud::Datastore.new(version: :v1)
548
- #
549
- # # TODO: Initialize `project_id`:
550
- # project_id = ''
551
- #
552
- # # TODO: Initialize `keys`:
553
- # keys = []
554
- # response = datastore_client.reserve_ids(project_id, keys)
555
-
556
- def reserve_ids \
557
- project_id,
558
- keys,
559
- database_id: nil,
560
- options: nil,
561
- &block
562
- req = {
563
- project_id: project_id,
564
- keys: keys,
565
- database_id: database_id
566
- }.delete_if { |_, v| v.nil? }
567
- req = Google::Gax::to_proto(req, Google::Datastore::V1::ReserveIdsRequest)
568
- @reserve_ids.call(req, options, &block)
569
- end
570
- end
571
- end
572
- end
573
- end
574
- end