google-cloud-datastore 0.20.1 → 0.21.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/lib/google-cloud-datastore.rb +14 -32
- data/lib/google/cloud/datastore.rb +113 -70
- data/lib/google/cloud/datastore/commit.rb +5 -10
- data/lib/google/cloud/datastore/cursor.rb +2 -3
- data/lib/google/cloud/datastore/dataset.rb +17 -22
- data/lib/google/cloud/datastore/dataset/lookup_results.rb +5 -10
- data/lib/google/cloud/datastore/dataset/query_results.rb +24 -36
- data/lib/google/cloud/datastore/entity.rb +26 -39
- data/lib/google/cloud/datastore/key.rb +12 -11
- data/lib/google/cloud/datastore/properties.rb +1 -1
- data/lib/google/cloud/datastore/service.rb +72 -74
- data/lib/google/cloud/datastore/transaction.rb +8 -12
- data/lib/google/cloud/datastore/v1.rb +16 -0
- data/lib/google/cloud/datastore/v1/datastore_api.rb +396 -0
- data/lib/google/cloud/datastore/v1/datastore_client_config.json +58 -0
- data/lib/google/cloud/datastore/version.rb +1 -1
- metadata +37 -6
@@ -46,12 +46,13 @@ module Google
|
|
46
46
|
# @return [String]
|
47
47
|
#
|
48
48
|
# @example
|
49
|
-
# require "google/cloud"
|
49
|
+
# require "google/cloud/datastore"
|
50
50
|
#
|
51
|
-
#
|
52
|
-
#
|
51
|
+
# datastore = Google::Cloud::Datastore.new(
|
52
|
+
# project: "my-todo-project",
|
53
|
+
# keyfile: "/path/to/keyfile.json"
|
54
|
+
# )
|
53
55
|
#
|
54
|
-
# datastore = gcloud.datastore
|
55
56
|
# task = datastore.find "Task", "sampleTask"
|
56
57
|
# task.key.project #=> "my-todo-project"
|
57
58
|
#
|
@@ -65,12 +66,13 @@ module Google
|
|
65
66
|
# @return [String, nil]
|
66
67
|
#
|
67
68
|
# @example
|
68
|
-
# require "google/cloud"
|
69
|
+
# require "google/cloud/datastore"
|
69
70
|
#
|
70
|
-
#
|
71
|
-
#
|
71
|
+
# datastore = Google::Cloud::Datastore.new(
|
72
|
+
# project: "my-todo-project",
|
73
|
+
# keyfile: "/path/to/keyfile.json"
|
74
|
+
# )
|
72
75
|
#
|
73
|
-
# datastore = gcloud.datastore
|
74
76
|
# task = datastore.find "Task", "sampleTask"
|
75
77
|
# task.key.namespace #=> "ns~todo-project"
|
76
78
|
#
|
@@ -186,10 +188,9 @@ module Google
|
|
186
188
|
# @return [Key, nil]
|
187
189
|
#
|
188
190
|
# @example
|
189
|
-
# require "google/cloud"
|
191
|
+
# require "google/cloud/datastore"
|
190
192
|
#
|
191
|
-
#
|
192
|
-
# datastore = gcloud.datastore
|
193
|
+
# datastore = Google::Cloud::Datastore.new
|
193
194
|
#
|
194
195
|
# task_list = datastore.find "TaskList", "default"
|
195
196
|
# query = datastore.query("Task").
|
@@ -92,7 +92,7 @@ module Google
|
|
92
92
|
# Ensures the key is the proper type,
|
93
93
|
# otherwise a PropertyError is raised.
|
94
94
|
def ensure_key_type key
|
95
|
-
return key.
|
95
|
+
return key.to_s if key.respond_to? :to_s
|
96
96
|
fail "Property key #{key} must be a String."
|
97
97
|
end
|
98
98
|
|
@@ -13,46 +13,55 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
+
require "google/cloud/errors"
|
16
17
|
require "google/cloud/datastore/credentials"
|
17
|
-
require "google/datastore/
|
18
|
-
require "google/cloud/
|
18
|
+
require "google/cloud/datastore/version"
|
19
|
+
require "google/cloud/datastore/v1"
|
20
|
+
require "google/gax/errors"
|
19
21
|
|
20
22
|
module Google
|
21
23
|
module Cloud
|
22
24
|
module Datastore
|
23
25
|
##
|
24
|
-
# @private Represents the
|
26
|
+
# @private Represents the GAX Datastore service, including all the API
|
25
27
|
# methods.
|
26
28
|
class Service
|
27
|
-
attr_accessor :project, :credentials, :host, :
|
29
|
+
attr_accessor :project, :credentials, :host, :timeout, :client_config
|
28
30
|
|
29
31
|
##
|
30
32
|
# Creates a new Service instance.
|
31
|
-
def initialize project, credentials, host: nil,
|
32
|
-
|
33
|
+
def initialize project, credentials, host: nil, timeout: nil,
|
34
|
+
client_config: nil
|
33
35
|
@project = project
|
34
36
|
@credentials = credentials
|
35
|
-
@host = host ||
|
36
|
-
@retries = retries
|
37
|
+
@host = host || V1::DatastoreApi::SERVICE_ADDRESS
|
37
38
|
@timeout = timeout
|
39
|
+
@client_config = client_config || {}
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
42
|
+
def channel
|
43
|
+
require "grpc"
|
44
|
+
GRPC::Core::Channel.new host, nil, chan_creds
|
45
|
+
end
|
46
|
+
|
47
|
+
def chan_creds
|
41
48
|
return credentials if insecure?
|
49
|
+
require "grpc"
|
42
50
|
GRPC::Core::ChannelCredentials.new.compose \
|
43
51
|
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
44
52
|
end
|
45
53
|
|
46
|
-
def
|
47
|
-
return
|
48
|
-
@
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
def service
|
55
|
+
return mocked_service if mocked_service
|
56
|
+
@service ||= V1::DatastoreApi.new(
|
57
|
+
service_path: host,
|
58
|
+
channel: channel,
|
59
|
+
timeout: timeout,
|
60
|
+
client_config: client_config,
|
61
|
+
app_name: "gcloud-ruby",
|
62
|
+
app_version: Google::Cloud::Datastore::VERSION)
|
54
63
|
end
|
55
|
-
attr_accessor :
|
64
|
+
attr_accessor :mocked_service
|
56
65
|
|
57
66
|
def insecure?
|
58
67
|
credentials == :this_channel_is_insecure
|
@@ -62,98 +71,72 @@ module Google
|
|
62
71
|
# Allocate IDs for incomplete keys.
|
63
72
|
# (This is useful for referencing an entity before it is inserted.)
|
64
73
|
def allocate_ids *incomplete_keys
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
execute { datastore.allocate_ids allocate_req }
|
74
|
+
execute do
|
75
|
+
service.allocate_ids project, incomplete_keys,
|
76
|
+
options: default_options
|
77
|
+
end
|
71
78
|
end
|
72
79
|
|
73
80
|
##
|
74
81
|
# Look up entities by keys.
|
75
82
|
def lookup *keys, consistency: nil, transaction: nil
|
76
|
-
|
77
|
-
project_id: project,
|
78
|
-
keys: keys
|
79
|
-
)
|
80
|
-
lookup_req.read_options = generate_read_options consistency,
|
81
|
-
transaction
|
83
|
+
read_options = generate_read_options consistency, transaction
|
82
84
|
|
83
|
-
execute
|
85
|
+
execute do
|
86
|
+
service.lookup project, read_options, keys, options: default_options
|
87
|
+
end
|
84
88
|
end
|
85
89
|
|
86
90
|
# Query for entities.
|
87
91
|
def run_query query, namespace = nil, consistency: nil, transaction: nil
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
elsif query.is_a? Google::Datastore::V1::GqlQuery
|
93
|
-
run_req["gql_query"] = query
|
94
|
-
else
|
95
|
-
fail ArgumentError, "Unable to query with a #{query.class} object."
|
92
|
+
gql_query = nil
|
93
|
+
if query.is_a? Google::Datastore::V1::GqlQuery
|
94
|
+
gql_query = query
|
95
|
+
query = nil
|
96
96
|
end
|
97
|
-
|
98
|
-
|
99
|
-
run_req.partition_id = Google::Datastore::V1::PartitionId.new(
|
97
|
+
read_options = generate_read_options consistency, transaction
|
98
|
+
partition_id = Google::Datastore::V1::PartitionId.new(
|
100
99
|
namespace_id: namespace) if namespace
|
101
100
|
|
102
|
-
execute
|
101
|
+
execute do
|
102
|
+
service.run_query project,
|
103
|
+
partition_id,
|
104
|
+
read_options,
|
105
|
+
query: query,
|
106
|
+
gql_query: gql_query,
|
107
|
+
options: default_options
|
108
|
+
end
|
103
109
|
end
|
104
110
|
|
105
111
|
##
|
106
112
|
# Begin a new transaction.
|
107
113
|
def begin_transaction
|
108
|
-
|
109
|
-
project_id: project
|
110
|
-
)
|
111
|
-
|
112
|
-
execute { datastore.begin_transaction tx_req }
|
114
|
+
execute { service.begin_transaction project }
|
113
115
|
end
|
114
116
|
|
115
117
|
##
|
116
118
|
# Commit a transaction, optionally creating, deleting or modifying
|
117
119
|
# some entities.
|
118
120
|
def commit mutations, transaction: nil
|
119
|
-
|
120
|
-
|
121
|
-
mode:
|
122
|
-
|
123
|
-
)
|
124
|
-
if transaction
|
125
|
-
commit_req.mode = :TRANSACTIONAL
|
126
|
-
commit_req.transaction = transaction
|
121
|
+
mode = transaction.nil? ? :NON_TRANSACTIONAL : :TRANSACTIONAL
|
122
|
+
execute do
|
123
|
+
service.commit project, mode, mutations, transaction: transaction,
|
124
|
+
options: default_options
|
127
125
|
end
|
128
|
-
|
129
|
-
execute { datastore.commit commit_req }
|
130
126
|
end
|
131
127
|
|
132
128
|
##
|
133
129
|
# Roll back a transaction.
|
134
130
|
def rollback transaction
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
)
|
139
|
-
|
140
|
-
execute { datastore.rollback rb_req }
|
131
|
+
execute do
|
132
|
+
service.rollback project, transaction, options: default_options
|
133
|
+
end
|
141
134
|
end
|
142
135
|
|
143
136
|
def inspect
|
144
137
|
"#{self.class}(#{@project})"
|
145
138
|
end
|
146
139
|
|
147
|
-
##
|
148
|
-
# Performs backoff and error handling
|
149
|
-
def execute
|
150
|
-
Google::Cloud::Core::GrpcBackoff.new(retries: retries).execute do
|
151
|
-
yield
|
152
|
-
end
|
153
|
-
rescue GRPC::BadStatus => e
|
154
|
-
raise Google::Cloud::Error.from_error(e)
|
155
|
-
end
|
156
|
-
|
157
140
|
protected
|
158
141
|
|
159
142
|
def generate_read_options consistency, transaction
|
@@ -169,6 +152,21 @@ module Google
|
|
169
152
|
end
|
170
153
|
nil
|
171
154
|
end
|
155
|
+
|
156
|
+
def default_headers
|
157
|
+
{ "google-cloud-resource-prefix" => "projects/#{@project}" }
|
158
|
+
end
|
159
|
+
|
160
|
+
def default_options
|
161
|
+
Google::Gax::CallOptions.new kwargs: default_headers
|
162
|
+
end
|
163
|
+
|
164
|
+
def execute
|
165
|
+
yield
|
166
|
+
rescue Google::Gax::GaxError => e
|
167
|
+
# GaxError wraps BadStatus, but exposes it as #cause
|
168
|
+
raise Google::Cloud::Error.from_error(e.cause)
|
169
|
+
end
|
172
170
|
end
|
173
171
|
end
|
174
172
|
end
|
@@ -59,7 +59,7 @@ module Google
|
|
59
59
|
|
60
60
|
##
|
61
61
|
# @private Creates a new Transaction instance.
|
62
|
-
# Takes a
|
62
|
+
# Takes a Service instead of project and Credentials.
|
63
63
|
def initialize service
|
64
64
|
@service = service
|
65
65
|
reset!
|
@@ -191,8 +191,7 @@ module Google
|
|
191
191
|
# @return [Google::Cloud::Datastore::Dataset::LookupResults]
|
192
192
|
#
|
193
193
|
# @example
|
194
|
-
#
|
195
|
-
# datastore = gcloud.datastore
|
194
|
+
# datastore = Google::Cloud::Datastore.new
|
196
195
|
# task_key1 = datastore.key "Task", 123456
|
197
196
|
# task_key2 = datastore.key "Task", 987654
|
198
197
|
# tasks = datastore.find_all task_key1, task_key2
|
@@ -259,10 +258,9 @@ module Google
|
|
259
258
|
# @yieldparam [Commit] commit The object that changes are made on
|
260
259
|
#
|
261
260
|
# @example
|
262
|
-
# require "google/cloud"
|
261
|
+
# require "google/cloud/datastore"
|
263
262
|
#
|
264
|
-
#
|
265
|
-
# datastore = gcloud.datastore
|
263
|
+
# datastore = Google::Cloud::Datastore.new
|
266
264
|
#
|
267
265
|
# task = datastore.entity "Task" do |t|
|
268
266
|
# t["type"] = "Personal"
|
@@ -282,10 +280,9 @@ module Google
|
|
282
280
|
# end
|
283
281
|
#
|
284
282
|
# @example Commit can be passed a block, same as {Dataset#commit}:
|
285
|
-
# require "google/cloud"
|
283
|
+
# require "google/cloud/datastore"
|
286
284
|
#
|
287
|
-
#
|
288
|
-
# datastore = gcloud.datastore
|
285
|
+
# datastore = Google::Cloud::Datastore.new
|
289
286
|
#
|
290
287
|
# tx = datastore.transaction
|
291
288
|
# begin
|
@@ -321,10 +318,9 @@ module Google
|
|
321
318
|
# Rolls a transaction back.
|
322
319
|
#
|
323
320
|
# @example
|
324
|
-
# require "google/cloud"
|
321
|
+
# require "google/cloud/datastore"
|
325
322
|
#
|
326
|
-
#
|
327
|
-
# datastore = gcloud.datastore
|
323
|
+
# datastore = Google::Cloud::Datastore.new
|
328
324
|
#
|
329
325
|
# task = datastore.entity "Task" do |t|
|
330
326
|
# t["type"] = "Personal"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
+
# http://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_api"
|
@@ -0,0 +1,396 @@
|
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
+
# http://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
|
+
# The only allowed edits are to method and file documentation. A 3-way
|
23
|
+
# merge preserves those additions if the generated source changes.
|
24
|
+
|
25
|
+
require "json"
|
26
|
+
require "pathname"
|
27
|
+
|
28
|
+
require "google/gax"
|
29
|
+
require "google/datastore/v1/datastore_pb"
|
30
|
+
|
31
|
+
module Google
|
32
|
+
module Cloud
|
33
|
+
module Datastore
|
34
|
+
module V1
|
35
|
+
# Each RPC normalizes the partition IDs of the keys in its input entities,
|
36
|
+
# and always returns entities with keys with normalized partition IDs.
|
37
|
+
# This applies to all keys and entities, including those in values, except keys
|
38
|
+
# with both an empty path and an empty or unset partition ID. Normalization of
|
39
|
+
# input keys sets the project ID (if not already set) to the project ID from
|
40
|
+
# the request.
|
41
|
+
#
|
42
|
+
# @!attribute [r] datastore_stub
|
43
|
+
# @return [Google::Datastore::V1::Datastore::Stub]
|
44
|
+
class DatastoreApi
|
45
|
+
attr_reader :datastore_stub
|
46
|
+
|
47
|
+
# The default address of the service.
|
48
|
+
SERVICE_ADDRESS = "datastore.googleapis.com".freeze
|
49
|
+
|
50
|
+
# The default port of the service.
|
51
|
+
DEFAULT_SERVICE_PORT = 443
|
52
|
+
|
53
|
+
CODE_GEN_NAME_VERSION = "gapic/0.1.0".freeze
|
54
|
+
|
55
|
+
DEFAULT_TIMEOUT = 30
|
56
|
+
|
57
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
58
|
+
# this service.
|
59
|
+
ALL_SCOPES = [
|
60
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
61
|
+
"https://www.googleapis.com/auth/datastore"
|
62
|
+
].freeze
|
63
|
+
|
64
|
+
# @param service_path [String]
|
65
|
+
# The domain name of the API remote host.
|
66
|
+
# @param port [Integer]
|
67
|
+
# The port on which to connect to the remote host.
|
68
|
+
# @param channel [Channel]
|
69
|
+
# A Channel object through which to make calls.
|
70
|
+
# @param chan_creds [Grpc::ChannelCredentials]
|
71
|
+
# A ChannelCredentials for the setting up the RPC client.
|
72
|
+
# @param client_config[Hash]
|
73
|
+
# A Hash for call options for each method. See
|
74
|
+
# Google::Gax#construct_settings for the structure of
|
75
|
+
# this data. Falls back to the default config if not specified
|
76
|
+
# or the specified config is missing data points.
|
77
|
+
# @param timeout [Numeric]
|
78
|
+
# The default timeout, in seconds, for calls made through this client.
|
79
|
+
# @param app_name [String]
|
80
|
+
# The codename of the calling service.
|
81
|
+
# @param app_version [String]
|
82
|
+
# The version of the calling service.
|
83
|
+
def initialize \
|
84
|
+
service_path: SERVICE_ADDRESS,
|
85
|
+
port: DEFAULT_SERVICE_PORT,
|
86
|
+
channel: nil,
|
87
|
+
chan_creds: nil,
|
88
|
+
scopes: ALL_SCOPES,
|
89
|
+
client_config: {},
|
90
|
+
timeout: DEFAULT_TIMEOUT,
|
91
|
+
app_name: "gax",
|
92
|
+
app_version: Google::Gax::VERSION
|
93
|
+
# These require statements are intentionally placed here to initialize
|
94
|
+
# the gRPC module only when it's required.
|
95
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
96
|
+
require "google/gax/grpc"
|
97
|
+
require "google/datastore/v1/datastore_services_pb"
|
98
|
+
|
99
|
+
google_api_client = "#{app_name}/#{app_version} " \
|
100
|
+
"#{CODE_GEN_NAME_VERSION} gax/#{Google::Gax::VERSION} " \
|
101
|
+
"ruby/#{RUBY_VERSION}".freeze
|
102
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
103
|
+
client_config_file = Pathname.new(__dir__).join(
|
104
|
+
"datastore_client_config.json"
|
105
|
+
)
|
106
|
+
defaults = client_config_file.open do |f|
|
107
|
+
Google::Gax.construct_settings(
|
108
|
+
"google.datastore.v1.Datastore",
|
109
|
+
JSON.parse(f.read),
|
110
|
+
client_config,
|
111
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
112
|
+
timeout,
|
113
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
114
|
+
kwargs: headers
|
115
|
+
)
|
116
|
+
end
|
117
|
+
@datastore_stub = Google::Gax::Grpc.create_stub(
|
118
|
+
service_path,
|
119
|
+
port,
|
120
|
+
chan_creds: chan_creds,
|
121
|
+
channel: channel,
|
122
|
+
scopes: scopes,
|
123
|
+
&Google::Datastore::V1::Datastore::Stub.method(:new)
|
124
|
+
)
|
125
|
+
|
126
|
+
@lookup = Google::Gax.create_api_call(
|
127
|
+
@datastore_stub.method(:lookup),
|
128
|
+
defaults["lookup"]
|
129
|
+
)
|
130
|
+
@run_query = Google::Gax.create_api_call(
|
131
|
+
@datastore_stub.method(:run_query),
|
132
|
+
defaults["run_query"]
|
133
|
+
)
|
134
|
+
@begin_transaction = Google::Gax.create_api_call(
|
135
|
+
@datastore_stub.method(:begin_transaction),
|
136
|
+
defaults["begin_transaction"]
|
137
|
+
)
|
138
|
+
@commit = Google::Gax.create_api_call(
|
139
|
+
@datastore_stub.method(:commit),
|
140
|
+
defaults["commit"]
|
141
|
+
)
|
142
|
+
@rollback = Google::Gax.create_api_call(
|
143
|
+
@datastore_stub.method(:rollback),
|
144
|
+
defaults["rollback"]
|
145
|
+
)
|
146
|
+
@allocate_ids = Google::Gax.create_api_call(
|
147
|
+
@datastore_stub.method(:allocate_ids),
|
148
|
+
defaults["allocate_ids"]
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Service calls
|
153
|
+
|
154
|
+
# Looks up entities by key.
|
155
|
+
#
|
156
|
+
# @param project_id [String]
|
157
|
+
# The ID of the project against which to make the request.
|
158
|
+
# @param read_options [Google::Datastore::V1::ReadOptions]
|
159
|
+
# The options for this lookup request.
|
160
|
+
# @param keys [Array<Google::Datastore::V1::Key>]
|
161
|
+
# Keys of entities to look up.
|
162
|
+
# @param options [Google::Gax::CallOptions]
|
163
|
+
# Overrides the default settings for this call, e.g, timeout,
|
164
|
+
# retries, etc.
|
165
|
+
# @return [Google::Datastore::V1::LookupResponse]
|
166
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
167
|
+
# @example
|
168
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
169
|
+
#
|
170
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
171
|
+
# ReadOptions = Google::Datastore::V1::ReadOptions
|
172
|
+
#
|
173
|
+
# datastore_api = DatastoreApi.new
|
174
|
+
# project_id = ''
|
175
|
+
# read_options = ReadOptions.new
|
176
|
+
# keys = []
|
177
|
+
# response = datastore_api.lookup(project_id, read_options, keys)
|
178
|
+
|
179
|
+
def lookup \
|
180
|
+
project_id,
|
181
|
+
read_options,
|
182
|
+
keys,
|
183
|
+
options: nil
|
184
|
+
req = Google::Datastore::V1::LookupRequest.new(
|
185
|
+
project_id: project_id,
|
186
|
+
read_options: read_options,
|
187
|
+
keys: keys
|
188
|
+
)
|
189
|
+
@lookup.call(req, options)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Queries for entities.
|
193
|
+
#
|
194
|
+
# @param project_id [String]
|
195
|
+
# The ID of the project against which to make the request.
|
196
|
+
# @param partition_id [Google::Datastore::V1::PartitionId]
|
197
|
+
# Entities are partitioned into subsets, identified by a partition ID.
|
198
|
+
# Queries are scoped to a single partition.
|
199
|
+
# This partition ID is normalized with the standard default context
|
200
|
+
# partition ID.
|
201
|
+
# @param read_options [Google::Datastore::V1::ReadOptions]
|
202
|
+
# The options for this query.
|
203
|
+
# @param query [Google::Datastore::V1::Query]
|
204
|
+
# The query to run.
|
205
|
+
# @param gql_query [Google::Datastore::V1::GqlQuery]
|
206
|
+
# The GQL query to run.
|
207
|
+
# @param options [Google::Gax::CallOptions]
|
208
|
+
# Overrides the default settings for this call, e.g, timeout,
|
209
|
+
# retries, etc.
|
210
|
+
# @return [Google::Datastore::V1::RunQueryResponse]
|
211
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
212
|
+
# @example
|
213
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
214
|
+
#
|
215
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
216
|
+
# PartitionId = Google::Datastore::V1::PartitionId
|
217
|
+
# ReadOptions = Google::Datastore::V1::ReadOptions
|
218
|
+
#
|
219
|
+
# datastore_api = DatastoreApi.new
|
220
|
+
# project_id = ''
|
221
|
+
# partition_id = PartitionId.new
|
222
|
+
# read_options = ReadOptions.new
|
223
|
+
# response = datastore_api.run_query(project_id, partition_id, read_options)
|
224
|
+
|
225
|
+
def run_query \
|
226
|
+
project_id,
|
227
|
+
partition_id,
|
228
|
+
read_options,
|
229
|
+
query: nil,
|
230
|
+
gql_query: nil,
|
231
|
+
options: nil
|
232
|
+
req = Google::Datastore::V1::RunQueryRequest.new(
|
233
|
+
project_id: project_id,
|
234
|
+
partition_id: partition_id,
|
235
|
+
read_options: read_options
|
236
|
+
)
|
237
|
+
req.query = query unless query.nil?
|
238
|
+
req.gql_query = gql_query unless gql_query.nil?
|
239
|
+
@run_query.call(req, options)
|
240
|
+
end
|
241
|
+
|
242
|
+
# Begins a new transaction.
|
243
|
+
#
|
244
|
+
# @param project_id [String]
|
245
|
+
# The ID of the project against which to make the request.
|
246
|
+
# @param options [Google::Gax::CallOptions]
|
247
|
+
# Overrides the default settings for this call, e.g, timeout,
|
248
|
+
# retries, etc.
|
249
|
+
# @return [Google::Datastore::V1::BeginTransactionResponse]
|
250
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
251
|
+
# @example
|
252
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
253
|
+
#
|
254
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
255
|
+
#
|
256
|
+
# datastore_api = DatastoreApi.new
|
257
|
+
# project_id = ''
|
258
|
+
# response = datastore_api.begin_transaction(project_id)
|
259
|
+
|
260
|
+
def begin_transaction \
|
261
|
+
project_id,
|
262
|
+
options: nil
|
263
|
+
req = Google::Datastore::V1::BeginTransactionRequest.new(
|
264
|
+
project_id: project_id
|
265
|
+
)
|
266
|
+
@begin_transaction.call(req, options)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Commits a transaction, optionally creating, deleting or modifying some
|
270
|
+
# entities.
|
271
|
+
#
|
272
|
+
# @param project_id [String]
|
273
|
+
# The ID of the project against which to make the request.
|
274
|
+
# @param mode [Google::Datastore::V1::CommitRequest::Mode]
|
275
|
+
# The type of commit to perform. Defaults to +TRANSACTIONAL+.
|
276
|
+
# @param transaction [String]
|
277
|
+
# The identifier of the transaction associated with the commit. A
|
278
|
+
# transaction identifier is returned by a call to
|
279
|
+
# Datastore::BeginTransaction.
|
280
|
+
# @param mutations [Array<Google::Datastore::V1::Mutation>]
|
281
|
+
# The mutations to perform.
|
282
|
+
#
|
283
|
+
# When mode is +TRANSACTIONAL+, mutations affecting a single entity are
|
284
|
+
# applied in order. The following sequences of mutations affecting a single
|
285
|
+
# entity are not permitted in a single +Commit+ request:
|
286
|
+
#
|
287
|
+
# - +insert+ followed by +insert+
|
288
|
+
# - +update+ followed by +insert+
|
289
|
+
# - +upsert+ followed by +insert+
|
290
|
+
# - +delete+ followed by +update+
|
291
|
+
#
|
292
|
+
# When mode is +NON_TRANSACTIONAL+, no two mutations may affect a single
|
293
|
+
# entity.
|
294
|
+
# @param options [Google::Gax::CallOptions]
|
295
|
+
# Overrides the default settings for this call, e.g, timeout,
|
296
|
+
# retries, etc.
|
297
|
+
# @return [Google::Datastore::V1::CommitResponse]
|
298
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
299
|
+
# @example
|
300
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
301
|
+
#
|
302
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
303
|
+
# Mode = Google::Datastore::V1::CommitRequest::Mode
|
304
|
+
#
|
305
|
+
# datastore_api = DatastoreApi.new
|
306
|
+
# project_id = ''
|
307
|
+
# mode = Mode::MODE_UNSPECIFIED
|
308
|
+
# mutations = []
|
309
|
+
# response = datastore_api.commit(project_id, mode, mutations)
|
310
|
+
|
311
|
+
def commit \
|
312
|
+
project_id,
|
313
|
+
mode,
|
314
|
+
mutations,
|
315
|
+
transaction: nil,
|
316
|
+
options: nil
|
317
|
+
req = Google::Datastore::V1::CommitRequest.new(
|
318
|
+
project_id: project_id,
|
319
|
+
mode: mode,
|
320
|
+
mutations: mutations
|
321
|
+
)
|
322
|
+
req.transaction = transaction unless transaction.nil?
|
323
|
+
@commit.call(req, options)
|
324
|
+
end
|
325
|
+
|
326
|
+
# Rolls back a transaction.
|
327
|
+
#
|
328
|
+
# @param project_id [String]
|
329
|
+
# The ID of the project against which to make the request.
|
330
|
+
# @param transaction [String]
|
331
|
+
# The transaction identifier, returned by a call to
|
332
|
+
# Datastore::BeginTransaction.
|
333
|
+
# @param options [Google::Gax::CallOptions]
|
334
|
+
# Overrides the default settings for this call, e.g, timeout,
|
335
|
+
# retries, etc.
|
336
|
+
# @return [Google::Datastore::V1::RollbackResponse]
|
337
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
338
|
+
# @example
|
339
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
340
|
+
#
|
341
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
342
|
+
#
|
343
|
+
# datastore_api = DatastoreApi.new
|
344
|
+
# project_id = ''
|
345
|
+
# transaction = ''
|
346
|
+
# response = datastore_api.rollback(project_id, transaction)
|
347
|
+
|
348
|
+
def rollback \
|
349
|
+
project_id,
|
350
|
+
transaction,
|
351
|
+
options: nil
|
352
|
+
req = Google::Datastore::V1::RollbackRequest.new(
|
353
|
+
project_id: project_id,
|
354
|
+
transaction: transaction
|
355
|
+
)
|
356
|
+
@rollback.call(req, options)
|
357
|
+
end
|
358
|
+
|
359
|
+
# Allocates IDs for the given keys, which is useful for referencing an entity
|
360
|
+
# before it is inserted.
|
361
|
+
#
|
362
|
+
# @param project_id [String]
|
363
|
+
# The ID of the project against which to make the request.
|
364
|
+
# @param keys [Array<Google::Datastore::V1::Key>]
|
365
|
+
# A list of keys with incomplete key paths for which to allocate IDs.
|
366
|
+
# No key may be reserved/read-only.
|
367
|
+
# @param options [Google::Gax::CallOptions]
|
368
|
+
# Overrides the default settings for this call, e.g, timeout,
|
369
|
+
# retries, etc.
|
370
|
+
# @return [Google::Datastore::V1::AllocateIdsResponse]
|
371
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
372
|
+
# @example
|
373
|
+
# require "google/cloud/datastore/v1/datastore_api"
|
374
|
+
#
|
375
|
+
# DatastoreApi = Google::Cloud::Datastore::V1::DatastoreApi
|
376
|
+
#
|
377
|
+
# datastore_api = DatastoreApi.new
|
378
|
+
# project_id = ''
|
379
|
+
# keys = []
|
380
|
+
# response = datastore_api.allocate_ids(project_id, keys)
|
381
|
+
|
382
|
+
def allocate_ids \
|
383
|
+
project_id,
|
384
|
+
keys,
|
385
|
+
options: nil
|
386
|
+
req = Google::Datastore::V1::AllocateIdsRequest.new(
|
387
|
+
project_id: project_id,
|
388
|
+
keys: keys
|
389
|
+
)
|
390
|
+
@allocate_ids.call(req, options)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|