google-cloud-datastore 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/google/cloud/datastore/dataset/lookup_results.rb +14 -3
- data/lib/google/cloud/datastore/dataset/query_results.rb +23 -3
- data/lib/google/cloud/datastore/dataset.rb +43 -12
- data/lib/google/cloud/datastore/key.rb +24 -2
- data/lib/google/cloud/datastore/read_only_transaction.rb +11 -3
- data/lib/google/cloud/datastore/service.rb +40 -18
- data/lib/google/cloud/datastore/version.rb +1 -1
- data/lib/google/cloud/datastore.rb +18 -6
- data/lib/google-cloud-datastore.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1471082bad6f76859fd0172a40bac47c81c31d3bc7f42e0f5135547f280307a6
|
4
|
+
data.tar.gz: a182edc1deadbfe697c45fad2bcde90379c58d07985833fd3f4bca64584bfaf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ae448187ef6bbd842bcafcb2c6cbd107b81e4dfb55b72bbfb62857af387a82b4361cc3b86cdf00ab2657a5b98bcf6f51c1caf2090b2c922f8f3db03016e19a
|
7
|
+
data.tar.gz: 25725fc96567a06df8c6b75c4b29f9ff8077e77b59a7bb1c31d0c384a9a0d880d9e0d807653f75986c56d428dbcf7aaf09fa4074f7335eef76dcc520e21c9304
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.6.0 (2023-02-13)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Added support for snapshot read ([#19422](https://github.com/googleapis/google-cloud-ruby/issues/19422))
|
8
|
+
|
9
|
+
### 2.5.0 (2023-02-09)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* Added support for multiple database ([#20038](https://github.com/googleapis/google-cloud-ruby/issues/20038))
|
14
|
+
|
3
15
|
### 2.4.0 (2023-02-02)
|
4
16
|
|
5
17
|
#### Features
|
@@ -53,6 +53,15 @@ module Google
|
|
53
53
|
# descriptions.missing #=> raise NoMethodError
|
54
54
|
#
|
55
55
|
class LookupResults < DelegateClass(::Array)
|
56
|
+
##
|
57
|
+
# The time at which these entities were read or found missing.
|
58
|
+
attr_reader :response_read_time
|
59
|
+
|
60
|
+
##
|
61
|
+
# Time at which the entities are being read. This would not be
|
62
|
+
# older than 270 seconds.
|
63
|
+
attr_reader :read_time
|
64
|
+
|
56
65
|
##
|
57
66
|
# Keys that were not looked up due to resource constraints.
|
58
67
|
attr_accessor :deferred
|
@@ -110,9 +119,9 @@ module Google
|
|
110
119
|
ensure_service!
|
111
120
|
lookup_res = @service.lookup(
|
112
121
|
*Array(@deferred).flatten.map(&:to_grpc),
|
113
|
-
consistency: @consistency, transaction: @transaction
|
122
|
+
consistency: @consistency, transaction: @transaction, read_time: @read_time
|
114
123
|
)
|
115
|
-
self.class.from_grpc lookup_res, @service, @consistency
|
124
|
+
self.class.from_grpc lookup_res, @service, @consistency, nil, @read_time
|
116
125
|
end
|
117
126
|
|
118
127
|
##
|
@@ -187,7 +196,7 @@ module Google
|
|
187
196
|
##
|
188
197
|
# @private New Dataset::LookupResults from a
|
189
198
|
# Google::Dataset::V1::LookupResponse object.
|
190
|
-
def self.from_grpc lookup_res, service, consistency = nil, transaction = nil
|
199
|
+
def self.from_grpc lookup_res, service, consistency = nil, transaction = nil, read_time = nil
|
191
200
|
entities = to_gcloud_entities lookup_res.found
|
192
201
|
deferred = to_gcloud_keys lookup_res.deferred
|
193
202
|
missing = to_gcloud_entities lookup_res.missing
|
@@ -195,6 +204,8 @@ module Google
|
|
195
204
|
lr.instance_variable_set :@service, service
|
196
205
|
lr.instance_variable_set :@consistency, consistency
|
197
206
|
lr.instance_variable_set :@transaction, transaction
|
207
|
+
lr.instance_variable_set :@read_time, read_time
|
208
|
+
lr.instance_variable_set :@response_read_time, lookup_res.read_time
|
198
209
|
lr.instance_variable_set :@deferred, deferred
|
199
210
|
lr.instance_variable_set :@missing, missing
|
200
211
|
end
|
@@ -72,6 +72,24 @@ module Google
|
|
72
72
|
# * `:NO_MORE_RESULTS`
|
73
73
|
attr_reader :more_results
|
74
74
|
|
75
|
+
##
|
76
|
+
# Read timestamp this batch was returned from.
|
77
|
+
# This applies to the range of results from the query's `start_cursor` (or
|
78
|
+
# the beginning of the query if no cursor was given) to this batch's
|
79
|
+
# `end_cursor` (not the query's `end_cursor`).
|
80
|
+
#
|
81
|
+
# In a single transaction, subsequent query result batches for the same query
|
82
|
+
# can have a greater timestamp. Each batch's read timestamp
|
83
|
+
# is valid for all preceding batches.
|
84
|
+
# This value will not be set for eventually consistent queries in Cloud
|
85
|
+
# Datastore.
|
86
|
+
attr_reader :batch_read_time
|
87
|
+
|
88
|
+
##
|
89
|
+
# Time at which the entities are being read. This would not be
|
90
|
+
# older than 270 seconds.
|
91
|
+
attr_reader :read_time
|
92
|
+
|
75
93
|
##
|
76
94
|
# @private
|
77
95
|
attr_accessor :service, :namespace, :cursors, :query
|
@@ -162,8 +180,8 @@ module Google
|
|
162
180
|
# Reduce the limit by the number of entities returned in the current batch
|
163
181
|
query.limit.value -= count
|
164
182
|
end
|
165
|
-
query_res = service.run_query query, namespace
|
166
|
-
self.class.from_grpc query_res, service, namespace, query
|
183
|
+
query_res = service.run_query query, namespace, read_time: read_time
|
184
|
+
self.class.from_grpc query_res, service, namespace, query, read_time
|
167
185
|
end
|
168
186
|
|
169
187
|
##
|
@@ -360,7 +378,7 @@ module Google
|
|
360
378
|
##
|
361
379
|
# @private New Dataset::QueryResults from a
|
362
380
|
# Google::Dataset::V1::RunQueryResponse object.
|
363
|
-
def self.from_grpc query_res, service, namespace, query
|
381
|
+
def self.from_grpc query_res, service, namespace, query, read_time = nil
|
364
382
|
r, c = Array(query_res.batch.entity_results).map do |result|
|
365
383
|
[Entity.from_grpc(result.entity), Cursor.from_grpc(result.cursor)]
|
366
384
|
end.transpose
|
@@ -373,6 +391,8 @@ module Google
|
|
373
391
|
qr.service = service
|
374
392
|
qr.namespace = namespace
|
375
393
|
qr.query = query_res.query || query
|
394
|
+
qr.instance_variable_set :@read_time, read_time
|
395
|
+
qr.instance_variable_set :@batch_read_time, query_res.batch.read_time
|
376
396
|
end
|
377
397
|
end
|
378
398
|
|
@@ -84,6 +84,26 @@ module Google
|
|
84
84
|
end
|
85
85
|
alias project project_id
|
86
86
|
|
87
|
+
##
|
88
|
+
# The Datastore database connected to.
|
89
|
+
#
|
90
|
+
# @return [String] ID of the database
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# require "google/cloud/datastore"
|
94
|
+
#
|
95
|
+
# datastore = Google::Cloud::Datastore.new(
|
96
|
+
# project_id: "my-todo-project",
|
97
|
+
# credentials: "/path/to/keyfile.json",
|
98
|
+
# database_id: "my-database"
|
99
|
+
# )
|
100
|
+
#
|
101
|
+
# datastore.database_id #=> "my-database"
|
102
|
+
#
|
103
|
+
def database_id
|
104
|
+
service.database
|
105
|
+
end
|
106
|
+
|
87
107
|
##
|
88
108
|
# Generate IDs for a Key before creating an entity.
|
89
109
|
#
|
@@ -317,6 +337,8 @@ module Google
|
|
317
337
|
# [Eventual Consistency in Google Cloud
|
318
338
|
# Datastore](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/#h.tf76fya5nqk8)
|
319
339
|
# for more information.
|
340
|
+
# @param [Time] read_time Reads entities as they were at the given time.
|
341
|
+
# This may not be older than 270 seconds. Optional
|
320
342
|
#
|
321
343
|
# @return [Google::Cloud::Datastore::Entity, nil]
|
322
344
|
#
|
@@ -335,12 +357,12 @@ module Google
|
|
335
357
|
#
|
336
358
|
# task = datastore.find "Task", "sampleTask"
|
337
359
|
#
|
338
|
-
def find key_or_kind, id_or_name = nil, consistency: nil
|
360
|
+
def find key_or_kind, id_or_name = nil, consistency: nil, read_time: nil
|
339
361
|
key = key_or_kind
|
340
362
|
unless key.is_a? Google::Cloud::Datastore::Key
|
341
363
|
key = Key.new key_or_kind, id_or_name
|
342
364
|
end
|
343
|
-
find_all(key, consistency: consistency).first
|
365
|
+
find_all(key, consistency: consistency, read_time: read_time).first
|
344
366
|
end
|
345
367
|
alias get find
|
346
368
|
|
@@ -357,6 +379,8 @@ module Google
|
|
357
379
|
# [Eventual Consistency in Google Cloud
|
358
380
|
# Datastore](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/#h.tf76fya5nqk8)
|
359
381
|
# for more information.
|
382
|
+
# @param [Time] read_time Reads entities as they were at the given time.
|
383
|
+
# This may not be older than 270 seconds. Optional
|
360
384
|
#
|
361
385
|
# @return [Google::Cloud::Datastore::Dataset::LookupResults]
|
362
386
|
#
|
@@ -369,12 +393,12 @@ module Google
|
|
369
393
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
370
394
|
# tasks = datastore.find_all task_key1, task_key2
|
371
395
|
#
|
372
|
-
def find_all *keys, consistency: nil
|
396
|
+
def find_all *keys, consistency: nil, read_time: nil
|
373
397
|
ensure_service!
|
374
398
|
check_consistency! consistency
|
375
399
|
lookup_res = service.lookup(*Array(keys).flatten.map(&:to_grpc),
|
376
|
-
consistency: consistency)
|
377
|
-
LookupResults.from_grpc lookup_res, service, consistency
|
400
|
+
consistency: consistency, read_time: read_time)
|
401
|
+
LookupResults.from_grpc lookup_res, service, consistency, nil, read_time
|
378
402
|
end
|
379
403
|
alias lookup find_all
|
380
404
|
|
@@ -391,6 +415,8 @@ module Google
|
|
391
415
|
# [Eventual Consistency in Google Cloud
|
392
416
|
# Datastore](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/#h.tf76fya5nqk8)
|
393
417
|
# for more information.
|
418
|
+
# @param [Time] read_time Reads entities as they were at the given time.
|
419
|
+
# This may not be older than 270 seconds. Optional
|
394
420
|
#
|
395
421
|
# @return [Google::Cloud::Datastore::Dataset::QueryResults]
|
396
422
|
#
|
@@ -441,16 +467,16 @@ module Google
|
|
441
467
|
# done: false
|
442
468
|
# tasks = datastore.run gql_query, namespace: "example-ns"
|
443
469
|
#
|
444
|
-
def run query, namespace: nil, consistency: nil
|
470
|
+
def run query, namespace: nil, consistency: nil, read_time: nil
|
445
471
|
ensure_service!
|
446
472
|
unless query.is_a?(Query) || query.is_a?(GqlQuery)
|
447
473
|
raise ArgumentError, "Cannot run a #{query.class} object."
|
448
474
|
end
|
449
475
|
check_consistency! consistency
|
450
476
|
query_res = service.run_query query.to_grpc, namespace,
|
451
|
-
consistency: consistency
|
477
|
+
consistency: consistency, read_time: read_time
|
452
478
|
QueryResults.from_grpc query_res, service, namespace,
|
453
|
-
query.to_grpc.dup
|
479
|
+
query.to_grpc.dup, read_time
|
454
480
|
end
|
455
481
|
alias run_query run
|
456
482
|
|
@@ -462,6 +488,8 @@ module Google
|
|
462
488
|
# @param [Symbol] consistency The non-transactional read consistency to
|
463
489
|
# use. Cannot be set to `:strong` for global queries. Accepted values
|
464
490
|
# are `:eventual` and `:strong`.
|
491
|
+
# @param [Time] read_time Reads entities as they were at the given time.
|
492
|
+
# This may not be older than 270 seconds. Optional
|
465
493
|
#
|
466
494
|
# The default consistency depends on the type of query used. See
|
467
495
|
# [Eventual Consistency in Google Cloud
|
@@ -525,14 +553,14 @@ module Google
|
|
525
553
|
# done: false
|
526
554
|
# res = datastore.run_aggregation gql_query, namespace: "example-ns"
|
527
555
|
#
|
528
|
-
def run_aggregation aggregate_query, namespace: nil, consistency: nil
|
556
|
+
def run_aggregation aggregate_query, namespace: nil, consistency: nil, read_time: nil
|
529
557
|
ensure_service!
|
530
558
|
unless aggregate_query.is_a?(AggregateQuery) || aggregate_query.is_a?(GqlQuery)
|
531
559
|
raise ArgumentError, "Cannot run a #{aggregate_query.class} object."
|
532
560
|
end
|
533
561
|
check_consistency! consistency
|
534
562
|
aggregate_query_res = service.run_aggregation_query aggregate_query.to_grpc, namespace,
|
535
|
-
consistency: consistency
|
563
|
+
consistency: consistency, read_time: read_time
|
536
564
|
AggregateQueryResults.from_grpc aggregate_query_res
|
537
565
|
end
|
538
566
|
|
@@ -657,6 +685,9 @@ module Google
|
|
657
685
|
# @see https://cloud.google.com/datastore/docs/concepts/transactions
|
658
686
|
# Transactions
|
659
687
|
#
|
688
|
+
# @param [Time] read_time Reads entities at the given time.
|
689
|
+
# This may not be older than 60 seconds. Optional
|
690
|
+
#
|
660
691
|
# @yield [tx] a block yielding a new transaction
|
661
692
|
# @yieldparam [ReadOnlyTransaction] tx the transaction object
|
662
693
|
#
|
@@ -678,8 +709,8 @@ module Google
|
|
678
709
|
# end
|
679
710
|
# end
|
680
711
|
#
|
681
|
-
def read_only_transaction
|
682
|
-
tx = ReadOnlyTransaction.new service
|
712
|
+
def read_only_transaction read_time: nil
|
713
|
+
tx = ReadOnlyTransaction.new service, read_time: read_time
|
683
714
|
return tx unless block_given?
|
684
715
|
|
685
716
|
begin
|
@@ -69,6 +69,27 @@ module Google
|
|
69
69
|
alias dataset_id project
|
70
70
|
alias dataset_id= project=
|
71
71
|
|
72
|
+
##
|
73
|
+
# The database of the Key.
|
74
|
+
#
|
75
|
+
# @return [String]
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# require "google/cloud/datastore"
|
79
|
+
#
|
80
|
+
# datastore = Google::Cloud::Datastore.new(
|
81
|
+
# project: "my-todo-project",
|
82
|
+
# database: "my-todo-database",
|
83
|
+
# keyfile: "/path/to/keyfile.json"
|
84
|
+
# )
|
85
|
+
#
|
86
|
+
# task = datastore.find "Task", "sampleTask"
|
87
|
+
# task.key.database #=> "my-todo-database"
|
88
|
+
#
|
89
|
+
attr_accessor :database
|
90
|
+
alias database_id database
|
91
|
+
alias database_id= database=
|
92
|
+
|
72
93
|
##
|
73
94
|
# The namespace of the Key.
|
74
95
|
#
|
@@ -281,9 +302,9 @@ module Google
|
|
281
302
|
Google::Cloud::Datastore::V1::Key::PathElement.new path_args
|
282
303
|
end
|
283
304
|
grpc = Google::Cloud::Datastore::V1::Key.new path: grpc_path
|
284
|
-
if project || namespace
|
305
|
+
if project || database || namespace
|
285
306
|
grpc.partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
|
286
|
-
project_id: project.to_s, namespace_id: namespace.to_s
|
307
|
+
project_id: project.to_s, database_id: database.to_s, namespace_id: namespace.to_s
|
287
308
|
)
|
288
309
|
end
|
289
310
|
grpc
|
@@ -304,6 +325,7 @@ module Google
|
|
304
325
|
end
|
305
326
|
if key_grpc.partition_id
|
306
327
|
key.project = key_grpc.partition_id.project_id
|
328
|
+
key.database = key_grpc.partition_id.database_id
|
307
329
|
key.namespace = key_grpc.partition_id.namespace_id
|
308
330
|
end
|
309
331
|
key.parent = Key.from_grpc key_grpc if key_grpc.path.count.positive?
|
@@ -59,13 +59,22 @@ module Google
|
|
59
59
|
# @private The Service object.
|
60
60
|
attr_accessor :service
|
61
61
|
|
62
|
+
##
|
63
|
+
# Reads entities at the given time.
|
64
|
+
# This may not be older than 60 seconds.
|
65
|
+
attr_reader :read_time
|
66
|
+
|
62
67
|
##
|
63
68
|
# @private Creates a new ReadOnlyTransaction instance.
|
64
69
|
# Takes a Service instead of project and Credentials.
|
65
70
|
#
|
66
|
-
|
71
|
+
# @param [Time] read_time Reads documents as they were at the given time.
|
72
|
+
# This may not be older than 270 seconds. Optional
|
73
|
+
#
|
74
|
+
def initialize service, read_time: nil
|
67
75
|
@service = service
|
68
76
|
reset!
|
77
|
+
@read_time = read_time
|
69
78
|
start
|
70
79
|
end
|
71
80
|
|
@@ -194,9 +203,8 @@ module Google
|
|
194
203
|
#
|
195
204
|
def start
|
196
205
|
raise TransactionError, "Transaction already opened." unless @id.nil?
|
197
|
-
|
198
206
|
ensure_service!
|
199
|
-
tx_res = service.begin_transaction read_only: true
|
207
|
+
tx_res = service.begin_transaction read_only: true, read_time: @read_time
|
200
208
|
@id = tx_res.transaction
|
201
209
|
end
|
202
210
|
alias begin_transaction start
|
@@ -29,14 +29,16 @@ module Google
|
|
29
29
|
attr_accessor :credentials
|
30
30
|
attr_accessor :host
|
31
31
|
attr_accessor :timeout
|
32
|
+
attr_accessor :database
|
32
33
|
|
33
34
|
##
|
34
35
|
# Creates a new Service instance.
|
35
|
-
def initialize project, credentials, host: nil, timeout: nil
|
36
|
+
def initialize project, credentials, database, host: nil, timeout: nil
|
36
37
|
@project = project
|
37
38
|
@credentials = credentials
|
38
39
|
@host = host
|
39
40
|
@timeout = timeout
|
41
|
+
@database = database
|
40
42
|
end
|
41
43
|
|
42
44
|
def service
|
@@ -47,34 +49,34 @@ module Google
|
|
47
49
|
config.endpoint = host if host
|
48
50
|
config.lib_name = "gccl"
|
49
51
|
config.lib_version = Google::Cloud::Datastore::VERSION
|
50
|
-
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
52
|
+
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}/databases/#{database}" }
|
51
53
|
end
|
52
54
|
end
|
55
|
+
|
53
56
|
attr_accessor :mocked_service
|
54
57
|
|
55
58
|
##
|
56
59
|
# Allocate IDs for incomplete keys.
|
57
60
|
# (This is useful for referencing an entity before it is inserted.)
|
58
61
|
def allocate_ids *incomplete_keys
|
59
|
-
service.allocate_ids project_id: project, keys: incomplete_keys
|
62
|
+
service.allocate_ids project_id: project, database_id: database, keys: incomplete_keys
|
60
63
|
end
|
61
64
|
|
62
65
|
##
|
63
66
|
# Look up entities by keys.
|
64
|
-
def lookup *keys, consistency: nil, transaction: nil
|
65
|
-
read_options = generate_read_options consistency, transaction
|
66
|
-
|
67
|
-
service.lookup project_id: project, keys: keys, read_options: read_options
|
67
|
+
def lookup *keys, consistency: nil, transaction: nil, read_time: nil
|
68
|
+
read_options = generate_read_options consistency, transaction, read_time
|
69
|
+
service.lookup project_id: project, database_id: database, keys: keys, read_options: read_options
|
68
70
|
end
|
69
71
|
|
70
72
|
# Query for entities.
|
71
|
-
def run_query query, namespace = nil, consistency: nil, transaction: nil
|
73
|
+
def run_query query, namespace = nil, consistency: nil, transaction: nil, read_time: nil
|
72
74
|
gql_query = nil
|
73
75
|
if query.is_a? Google::Cloud::Datastore::V1::GqlQuery
|
74
76
|
gql_query = query
|
75
77
|
query = nil
|
76
78
|
end
|
77
|
-
read_options = generate_read_options consistency, transaction
|
79
|
+
read_options = generate_read_options consistency, transaction, read_time
|
78
80
|
if namespace
|
79
81
|
partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
|
80
82
|
namespace_id: namespace
|
@@ -82,6 +84,7 @@ module Google
|
|
82
84
|
end
|
83
85
|
|
84
86
|
service.run_query project_id: project,
|
87
|
+
database_id: database,
|
85
88
|
partition_id: partition_id,
|
86
89
|
read_options: read_options,
|
87
90
|
query: query,
|
@@ -89,13 +92,13 @@ module Google
|
|
89
92
|
end
|
90
93
|
|
91
94
|
## Query for aggregates
|
92
|
-
def run_aggregation_query query, namespace = nil, consistency: nil, transaction: nil
|
95
|
+
def run_aggregation_query query, namespace = nil, consistency: nil, transaction: nil, read_time: nil
|
93
96
|
gql_query = nil
|
94
97
|
if query.is_a? Google::Cloud::Datastore::V1::GqlQuery
|
95
98
|
gql_query = query
|
96
99
|
query = nil
|
97
100
|
end
|
98
|
-
read_options = generate_read_options consistency, transaction
|
101
|
+
read_options = generate_read_options consistency, transaction, read_time
|
99
102
|
if namespace
|
100
103
|
partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
|
101
104
|
namespace_id: namespace
|
@@ -111,11 +114,13 @@ module Google
|
|
111
114
|
|
112
115
|
##
|
113
116
|
# Begin a new transaction.
|
114
|
-
def begin_transaction read_only: nil, previous_transaction: nil
|
117
|
+
def begin_transaction read_only: nil, previous_transaction: nil, read_time: nil
|
115
118
|
if read_only
|
116
119
|
transaction_options = Google::Cloud::Datastore::V1::TransactionOptions.new
|
117
120
|
transaction_options.read_only = \
|
118
|
-
Google::Cloud::Datastore::V1::TransactionOptions::ReadOnly.new
|
121
|
+
Google::Cloud::Datastore::V1::TransactionOptions::ReadOnly.new \
|
122
|
+
read_time: read_time_to_timestamp(read_time)
|
123
|
+
|
119
124
|
end
|
120
125
|
if previous_transaction
|
121
126
|
transaction_options ||= \
|
@@ -125,7 +130,7 @@ module Google
|
|
125
130
|
)
|
126
131
|
transaction_options.read_write = rw
|
127
132
|
end
|
128
|
-
service.begin_transaction project_id: project, transaction_options: transaction_options
|
133
|
+
service.begin_transaction project_id: project, database_id: database, transaction_options: transaction_options
|
129
134
|
end
|
130
135
|
|
131
136
|
##
|
@@ -133,22 +138,23 @@ module Google
|
|
133
138
|
# some entities.
|
134
139
|
def commit mutations, transaction: nil
|
135
140
|
mode = transaction.nil? ? :NON_TRANSACTIONAL : :TRANSACTIONAL
|
136
|
-
service.commit project_id: project,
|
141
|
+
service.commit project_id: project, database_id: database, mode: mode,
|
142
|
+
mutations: mutations, transaction: transaction
|
137
143
|
end
|
138
144
|
|
139
145
|
##
|
140
146
|
# Roll back a transaction.
|
141
147
|
def rollback transaction
|
142
|
-
service.rollback project_id: project, transaction: transaction
|
148
|
+
service.rollback project_id: project, database_id: database, transaction: transaction
|
143
149
|
end
|
144
150
|
|
145
151
|
def inspect
|
146
|
-
"#{self.class}(#{@project})"
|
152
|
+
"#{self.class}(#{@project})(#{database})"
|
147
153
|
end
|
148
154
|
|
149
155
|
protected
|
150
156
|
|
151
|
-
def generate_read_options consistency, transaction
|
157
|
+
def generate_read_options consistency, transaction, read_time
|
152
158
|
if consistency == :eventual
|
153
159
|
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
154
160
|
read_consistency: :EVENTUAL
|
@@ -161,9 +167,25 @@ module Google
|
|
161
167
|
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
162
168
|
transaction: transaction
|
163
169
|
)
|
170
|
+
elsif read_time
|
171
|
+
return Google::Cloud::Datastore::V1::ReadOptions.new(
|
172
|
+
read_time: read_time_to_timestamp(read_time)
|
173
|
+
)
|
164
174
|
end
|
165
175
|
nil
|
166
176
|
end
|
177
|
+
|
178
|
+
def read_time_to_timestamp time
|
179
|
+
return nil if time.nil?
|
180
|
+
|
181
|
+
# Force the object to be a Time object.
|
182
|
+
time = time.to_time.utc
|
183
|
+
|
184
|
+
Google::Protobuf::Timestamp.new(
|
185
|
+
seconds: time.to_i,
|
186
|
+
nanos: time.usec * 1000
|
187
|
+
)
|
188
|
+
end
|
167
189
|
end
|
168
190
|
end
|
169
191
|
end
|
@@ -74,6 +74,8 @@ module Google
|
|
74
74
|
# If the param is nil, uses the default endpoint.
|
75
75
|
# @param [String] emulator_host Datastore emulator host. Optional.
|
76
76
|
# If the param is nil, uses the value of the `emulator_host` config.
|
77
|
+
# @param [String] database_id Identifier for a Datastore database in the project. If not
|
78
|
+
# present, the default database of the project will be used.
|
77
79
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
78
80
|
# @param [String] keyfile Alias for the `credentials` argument.
|
79
81
|
# Deprecated.
|
@@ -103,13 +105,15 @@ module Google
|
|
103
105
|
timeout: nil,
|
104
106
|
endpoint: nil,
|
105
107
|
emulator_host: nil,
|
108
|
+
database_id: nil,
|
106
109
|
project: nil,
|
107
110
|
keyfile: nil
|
108
|
-
project_id
|
109
|
-
scope
|
110
|
-
timeout
|
111
|
-
endpoint
|
111
|
+
project_id = get_project_id project_id, project
|
112
|
+
scope ||= configure.scope
|
113
|
+
timeout ||= configure.timeout
|
114
|
+
endpoint ||= configure.endpoint
|
112
115
|
emulator_host ||= configure.emulator_host
|
116
|
+
database_id ||= configure.database_id
|
113
117
|
|
114
118
|
if emulator_host
|
115
119
|
project_id = project_id.to_s # Always cast to a string
|
@@ -117,7 +121,7 @@ module Google
|
|
117
121
|
|
118
122
|
return Datastore::Dataset.new(
|
119
123
|
Datastore::Service.new(
|
120
|
-
project_id, :this_channel_is_insecure,
|
124
|
+
project_id, :this_channel_is_insecure, database_id,
|
121
125
|
host: emulator_host, timeout: timeout
|
122
126
|
)
|
123
127
|
)
|
@@ -136,7 +140,7 @@ module Google
|
|
136
140
|
|
137
141
|
Datastore::Dataset.new(
|
138
142
|
Datastore::Service.new(
|
139
|
-
project_id, credentials,
|
143
|
+
project_id, credentials, database_id,
|
140
144
|
host: endpoint, timeout: timeout
|
141
145
|
)
|
142
146
|
)
|
@@ -175,6 +179,14 @@ module Google
|
|
175
179
|
Google::Cloud.configure.datastore
|
176
180
|
end
|
177
181
|
|
182
|
+
##
|
183
|
+
# @private Default project.
|
184
|
+
def self.get_project_id project_id, project
|
185
|
+
project_id || project || Google::Cloud.configure.datastore.project_id ||
|
186
|
+
Google::Cloud.configure.project_id ||
|
187
|
+
Google::Cloud.env.project_id
|
188
|
+
end
|
189
|
+
|
178
190
|
##
|
179
191
|
# @private Default project.
|
180
192
|
def self.default_project_id
|
@@ -67,9 +67,10 @@ module Google
|
|
67
67
|
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
68
68
|
# datastore = gcloud.datastore scope: platform_scope
|
69
69
|
#
|
70
|
-
def datastore scope: nil, timeout: nil
|
70
|
+
def datastore scope: nil, timeout: nil, database_id: nil
|
71
71
|
Google::Cloud.datastore @project, @keyfile,
|
72
|
-
scope: scope, timeout: (timeout || @timeout)
|
72
|
+
scope: scope, timeout: (timeout || @timeout),
|
73
|
+
database_id: database_id
|
73
74
|
end
|
74
75
|
|
75
76
|
##
|
@@ -112,11 +113,12 @@ module Google
|
|
112
113
|
# datastore.save task
|
113
114
|
#
|
114
115
|
def self.datastore project_id = nil, credentials = nil, scope: nil,
|
115
|
-
timeout: nil
|
116
|
+
timeout: nil, database_id: nil
|
116
117
|
require "google/cloud/datastore"
|
117
118
|
Google::Cloud::Datastore.new project_id: project_id,
|
118
119
|
credentials: credentials,
|
119
|
-
scope: scope, timeout: timeout
|
120
|
+
scope: scope, timeout: timeout,
|
121
|
+
database_id: database_id
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -136,8 +138,7 @@ Google::Cloud.configure.add_config! :datastore do |config|
|
|
136
138
|
ENV["DATASTORE_EMULATOR_HOST"]
|
137
139
|
end
|
138
140
|
default_scopes = [
|
139
|
-
"https://www.googleapis.com/auth/cloud-platform",
|
140
|
-
"https://www.googleapis.com/auth/datastore"
|
141
|
+
"https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/datastore"
|
141
142
|
]
|
142
143
|
|
143
144
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
@@ -149,4 +150,5 @@ Google::Cloud.configure.add_config! :datastore do |config|
|
|
149
150
|
config.add_field! :timeout, nil, match: Integer
|
150
151
|
config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
|
151
152
|
config.add_field! :endpoint, "datastore.googleapis.com", match: String
|
153
|
+
config.add_field! :database_id, "", match: String
|
152
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-datastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.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: 2023-02-
|
12
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|