google-cloud-datastore 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -4
- data/lib/google-cloud-datastore.rb +12 -10
- data/lib/google/cloud/datastore.rb +35 -31
- data/lib/google/cloud/datastore/convert.rb +0 -11
- data/lib/google/cloud/datastore/credentials.rb +28 -9
- data/lib/google/cloud/datastore/dataset.rb +7 -6
- data/lib/google/cloud/datastore/key.rb +2 -0
- data/lib/google/cloud/datastore/properties.rb +4 -8
- data/lib/google/cloud/datastore/service.rb +4 -3
- data/lib/google/cloud/datastore/v1/datastore_client.rb +168 -80
- data/lib/google/cloud/datastore/v1/datastore_client_config.json +5 -0
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/datastore.rb +72 -20
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/entity.rb +10 -10
- data/lib/google/cloud/datastore/v1/doc/google/datastore/v1/query.rb +7 -7
- data/lib/google/cloud/datastore/v1/doc/overview.rb +54 -0
- data/lib/google/cloud/datastore/version.rb +1 -1
- data/lib/google/datastore/v1/datastore_pb.rb +24 -0
- data/lib/google/datastore/v1/datastore_services_pb.rb +4 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a1da7c30b9ed87eedfb4abe77dac961faa9725cf37aa01a005801f5c61a8d1f
|
4
|
+
data.tar.gz: e0914a5d01fa98beabd730265ed7ad6b5d5ec82c03048f02ef8eea30176857ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec12fe6cae19b6eef6be1adfa03443452126571eaf4dcd01e670d5311c308a1038315efa8071d81143c23e8dc1915a942c4848f5d847fb73986b433520bb32f3
|
7
|
+
data.tar.gz: 55779d36826b8e93f27a606687795d4d176409ab4854b9f0135207cf73364e333e7be7ff2485dc84fa058edee7fffbf24f1266388ca17e8fd277ada036a4852c
|
data/README.md
CHANGED
@@ -26,8 +26,8 @@ Instructions and configuration options are covered in the [Authentication Guide]
|
|
26
26
|
require "google/cloud/datastore"
|
27
27
|
|
28
28
|
datastore = Google::Cloud::Datastore.new(
|
29
|
-
|
30
|
-
|
29
|
+
project_id: "my-todo-project",
|
30
|
+
credentials: "/path/to/keyfile.json"
|
31
31
|
)
|
32
32
|
|
33
33
|
# Create a new task to demo datastore
|
@@ -55,8 +55,6 @@ This library is supported on Ruby 2.0+.
|
|
55
55
|
|
56
56
|
This library follows [Semantic Versioning](http://semver.org/).
|
57
57
|
|
58
|
-
It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
|
59
|
-
|
60
58
|
## Contributing
|
61
59
|
|
62
60
|
Contributions to this library are always welcome and highly encouraged.
|
@@ -13,9 +13,9 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
##
|
16
|
-
# This file is here to be autorequired by bundler, so that the
|
17
|
-
# #
|
18
|
-
# be loaded until required and used.
|
16
|
+
# This file is here to be autorequired by bundler, so that the
|
17
|
+
# Google::Cloud.datastore and Google::Cloud#datastore methods can be available,
|
18
|
+
# but the library and all dependencies won't be loaded until required and used.
|
19
19
|
|
20
20
|
|
21
21
|
gem "google-cloud-core"
|
@@ -79,10 +79,11 @@ module Google
|
|
79
79
|
# For more information on connecting to Google Cloud see the [Authentication
|
80
80
|
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
81
81
|
#
|
82
|
-
# @param [String]
|
83
|
-
#
|
84
|
-
# @param [String, Hash]
|
85
|
-
#
|
82
|
+
# @param [String] project_id Identifier for a Datastore project. If not
|
83
|
+
# present, the default project for the credentials is used.
|
84
|
+
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
85
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
86
|
+
# Google::Auth::Credentials object. (See {Datastore::Credentials})
|
86
87
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
87
88
|
# set of resources and operations that the connection can access. See
|
88
89
|
# [Using OAuth 2.0 to Access Google
|
@@ -112,10 +113,11 @@ module Google
|
|
112
113
|
#
|
113
114
|
# datastore.save task
|
114
115
|
#
|
115
|
-
def self.datastore
|
116
|
-
client_config: nil
|
116
|
+
def self.datastore project_id = nil, credentials = nil, scope: nil,
|
117
|
+
timeout: nil, client_config: nil
|
117
118
|
require "google/cloud/datastore"
|
118
|
-
Google::Cloud::Datastore.new
|
119
|
+
Google::Cloud::Datastore.new project_id: project_id,
|
120
|
+
credentials: credentials,
|
119
121
|
scope: scope, timeout: timeout,
|
120
122
|
client_config: client_config
|
121
123
|
end
|
@@ -39,8 +39,8 @@ module Google
|
|
39
39
|
# require "google/cloud/datastore"
|
40
40
|
#
|
41
41
|
# datastore = Google::Cloud::Datastore.new(
|
42
|
-
#
|
43
|
-
#
|
42
|
+
# project_id: "my-todo-project",
|
43
|
+
# credentials: "/path/to/keyfile.json"
|
44
44
|
# )
|
45
45
|
#
|
46
46
|
# task = datastore.find "Task", "sampleTask"
|
@@ -537,6 +537,8 @@ module Google
|
|
537
537
|
# ```
|
538
538
|
#
|
539
539
|
module Datastore
|
540
|
+
# rubocop:disable MethodLength
|
541
|
+
|
540
542
|
##
|
541
543
|
# Creates a new object for connecting to the Datastore service.
|
542
544
|
# Each call creates a new connection.
|
@@ -545,10 +547,11 @@ module Google
|
|
545
547
|
# [Authentication
|
546
548
|
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
547
549
|
#
|
548
|
-
# @param [String]
|
549
|
-
#
|
550
|
-
# @param [String, Hash]
|
551
|
-
#
|
550
|
+
# @param [String] project_id Identifier for a Datastore project. If not
|
551
|
+
# present, the default project for the credentials is used.
|
552
|
+
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
553
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
554
|
+
# Google::Auth::Credentials object. (See {Datastore::Credentials})
|
552
555
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
553
556
|
# the set of resources and operations that the connection can access.
|
554
557
|
# See [Using OAuth 2.0 to Access Google
|
@@ -562,6 +565,9 @@ module Google
|
|
562
565
|
# behavior of the API client. See Google::Gax::CallSettings. Optional.
|
563
566
|
# @param [String] emulator_host Datastore emulator host. Optional.
|
564
567
|
# If the param is nil, ENV["DATASTORE_EMULATOR_HOST"] will be used.
|
568
|
+
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
569
|
+
# @param [String] keyfile Alias for the `credentials` argument.
|
570
|
+
# Deprecated.
|
565
571
|
#
|
566
572
|
# @return [Google::Cloud::Datastore::Dataset]
|
567
573
|
#
|
@@ -569,8 +575,8 @@ module Google
|
|
569
575
|
# require "google/cloud/datastore"
|
570
576
|
#
|
571
577
|
# datastore = Google::Cloud::Datastore.new(
|
572
|
-
#
|
573
|
-
#
|
578
|
+
# project_id: "my-todo-project",
|
579
|
+
# credentials: "/path/to/keyfile.json"
|
574
580
|
# )
|
575
581
|
#
|
576
582
|
# task = datastore.entity "Task", "sampleTask" do |t|
|
@@ -582,36 +588,34 @@ module Google
|
|
582
588
|
#
|
583
589
|
# datastore.save task
|
584
590
|
#
|
585
|
-
def self.new
|
586
|
-
client_config: nil, emulator_host: nil
|
587
|
-
|
588
|
-
|
589
|
-
|
591
|
+
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
592
|
+
client_config: nil, emulator_host: nil, project: nil,
|
593
|
+
keyfile: nil
|
594
|
+
project_id ||= (project || Datastore::Dataset.default_project_id)
|
595
|
+
project_id = project_id.to_s # Always cast to a string
|
596
|
+
fail ArgumentError, "project_id is missing" if project_id.empty?
|
590
597
|
|
591
598
|
emulator_host ||= ENV["DATASTORE_EMULATOR_HOST"]
|
592
599
|
if emulator_host
|
593
|
-
return
|
594
|
-
|
595
|
-
|
596
|
-
host: emulator_host,
|
597
|
-
client_config: client_config))
|
600
|
+
return Datastore::Dataset.new(
|
601
|
+
Datastore::Service.new(
|
602
|
+
project_id, :this_channel_is_insecure,
|
603
|
+
host: emulator_host, client_config: client_config))
|
598
604
|
end
|
599
|
-
credentials = credentials_with_scope keyfile, scope
|
600
|
-
Google::Cloud::Datastore::Dataset.new(
|
601
|
-
Google::Cloud::Datastore::Service.new(
|
602
|
-
project, credentials, timeout: timeout,
|
603
|
-
client_config: client_config))
|
604
|
-
end
|
605
605
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
Google::Cloud::Datastore::Credentials.default(scope: scope)
|
611
|
-
else
|
612
|
-
Google::Cloud::Datastore::Credentials.new(keyfile, scope: scope)
|
606
|
+
credentials ||= keyfile
|
607
|
+
credentials ||= Datastore::Credentials.default(scope: scope)
|
608
|
+
unless credentials.is_a? Google::Auth::Credentials
|
609
|
+
credentials = Datastore::Credentials.new credentials, scope: scope
|
613
610
|
end
|
611
|
+
|
612
|
+
Datastore::Dataset.new(
|
613
|
+
Datastore::Service.new(
|
614
|
+
project_id, credentials,
|
615
|
+
timeout: timeout, client_config: client_config))
|
614
616
|
end
|
617
|
+
|
618
|
+
# rubocop:enable MethodLength
|
615
619
|
end
|
616
620
|
end
|
617
621
|
end
|
@@ -53,17 +53,6 @@ module Google
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
##
|
57
|
-
# @private Convert a Google::Protobuf::Map to a Hash
|
58
|
-
def self.map_to_hash map
|
59
|
-
if map.respond_to? :to_h
|
60
|
-
map.to_h
|
61
|
-
else
|
62
|
-
# Enumerable doesn't have to_h on ruby 2.0...
|
63
|
-
Hash[map.to_a]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
56
|
PROP_FILTER_OPS = { "<" => :LESS_THAN,
|
68
57
|
"lt" => :LESS_THAN,
|
69
58
|
"<=" => :LESS_THAN_OR_EQUAL,
|
@@ -13,25 +13,44 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "
|
16
|
+
require "googleauth"
|
17
17
|
|
18
18
|
module Google
|
19
19
|
module Cloud
|
20
20
|
module Datastore
|
21
21
|
##
|
22
|
-
#
|
22
|
+
# # Credentials
|
23
23
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# to the JSON keyfile downloaded from Google Cloud.
|
24
|
+
# Represents the authentication and authorization used to connect to the
|
25
|
+
# Datastore API.
|
27
26
|
#
|
28
|
-
# @
|
29
|
-
|
27
|
+
# @example
|
28
|
+
# require "google/cloud/datastore"
|
29
|
+
#
|
30
|
+
# keyfile = "/path/to/keyfile.json"
|
31
|
+
# creds = Google::Cloud::Datastore::Credentials.new keyfile
|
32
|
+
#
|
33
|
+
# datastore = Google::Cloud::Datastore.new(
|
34
|
+
# project_id: "my-todo-project",
|
35
|
+
# credentials: creds
|
36
|
+
# )
|
37
|
+
#
|
38
|
+
# datastore.project_id #=> "my-todo-project"
|
39
|
+
#
|
40
|
+
class Credentials < Google::Auth::Credentials
|
30
41
|
SCOPE = ["https://www.googleapis.com/auth/datastore"]
|
31
|
-
PATH_ENV_VARS = %w(
|
42
|
+
PATH_ENV_VARS = %w(DATASTORE_CREDENTIALS
|
43
|
+
DATASTORE_KEYFILE
|
44
|
+
GOOGLE_CLOUD_CREDENTIALS
|
45
|
+
GOOGLE_CLOUD_KEYFILE
|
32
46
|
GCLOUD_KEYFILE)
|
33
|
-
JSON_ENV_VARS = %w(
|
47
|
+
JSON_ENV_VARS = %w(DATASTORE_CREDENTIALS_JSON
|
48
|
+
DATASTORE_KEYFILE_JSON
|
49
|
+
GOOGLE_CLOUD_CREDENTIALS_JSON
|
50
|
+
GOOGLE_CLOUD_KEYFILE_JSON
|
34
51
|
GCLOUD_KEYFILE_JSON)
|
52
|
+
DEFAULT_PATHS = \
|
53
|
+
["~/.config/gcloud/application_default_credentials.json"]
|
35
54
|
end
|
36
55
|
end
|
37
56
|
end
|
@@ -71,19 +71,20 @@ module Google
|
|
71
71
|
# require "google/cloud/datastore"
|
72
72
|
#
|
73
73
|
# datastore = Google::Cloud::Datastore.new(
|
74
|
-
#
|
75
|
-
#
|
74
|
+
# project_id: "my-todo-project",
|
75
|
+
# credentials: "/path/to/keyfile.json"
|
76
76
|
# )
|
77
77
|
#
|
78
|
-
# datastore.
|
78
|
+
# datastore.project_id #=> "my-todo-project"
|
79
79
|
#
|
80
|
-
def
|
80
|
+
def project_id
|
81
81
|
service.project
|
82
82
|
end
|
83
|
+
alias_method :project, :project_id
|
83
84
|
|
84
85
|
##
|
85
|
-
# @private Default
|
86
|
-
def self.
|
86
|
+
# @private Default project_id.
|
87
|
+
def self.default_project_id
|
87
88
|
ENV["DATASTORE_DATASET"] ||
|
88
89
|
ENV["DATASTORE_PROJECT"] ||
|
89
90
|
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
@@ -73,17 +73,13 @@ module Google
|
|
73
73
|
alias_method :to_hash, :to_h
|
74
74
|
|
75
75
|
def to_grpc
|
76
|
-
|
76
|
+
# Convert to Hash with Google::Datastore::V1::Value values.
|
77
|
+
Hash[@hash.map { |k, v| [k.to_s, Convert.to_value(v)] }]
|
77
78
|
end
|
78
79
|
|
79
80
|
def self.from_grpc grpc_map
|
80
|
-
#
|
81
|
-
|
82
|
-
grpc_hash = Convert.map_to_hash grpc_map
|
83
|
-
grpc_array = grpc_hash.map do |(k, v)|
|
84
|
-
[k.to_s, Convert.from_value(v)]
|
85
|
-
end
|
86
|
-
new Hash[grpc_array]
|
81
|
+
# Convert to Hash of string keys and raw values.
|
82
|
+
new Hash[grpc_map.map { |k, v| [k.to_s, Convert.from_value(v)] }]
|
87
83
|
end
|
88
84
|
|
89
85
|
protected
|
@@ -55,7 +55,7 @@ module Google
|
|
55
55
|
return mocked_service if mocked_service
|
56
56
|
@service ||= V1::DatastoreClient.new(
|
57
57
|
service_path: host,
|
58
|
-
|
58
|
+
credentials: channel,
|
59
59
|
timeout: timeout,
|
60
60
|
client_config: client_config,
|
61
61
|
lib_name: "gccl",
|
@@ -83,7 +83,8 @@ module Google
|
|
83
83
|
read_options = generate_read_options consistency, transaction
|
84
84
|
|
85
85
|
execute do
|
86
|
-
service.lookup project,
|
86
|
+
service.lookup project, keys,
|
87
|
+
read_options: read_options, options: default_options
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
@@ -101,7 +102,7 @@ module Google
|
|
101
102
|
execute do
|
102
103
|
service.run_query project,
|
103
104
|
partition_id,
|
104
|
-
read_options,
|
105
|
+
read_options: read_options,
|
105
106
|
query: query,
|
106
107
|
gql_query: gql_query,
|
107
108
|
options: default_options
|
@@ -28,6 +28,7 @@ require "pathname"
|
|
28
28
|
require "google/gax"
|
29
29
|
|
30
30
|
require "google/datastore/v1/datastore_pb"
|
31
|
+
require "google/cloud/datastore/credentials"
|
31
32
|
|
32
33
|
module Google
|
33
34
|
module Cloud
|
@@ -60,15 +61,24 @@ module Google
|
|
60
61
|
"https://www.googleapis.com/auth/datastore"
|
61
62
|
].freeze
|
62
63
|
|
63
|
-
# @param
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# A
|
69
|
-
#
|
70
|
-
# A
|
71
|
-
#
|
64
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
65
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
66
|
+
# be many types.
|
67
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
68
|
+
# authenticating requests made by this client.
|
69
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
70
|
+
# credentials for this client.
|
71
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
72
|
+
# credentials for this client.
|
73
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
74
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
75
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
76
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
77
|
+
# metadata for requests, generally, to give OAuth credentials.
|
78
|
+
# @param scopes [Array<String>]
|
79
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
80
|
+
# an updater_proc is supplied.
|
81
|
+
# @param client_config [Hash]
|
72
82
|
# A Hash for call options for each method. See
|
73
83
|
# Google::Gax#construct_settings for the structure of
|
74
84
|
# this data. Falls back to the default config if not specified
|
@@ -80,11 +90,11 @@ module Google
|
|
80
90
|
port: DEFAULT_SERVICE_PORT,
|
81
91
|
channel: nil,
|
82
92
|
chan_creds: nil,
|
93
|
+
updater_proc: nil,
|
94
|
+
credentials: nil,
|
83
95
|
scopes: ALL_SCOPES,
|
84
96
|
client_config: {},
|
85
97
|
timeout: DEFAULT_TIMEOUT,
|
86
|
-
app_name: nil,
|
87
|
-
app_version: nil,
|
88
98
|
lib_name: nil,
|
89
99
|
lib_version: ""
|
90
100
|
# These require statements are intentionally placed here to initialize
|
@@ -93,14 +103,38 @@ module Google
|
|
93
103
|
require "google/gax/grpc"
|
94
104
|
require "google/datastore/v1/datastore_services_pb"
|
95
105
|
|
106
|
+
if channel || chan_creds || updater_proc
|
107
|
+
warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
|
108
|
+
"on 2017/09/08"
|
109
|
+
credentials ||= channel
|
110
|
+
credentials ||= chan_creds
|
111
|
+
credentials ||= updater_proc
|
112
|
+
end
|
113
|
+
if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT
|
114
|
+
warn "`service_path` and `port` parameters are deprecated and will be removed"
|
115
|
+
end
|
116
|
+
|
117
|
+
credentials ||= Google::Cloud::Datastore::Credentials.default
|
96
118
|
|
97
|
-
if
|
98
|
-
|
119
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
120
|
+
updater_proc = Google::Cloud::Datastore::Credentials.new(credentials).updater_proc
|
121
|
+
end
|
122
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
123
|
+
channel = credentials
|
124
|
+
end
|
125
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
126
|
+
chan_creds = credentials
|
127
|
+
end
|
128
|
+
if credentials.is_a?(Proc)
|
129
|
+
updater_proc = credentials
|
130
|
+
end
|
131
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
132
|
+
updater_proc = credentials.updater_proc
|
99
133
|
end
|
100
134
|
|
101
135
|
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
102
136
|
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
103
|
-
google_api_client << " gapic/0.
|
137
|
+
google_api_client << " gapic/0.1.0 gax/#{Google::Gax::VERSION}"
|
104
138
|
google_api_client << " grpc/#{GRPC::VERSION}"
|
105
139
|
google_api_client.freeze
|
106
140
|
|
@@ -124,6 +158,7 @@ module Google
|
|
124
158
|
port,
|
125
159
|
chan_creds: chan_creds,
|
126
160
|
channel: channel,
|
161
|
+
updater_proc: updater_proc,
|
127
162
|
scopes: scopes,
|
128
163
|
&Google::Datastore::V1::Datastore::Stub.method(:new)
|
129
164
|
)
|
@@ -152,6 +187,10 @@ module Google
|
|
152
187
|
@datastore_stub.method(:allocate_ids),
|
153
188
|
defaults["allocate_ids"]
|
154
189
|
)
|
190
|
+
@reserve_ids = Google::Gax.create_api_call(
|
191
|
+
@datastore_stub.method(:reserve_ids),
|
192
|
+
defaults["reserve_ids"]
|
193
|
+
)
|
155
194
|
end
|
156
195
|
|
157
196
|
# Service calls
|
@@ -160,37 +199,38 @@ module Google
|
|
160
199
|
#
|
161
200
|
# @param project_id [String]
|
162
201
|
# The ID of the project against which to make the request.
|
163
|
-
# @param
|
164
|
-
# The options for this lookup request.
|
165
|
-
# @param keys [Array<Google::Datastore::V1::Key>]
|
202
|
+
# @param keys [Array<Google::Datastore::V1::Key | Hash>]
|
166
203
|
# Keys of entities to look up.
|
204
|
+
# A hash of the same form as `Google::Datastore::V1::Key`
|
205
|
+
# can also be provided.
|
206
|
+
# @param read_options [Google::Datastore::V1::ReadOptions | Hash]
|
207
|
+
# The options for this lookup request.
|
208
|
+
# A hash of the same form as `Google::Datastore::V1::ReadOptions`
|
209
|
+
# can also be provided.
|
167
210
|
# @param options [Google::Gax::CallOptions]
|
168
211
|
# Overrides the default settings for this call, e.g, timeout,
|
169
212
|
# retries, etc.
|
170
213
|
# @return [Google::Datastore::V1::LookupResponse]
|
171
214
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
172
215
|
# @example
|
173
|
-
# require "google/cloud/datastore/v1
|
216
|
+
# require "google/cloud/datastore/v1"
|
174
217
|
#
|
175
|
-
#
|
176
|
-
# ReadOptions = Google::Datastore::V1::ReadOptions
|
177
|
-
#
|
178
|
-
# datastore_client = DatastoreClient.new
|
218
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
179
219
|
# project_id = ''
|
180
|
-
# read_options = ReadOptions.new
|
181
220
|
# keys = []
|
182
|
-
# response = datastore_client.lookup(project_id,
|
221
|
+
# response = datastore_client.lookup(project_id, keys)
|
183
222
|
|
184
223
|
def lookup \
|
185
224
|
project_id,
|
186
|
-
read_options,
|
187
225
|
keys,
|
226
|
+
read_options: nil,
|
188
227
|
options: nil
|
189
|
-
req =
|
228
|
+
req = {
|
190
229
|
project_id: project_id,
|
191
|
-
|
192
|
-
|
193
|
-
}.delete_if { |_, v| v.nil? }
|
230
|
+
keys: keys,
|
231
|
+
read_options: read_options
|
232
|
+
}.delete_if { |_, v| v.nil? }
|
233
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::LookupRequest)
|
194
234
|
@lookup.call(req, options)
|
195
235
|
end
|
196
236
|
|
@@ -198,49 +238,53 @@ module Google
|
|
198
238
|
#
|
199
239
|
# @param project_id [String]
|
200
240
|
# The ID of the project against which to make the request.
|
201
|
-
# @param partition_id [Google::Datastore::V1::PartitionId]
|
241
|
+
# @param partition_id [Google::Datastore::V1::PartitionId | Hash]
|
202
242
|
# Entities are partitioned into subsets, identified by a partition ID.
|
203
243
|
# Queries are scoped to a single partition.
|
204
244
|
# This partition ID is normalized with the standard default context
|
205
245
|
# partition ID.
|
206
|
-
#
|
246
|
+
# A hash of the same form as `Google::Datastore::V1::PartitionId`
|
247
|
+
# can also be provided.
|
248
|
+
# @param read_options [Google::Datastore::V1::ReadOptions | Hash]
|
207
249
|
# The options for this query.
|
208
|
-
#
|
250
|
+
# A hash of the same form as `Google::Datastore::V1::ReadOptions`
|
251
|
+
# can also be provided.
|
252
|
+
# @param query [Google::Datastore::V1::Query | Hash]
|
209
253
|
# The query to run.
|
210
|
-
#
|
254
|
+
# A hash of the same form as `Google::Datastore::V1::Query`
|
255
|
+
# can also be provided.
|
256
|
+
# @param gql_query [Google::Datastore::V1::GqlQuery | Hash]
|
211
257
|
# The GQL query to run.
|
258
|
+
# A hash of the same form as `Google::Datastore::V1::GqlQuery`
|
259
|
+
# can also be provided.
|
212
260
|
# @param options [Google::Gax::CallOptions]
|
213
261
|
# Overrides the default settings for this call, e.g, timeout,
|
214
262
|
# retries, etc.
|
215
263
|
# @return [Google::Datastore::V1::RunQueryResponse]
|
216
264
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
217
265
|
# @example
|
218
|
-
# require "google/cloud/datastore/v1
|
266
|
+
# require "google/cloud/datastore/v1"
|
219
267
|
#
|
220
|
-
#
|
221
|
-
# PartitionId = Google::Datastore::V1::PartitionId
|
222
|
-
# ReadOptions = Google::Datastore::V1::ReadOptions
|
223
|
-
#
|
224
|
-
# datastore_client = DatastoreClient.new
|
268
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
225
269
|
# project_id = ''
|
226
|
-
# partition_id =
|
227
|
-
#
|
228
|
-
# response = datastore_client.run_query(project_id, partition_id, read_options)
|
270
|
+
# partition_id = {}
|
271
|
+
# response = datastore_client.run_query(project_id, partition_id)
|
229
272
|
|
230
273
|
def run_query \
|
231
274
|
project_id,
|
232
275
|
partition_id,
|
233
|
-
read_options,
|
276
|
+
read_options: nil,
|
234
277
|
query: nil,
|
235
278
|
gql_query: nil,
|
236
279
|
options: nil
|
237
|
-
req =
|
280
|
+
req = {
|
238
281
|
project_id: project_id,
|
239
282
|
partition_id: partition_id,
|
240
283
|
read_options: read_options,
|
241
284
|
query: query,
|
242
285
|
gql_query: gql_query
|
243
|
-
}.delete_if { |_, v| v.nil? }
|
286
|
+
}.delete_if { |_, v| v.nil? }
|
287
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::RunQueryRequest)
|
244
288
|
@run_query.call(req, options)
|
245
289
|
end
|
246
290
|
|
@@ -248,26 +292,31 @@ module Google
|
|
248
292
|
#
|
249
293
|
# @param project_id [String]
|
250
294
|
# The ID of the project against which to make the request.
|
295
|
+
# @param transaction_options [Google::Datastore::V1::TransactionOptions | Hash]
|
296
|
+
# Options for a new transaction.
|
297
|
+
# A hash of the same form as `Google::Datastore::V1::TransactionOptions`
|
298
|
+
# can also be provided.
|
251
299
|
# @param options [Google::Gax::CallOptions]
|
252
300
|
# Overrides the default settings for this call, e.g, timeout,
|
253
301
|
# retries, etc.
|
254
302
|
# @return [Google::Datastore::V1::BeginTransactionResponse]
|
255
303
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
256
304
|
# @example
|
257
|
-
# require "google/cloud/datastore/v1
|
258
|
-
#
|
259
|
-
# DatastoreClient = Google::Cloud::Datastore::V1::DatastoreClient
|
305
|
+
# require "google/cloud/datastore/v1"
|
260
306
|
#
|
261
|
-
# datastore_client =
|
307
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
262
308
|
# project_id = ''
|
263
309
|
# response = datastore_client.begin_transaction(project_id)
|
264
310
|
|
265
311
|
def begin_transaction \
|
266
312
|
project_id,
|
313
|
+
transaction_options: nil,
|
267
314
|
options: nil
|
268
|
-
req =
|
269
|
-
project_id: project_id
|
270
|
-
|
315
|
+
req = {
|
316
|
+
project_id: project_id,
|
317
|
+
transaction_options: transaction_options
|
318
|
+
}.delete_if { |_, v| v.nil? }
|
319
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::BeginTransactionRequest)
|
271
320
|
@begin_transaction.call(req, options)
|
272
321
|
end
|
273
322
|
|
@@ -278,38 +327,37 @@ module Google
|
|
278
327
|
# The ID of the project against which to make the request.
|
279
328
|
# @param mode [Google::Datastore::V1::CommitRequest::Mode]
|
280
329
|
# The type of commit to perform. Defaults to +TRANSACTIONAL+.
|
281
|
-
# @param mutations [Array<Google::Datastore::V1::Mutation>]
|
330
|
+
# @param mutations [Array<Google::Datastore::V1::Mutation | Hash>]
|
282
331
|
# The mutations to perform.
|
283
332
|
#
|
284
333
|
# When mode is +TRANSACTIONAL+, mutations affecting a single entity are
|
285
334
|
# applied in order. The following sequences of mutations affecting a single
|
286
335
|
# entity are not permitted in a single +Commit+ request:
|
287
336
|
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
337
|
+
# * +insert+ followed by +insert+
|
338
|
+
# * +update+ followed by +insert+
|
339
|
+
# * +upsert+ followed by +insert+
|
340
|
+
# * +delete+ followed by +update+
|
292
341
|
#
|
293
342
|
# When mode is +NON_TRANSACTIONAL+, no two mutations may affect a single
|
294
343
|
# entity.
|
344
|
+
# A hash of the same form as `Google::Datastore::V1::Mutation`
|
345
|
+
# can also be provided.
|
295
346
|
# @param transaction [String]
|
296
347
|
# The identifier of the transaction associated with the commit. A
|
297
348
|
# transaction identifier is returned by a call to
|
298
|
-
# Datastore::BeginTransaction.
|
349
|
+
# {Google::Datastore::V1::Datastore::BeginTransaction Datastore::BeginTransaction}.
|
299
350
|
# @param options [Google::Gax::CallOptions]
|
300
351
|
# Overrides the default settings for this call, e.g, timeout,
|
301
352
|
# retries, etc.
|
302
353
|
# @return [Google::Datastore::V1::CommitResponse]
|
303
354
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
304
355
|
# @example
|
305
|
-
# require "google/cloud/datastore/v1
|
306
|
-
#
|
307
|
-
# DatastoreClient = Google::Cloud::Datastore::V1::DatastoreClient
|
308
|
-
# Mode = Google::Datastore::V1::CommitRequest::Mode
|
356
|
+
# require "google/cloud/datastore/v1"
|
309
357
|
#
|
310
|
-
# datastore_client =
|
358
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
311
359
|
# project_id = ''
|
312
|
-
# mode =
|
360
|
+
# mode = :MODE_UNSPECIFIED
|
313
361
|
# mutations = []
|
314
362
|
# response = datastore_client.commit(project_id, mode, mutations)
|
315
363
|
|
@@ -319,12 +367,13 @@ module Google
|
|
319
367
|
mutations,
|
320
368
|
transaction: nil,
|
321
369
|
options: nil
|
322
|
-
req =
|
370
|
+
req = {
|
323
371
|
project_id: project_id,
|
324
372
|
mode: mode,
|
325
373
|
mutations: mutations,
|
326
374
|
transaction: transaction
|
327
|
-
}.delete_if { |_, v| v.nil? }
|
375
|
+
}.delete_if { |_, v| v.nil? }
|
376
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::CommitRequest)
|
328
377
|
@commit.call(req, options)
|
329
378
|
end
|
330
379
|
|
@@ -334,18 +383,16 @@ module Google
|
|
334
383
|
# The ID of the project against which to make the request.
|
335
384
|
# @param transaction [String]
|
336
385
|
# The transaction identifier, returned by a call to
|
337
|
-
# Datastore::BeginTransaction.
|
386
|
+
# {Google::Datastore::V1::Datastore::BeginTransaction Datastore::BeginTransaction}.
|
338
387
|
# @param options [Google::Gax::CallOptions]
|
339
388
|
# Overrides the default settings for this call, e.g, timeout,
|
340
389
|
# retries, etc.
|
341
390
|
# @return [Google::Datastore::V1::RollbackResponse]
|
342
391
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
343
392
|
# @example
|
344
|
-
# require "google/cloud/datastore/v1
|
393
|
+
# require "google/cloud/datastore/v1"
|
345
394
|
#
|
346
|
-
#
|
347
|
-
#
|
348
|
-
# datastore_client = DatastoreClient.new
|
395
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
349
396
|
# project_id = ''
|
350
397
|
# transaction = ''
|
351
398
|
# response = datastore_client.rollback(project_id, transaction)
|
@@ -354,10 +401,11 @@ module Google
|
|
354
401
|
project_id,
|
355
402
|
transaction,
|
356
403
|
options: nil
|
357
|
-
req =
|
404
|
+
req = {
|
358
405
|
project_id: project_id,
|
359
406
|
transaction: transaction
|
360
|
-
}.delete_if { |_, v| v.nil? }
|
407
|
+
}.delete_if { |_, v| v.nil? }
|
408
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::RollbackRequest)
|
361
409
|
@rollback.call(req, options)
|
362
410
|
end
|
363
411
|
|
@@ -366,20 +414,20 @@ module Google
|
|
366
414
|
#
|
367
415
|
# @param project_id [String]
|
368
416
|
# The ID of the project against which to make the request.
|
369
|
-
# @param keys [Array<Google::Datastore::V1::Key>]
|
417
|
+
# @param keys [Array<Google::Datastore::V1::Key | Hash>]
|
370
418
|
# A list of keys with incomplete key paths for which to allocate IDs.
|
371
419
|
# No key may be reserved/read-only.
|
420
|
+
# A hash of the same form as `Google::Datastore::V1::Key`
|
421
|
+
# can also be provided.
|
372
422
|
# @param options [Google::Gax::CallOptions]
|
373
423
|
# Overrides the default settings for this call, e.g, timeout,
|
374
424
|
# retries, etc.
|
375
425
|
# @return [Google::Datastore::V1::AllocateIdsResponse]
|
376
426
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
377
427
|
# @example
|
378
|
-
# require "google/cloud/datastore/v1
|
379
|
-
#
|
380
|
-
# DatastoreClient = Google::Cloud::Datastore::V1::DatastoreClient
|
428
|
+
# require "google/cloud/datastore/v1"
|
381
429
|
#
|
382
|
-
# datastore_client =
|
430
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
383
431
|
# project_id = ''
|
384
432
|
# keys = []
|
385
433
|
# response = datastore_client.allocate_ids(project_id, keys)
|
@@ -388,12 +436,52 @@ module Google
|
|
388
436
|
project_id,
|
389
437
|
keys,
|
390
438
|
options: nil
|
391
|
-
req =
|
439
|
+
req = {
|
392
440
|
project_id: project_id,
|
393
441
|
keys: keys
|
394
|
-
}.delete_if { |_, v| v.nil? }
|
442
|
+
}.delete_if { |_, v| v.nil? }
|
443
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::AllocateIdsRequest)
|
395
444
|
@allocate_ids.call(req, options)
|
396
445
|
end
|
446
|
+
|
447
|
+
# Prevents the supplied keys' IDs from being auto-allocated by Cloud
|
448
|
+
# Datastore.
|
449
|
+
#
|
450
|
+
# @param project_id [String]
|
451
|
+
# The ID of the project against which to make the request.
|
452
|
+
# @param keys [Array<Google::Datastore::V1::Key | Hash>]
|
453
|
+
# A list of keys with complete key paths whose numeric IDs should not be
|
454
|
+
# auto-allocated.
|
455
|
+
# A hash of the same form as `Google::Datastore::V1::Key`
|
456
|
+
# can also be provided.
|
457
|
+
# @param database_id [String]
|
458
|
+
# If not empty, the ID of the database against which to make the request.
|
459
|
+
# @param options [Google::Gax::CallOptions]
|
460
|
+
# Overrides the default settings for this call, e.g, timeout,
|
461
|
+
# retries, etc.
|
462
|
+
# @return [Google::Datastore::V1::ReserveIdsResponse]
|
463
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
464
|
+
# @example
|
465
|
+
# require "google/cloud/datastore/v1"
|
466
|
+
#
|
467
|
+
# datastore_client = Google::Cloud::Datastore::V1.new
|
468
|
+
# project_id = ''
|
469
|
+
# keys = []
|
470
|
+
# response = datastore_client.reserve_ids(project_id, keys)
|
471
|
+
|
472
|
+
def reserve_ids \
|
473
|
+
project_id,
|
474
|
+
keys,
|
475
|
+
database_id: nil,
|
476
|
+
options: nil
|
477
|
+
req = {
|
478
|
+
project_id: project_id,
|
479
|
+
keys: keys,
|
480
|
+
database_id: database_id
|
481
|
+
}.delete_if { |_, v| v.nil? }
|
482
|
+
req = Google::Gax::to_proto(req, Google::Datastore::V1::ReserveIdsRequest)
|
483
|
+
@reserve_ids.call(req, options)
|
484
|
+
end
|
397
485
|
end
|
398
486
|
end
|
399
487
|
end
|