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
@@ -23,10 +23,9 @@ module Google
|
|
23
23
|
# QueryResults.
|
24
24
|
#
|
25
25
|
# @example
|
26
|
-
# require "google/cloud"
|
26
|
+
# require "google/cloud/datastore"
|
27
27
|
#
|
28
|
-
#
|
29
|
-
# datastore = gcloud.datastore
|
28
|
+
# datastore = Google::Cloud::Datastore.new
|
30
29
|
#
|
31
30
|
# query = datastore.query("Task").
|
32
31
|
# where("done", "=", false)
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/core/
|
16
|
+
require "google/cloud/core/environment"
|
17
17
|
require "google/cloud/datastore/grpc_utils"
|
18
18
|
require "google/cloud/datastore/credentials"
|
19
19
|
require "google/cloud/datastore/service"
|
@@ -43,10 +43,9 @@ module Google
|
|
43
43
|
# See {Google::Cloud#datastore}
|
44
44
|
#
|
45
45
|
# @example
|
46
|
-
# require "google/cloud"
|
46
|
+
# require "google/cloud/datastore"
|
47
47
|
#
|
48
|
-
#
|
49
|
-
# datastore = gcloud.datastore
|
48
|
+
# datastore = Google::Cloud::Datastore.new
|
50
49
|
#
|
51
50
|
# query = datastore.query("Task").
|
52
51
|
# where("done", "=", false)
|
@@ -55,7 +54,7 @@ module Google
|
|
55
54
|
#
|
56
55
|
class Dataset
|
57
56
|
##
|
58
|
-
# @private The
|
57
|
+
# @private The Service object.
|
59
58
|
attr_accessor :service
|
60
59
|
|
61
60
|
##
|
@@ -70,12 +69,13 @@ module Google
|
|
70
69
|
# The Datastore project connected to.
|
71
70
|
#
|
72
71
|
# @example
|
73
|
-
# require "google/cloud"
|
72
|
+
# require "google/cloud/datastore"
|
74
73
|
#
|
75
|
-
#
|
76
|
-
#
|
74
|
+
# datastore = Google::Cloud::Datastore.new(
|
75
|
+
# project: "my-todo-project",
|
76
|
+
# keyfile: "/path/to/keyfile.json"
|
77
|
+
# )
|
77
78
|
#
|
78
|
-
# datastore = gcloud.datastore
|
79
79
|
# datastore.project #=> "my-todo-project"
|
80
80
|
#
|
81
81
|
def project
|
@@ -89,7 +89,7 @@ module Google
|
|
89
89
|
ENV["DATASTORE_PROJECT"] ||
|
90
90
|
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
91
91
|
ENV["GCLOUD_PROJECT"] ||
|
92
|
-
Google::Cloud::Core::
|
92
|
+
Google::Cloud::Core::Environment.project_id
|
93
93
|
end
|
94
94
|
|
95
95
|
##
|
@@ -233,8 +233,7 @@ module Google
|
|
233
233
|
# @return [Boolean] Returns `true` if successful
|
234
234
|
#
|
235
235
|
# @example
|
236
|
-
#
|
237
|
-
# datastore = gcloud.datastore
|
236
|
+
# datastore = Google::Cloud::Datastore.new
|
238
237
|
# datastore.delete task1, task2
|
239
238
|
#
|
240
239
|
def delete *entities_or_keys
|
@@ -252,8 +251,7 @@ module Google
|
|
252
251
|
# were persisted.
|
253
252
|
#
|
254
253
|
# @example
|
255
|
-
#
|
256
|
-
# datastore = gcloud.datastore
|
254
|
+
# datastore = Google::Cloud::Datastore.new
|
257
255
|
# datastore.commit do |c|
|
258
256
|
# c.save task3, task4
|
259
257
|
# c.delete task1, task2
|
@@ -326,8 +324,7 @@ module Google
|
|
326
324
|
# @return [Google::Cloud::Datastore::Dataset::LookupResults]
|
327
325
|
#
|
328
326
|
# @example
|
329
|
-
#
|
330
|
-
# datastore = gcloud.datastore
|
327
|
+
# datastore = Google::Cloud::Datastore.new
|
331
328
|
#
|
332
329
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
333
330
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -405,10 +402,9 @@ module Google
|
|
405
402
|
# @yieldparam [Transaction] tx the transaction object
|
406
403
|
#
|
407
404
|
# @example Runs the given block in a database transaction:
|
408
|
-
# require "google/cloud"
|
405
|
+
# require "google/cloud/datastore"
|
409
406
|
#
|
410
|
-
#
|
411
|
-
# datastore = gcloud.datastore
|
407
|
+
# datastore = Google::Cloud::Datastore.new
|
412
408
|
#
|
413
409
|
# task = datastore.entity "Task", "sampleTask" do |t|
|
414
410
|
# t["type"] = "Personal"
|
@@ -424,10 +420,9 @@ module Google
|
|
424
420
|
# end
|
425
421
|
#
|
426
422
|
# @example If no block is given, a Transaction object is returned:
|
427
|
-
# require "google/cloud"
|
423
|
+
# require "google/cloud/datastore"
|
428
424
|
#
|
429
|
-
#
|
430
|
-
# datastore = gcloud.datastore
|
425
|
+
# datastore = Google::Cloud::Datastore.new
|
431
426
|
#
|
432
427
|
# task = datastore.entity "Task", "sampleTask" do |t|
|
433
428
|
# t["type"] = "Personal"
|
@@ -65,8 +65,7 @@ module Google
|
|
65
65
|
# @return [Boolean]
|
66
66
|
#
|
67
67
|
# @example
|
68
|
-
#
|
69
|
-
# datastore = gcloud.datastore
|
68
|
+
# datastore = Google::Cloud::Datastore.new
|
70
69
|
#
|
71
70
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
72
71
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -85,8 +84,7 @@ module Google
|
|
85
84
|
# @return [LookupResults]
|
86
85
|
#
|
87
86
|
# @example
|
88
|
-
#
|
89
|
-
# datastore = gcloud.datastore
|
87
|
+
# datastore = Google::Cloud::Datastore.new
|
90
88
|
#
|
91
89
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
92
90
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -123,8 +121,7 @@ module Google
|
|
123
121
|
# @return [Enumerator]
|
124
122
|
#
|
125
123
|
# @example Iterating each result by passing a block:
|
126
|
-
#
|
127
|
-
# datastore = gcloud.datastore
|
124
|
+
# datastore = Google::Cloud::Datastore.new
|
128
125
|
#
|
129
126
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
130
127
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -134,8 +131,7 @@ module Google
|
|
134
131
|
# end
|
135
132
|
#
|
136
133
|
# @example Using the enumerator by not passing a block:
|
137
|
-
#
|
138
|
-
# datastore = gcloud.datastore
|
134
|
+
# datastore = Google::Cloud::Datastore.new
|
139
135
|
#
|
140
136
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
141
137
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -145,8 +141,7 @@ module Google
|
|
145
141
|
# end
|
146
142
|
#
|
147
143
|
# @example Limit the number of API calls made:
|
148
|
-
#
|
149
|
-
# datastore = gcloud.datastore
|
144
|
+
# datastore = Google::Cloud::Datastore.new
|
150
145
|
#
|
151
146
|
# task_key1 = datastore.key "Task", "sampleTask1"
|
152
147
|
# task_key2 = datastore.key "Task", "sampleTask2"
|
@@ -29,10 +29,9 @@ module Google
|
|
29
29
|
# Many common Array methods will return a new Array instance.
|
30
30
|
#
|
31
31
|
# @example
|
32
|
-
# require "google/cloud"
|
32
|
+
# require "google/cloud/datastore"
|
33
33
|
#
|
34
|
-
#
|
35
|
-
# datastore = gcloud.datastore
|
34
|
+
# datastore = Google::Cloud::Datastore.new
|
36
35
|
#
|
37
36
|
# query = datastore.query("Task")
|
38
37
|
# tasks = datastore.run query
|
@@ -41,10 +40,9 @@ module Google
|
|
41
40
|
# tasks.cursor #=> Cursor(c3VwZXJhd2Vzb21lIQ)
|
42
41
|
#
|
43
42
|
# @example Caution, many Array methods will return a new Array instance:
|
44
|
-
# require "google/cloud"
|
43
|
+
# require "google/cloud/datastore"
|
45
44
|
#
|
46
|
-
#
|
47
|
-
# datastore = gcloud.datastore
|
45
|
+
# datastore = Google::Cloud::Datastore.new
|
48
46
|
#
|
49
47
|
# query = datastore.query("Task")
|
50
48
|
# tasks = datastore.run query
|
@@ -122,10 +120,9 @@ module Google
|
|
122
120
|
# @return [Boolean]
|
123
121
|
#
|
124
122
|
# @example
|
125
|
-
# require "google/cloud"
|
123
|
+
# require "google/cloud/datastore"
|
126
124
|
#
|
127
|
-
#
|
128
|
-
# datastore = gcloud.datastore
|
125
|
+
# datastore = Google::Cloud::Datastore.new
|
129
126
|
# query = datastore.query "Task"
|
130
127
|
# tasks = datastore.run query
|
131
128
|
#
|
@@ -143,10 +140,9 @@ module Google
|
|
143
140
|
# @return [QueryResults]
|
144
141
|
#
|
145
142
|
# @example
|
146
|
-
# require "google/cloud"
|
143
|
+
# require "google/cloud/datastore"
|
147
144
|
#
|
148
|
-
#
|
149
|
-
# datastore = gcloud.datastore
|
145
|
+
# datastore = Google::Cloud::Datastore.new
|
150
146
|
# query = datastore.query "Task"
|
151
147
|
# tasks = datastore.run query
|
152
148
|
#
|
@@ -171,10 +167,9 @@ module Google
|
|
171
167
|
# @return [Cursor]
|
172
168
|
#
|
173
169
|
# @example
|
174
|
-
# require "google/cloud"
|
170
|
+
# require "google/cloud/datastore"
|
175
171
|
#
|
176
|
-
#
|
177
|
-
# datastore = gcloud.datastore
|
172
|
+
# datastore = Google::Cloud::Datastore.new
|
178
173
|
# query = datastore.query "Task"
|
179
174
|
# tasks = datastore.run query
|
180
175
|
#
|
@@ -201,10 +196,9 @@ module Google
|
|
201
196
|
# @return [Enumerator]
|
202
197
|
#
|
203
198
|
# @example
|
204
|
-
# require "google/cloud"
|
199
|
+
# require "google/cloud/datastore"
|
205
200
|
#
|
206
|
-
#
|
207
|
-
# datastore = gcloud.datastore
|
201
|
+
# datastore = Google::Cloud::Datastore.new
|
208
202
|
# query = datastore.query "Task"
|
209
203
|
# tasks = datastore.run query
|
210
204
|
# tasks.each_with_cursor do |task, cursor|
|
@@ -235,10 +229,9 @@ module Google
|
|
235
229
|
# @return [Enumerator]
|
236
230
|
#
|
237
231
|
# @example Iterating each query result by passing a block:
|
238
|
-
# require "google/cloud"
|
232
|
+
# require "google/cloud/datastore"
|
239
233
|
#
|
240
|
-
#
|
241
|
-
# datastore = gcloud.datastore
|
234
|
+
# datastore = Google::Cloud::Datastore.new
|
242
235
|
# query = datastore.query "Task"
|
243
236
|
# tasks = datastore.run query
|
244
237
|
# tasks.all do |task|
|
@@ -246,10 +239,9 @@ module Google
|
|
246
239
|
# end
|
247
240
|
#
|
248
241
|
# @example Using the enumerator by not passing a block:
|
249
|
-
# require "google/cloud"
|
242
|
+
# require "google/cloud/datastore"
|
250
243
|
#
|
251
|
-
#
|
252
|
-
# datastore = gcloud.datastore
|
244
|
+
# datastore = Google::Cloud::Datastore.new
|
253
245
|
# query = datastore.query "Task"
|
254
246
|
# tasks = datastore.run query
|
255
247
|
# tasks.all.map(&:key).each do |key|
|
@@ -257,10 +249,9 @@ module Google
|
|
257
249
|
# end
|
258
250
|
#
|
259
251
|
# @example Limit the number of API calls made:
|
260
|
-
# require "google/cloud"
|
252
|
+
# require "google/cloud/datastore"
|
261
253
|
#
|
262
|
-
#
|
263
|
-
# datastore = gcloud.datastore
|
254
|
+
# datastore = Google::Cloud::Datastore.new
|
264
255
|
# query = datastore.query "Task"
|
265
256
|
# tasks = datastore.run query
|
266
257
|
# tasks.all(request_limit: 10) do |task|
|
@@ -306,10 +297,9 @@ module Google
|
|
306
297
|
# @return [Enumerator]
|
307
298
|
#
|
308
299
|
# @example Iterating all results and cursors by passing a block:
|
309
|
-
# require "google/cloud"
|
300
|
+
# require "google/cloud/datastore"
|
310
301
|
#
|
311
|
-
#
|
312
|
-
# datastore = gcloud.datastore
|
302
|
+
# datastore = Google::Cloud::Datastore.new
|
313
303
|
# query = datastore.query "Task"
|
314
304
|
# tasks = datastore.run query
|
315
305
|
# tasks.all_with_cursor do |task, cursor|
|
@@ -317,19 +307,17 @@ module Google
|
|
317
307
|
# end
|
318
308
|
#
|
319
309
|
# @example Using the enumerator by not passing a block:
|
320
|
-
# require "google/cloud"
|
310
|
+
# require "google/cloud/datastore"
|
321
311
|
#
|
322
|
-
#
|
323
|
-
# datastore = gcloud.datastore
|
312
|
+
# datastore = Google::Cloud::Datastore.new
|
324
313
|
# query = datastore.query "Task"
|
325
314
|
# tasks = datastore.run query
|
326
315
|
# tasks.all_with_cursor.count #=> number of result/cursor pairs
|
327
316
|
#
|
328
317
|
# @example Limit the number of API calls made:
|
329
|
-
# require "google/cloud"
|
318
|
+
# require "google/cloud/datastore"
|
330
319
|
#
|
331
|
-
#
|
332
|
-
# datastore = gcloud.datastore
|
320
|
+
# datastore = Google::Cloud::Datastore.new
|
333
321
|
# query = datastore.query "Task"
|
334
322
|
# tasks = datastore.run query
|
335
323
|
# tasks.all_with_cursor(request_limit: 10) do |task, cursor|
|
@@ -81,43 +81,38 @@ module Google
|
|
81
81
|
# @return [Object, nil] Returns `nil` if the property doesn't exist
|
82
82
|
#
|
83
83
|
# @example Properties can be retrieved with a string name:
|
84
|
-
# require "google/cloud"
|
84
|
+
# require "google/cloud/datastore"
|
85
85
|
#
|
86
|
-
#
|
87
|
-
# datastore = gcloud.datastore
|
86
|
+
# datastore = Google::Cloud::Datastore.new
|
88
87
|
# task = datastore.find "Task", "sampleTask"
|
89
88
|
# task["description"] #=> "Learn Cloud Datastore"
|
90
89
|
#
|
91
90
|
# @example Or with a symbol name:
|
92
|
-
# require "google/cloud"
|
91
|
+
# require "google/cloud/datastore"
|
93
92
|
#
|
94
|
-
#
|
95
|
-
# datastore = gcloud.datastore
|
93
|
+
# datastore = Google::Cloud::Datastore.new
|
96
94
|
# task = datastore.find "Task", "sampleTask"
|
97
95
|
# task[:description] #=> "Learn Cloud Datastore"
|
98
96
|
#
|
99
97
|
# @example Getting a blob value returns a StringIO object:
|
100
|
-
# require "google/cloud"
|
98
|
+
# require "google/cloud/datastore"
|
101
99
|
#
|
102
|
-
#
|
103
|
-
# datastore = gcloud.datastore
|
100
|
+
# datastore = Google::Cloud::Datastore.new
|
104
101
|
# user = datastore.find "User", "alice"
|
105
102
|
# user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
|
106
103
|
#
|
107
104
|
# @example Getting a geo point value returns a Hash:
|
108
|
-
# require "google/cloud"
|
105
|
+
# require "google/cloud/datastore"
|
109
106
|
#
|
110
|
-
#
|
111
|
-
# datastore = gcloud.datastore
|
107
|
+
# datastore = Google::Cloud::Datastore.new
|
112
108
|
# user = datastore.find "User", "alice"
|
113
109
|
# user["location"] #=> { longitude: -122.0862462,
|
114
110
|
# # latitude: 37.4220041 }
|
115
111
|
#
|
116
112
|
# @example Getting a blob value returns a StringIO object:
|
117
|
-
# require "google/cloud"
|
113
|
+
# require "google/cloud/datastore"
|
118
114
|
#
|
119
|
-
#
|
120
|
-
# datastore = gcloud.datastore
|
115
|
+
# datastore = Google::Cloud::Datastore.new
|
121
116
|
# user = datastore.find "User", "alice"
|
122
117
|
# user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
|
123
118
|
#
|
@@ -139,45 +134,40 @@ module Google
|
|
139
134
|
# @param [Object] prop_value The value of the property.
|
140
135
|
#
|
141
136
|
# @example Properties can be set with a string name:
|
142
|
-
# require "google/cloud"
|
137
|
+
# require "google/cloud/datastore"
|
143
138
|
#
|
144
|
-
#
|
145
|
-
# datastore = gcloud.datastore
|
139
|
+
# datastore = Google::Cloud::Datastore.new
|
146
140
|
# task = datastore.find "Task", "sampleTask"
|
147
141
|
# task["description"] = "Learn Cloud Datastore"
|
148
142
|
# task["tags"] = ["fun", "programming"]
|
149
143
|
#
|
150
144
|
# @example Or with a symbol name:
|
151
|
-
# require "google/cloud"
|
145
|
+
# require "google/cloud/datastore"
|
152
146
|
#
|
153
|
-
#
|
154
|
-
# datastore = gcloud.datastore
|
147
|
+
# datastore = Google::Cloud::Datastore.new
|
155
148
|
# task = datastore.find "Task", "sampleTask"
|
156
149
|
# task[:description] = "Learn Cloud Datastore"
|
157
150
|
# task[:tags] = ["fun", "programming"]
|
158
151
|
#
|
159
152
|
# @example Setting a blob value using an IO:
|
160
|
-
# require "google/cloud"
|
153
|
+
# require "google/cloud/datastore"
|
161
154
|
#
|
162
|
-
#
|
163
|
-
# datastore = gcloud.datastore
|
155
|
+
# datastore = Google::Cloud::Datastore.new
|
164
156
|
# user = datastore.find "User", "alice"
|
165
157
|
# user["avatar"] = File.open "/avatars/alice.png"
|
166
158
|
# user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
|
167
159
|
#
|
168
160
|
# @example Setting a geo point value using a Hash:
|
169
|
-
# require "google/cloud"
|
161
|
+
# require "google/cloud/datastore"
|
170
162
|
#
|
171
|
-
#
|
172
|
-
# datastore = gcloud.datastore
|
163
|
+
# datastore = Google::Cloud::Datastore.new
|
173
164
|
# user = datastore.find "User", "alice"
|
174
165
|
# user["location"] = { longitude: -122.0862462, latitude: 37.4220041 }
|
175
166
|
#
|
176
167
|
# @example Setting a blob value using an IO:
|
177
|
-
# require "google/cloud"
|
168
|
+
# require "google/cloud/datastore"
|
178
169
|
#
|
179
|
-
#
|
180
|
-
# datastore = gcloud.datastore
|
170
|
+
# datastore = Google::Cloud::Datastore.new
|
181
171
|
# user = datastore.find "User", "alice"
|
182
172
|
# user["avatar"] = File.open "/avatars/alice.png"
|
183
173
|
# user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
|
@@ -221,19 +211,17 @@ module Google
|
|
221
211
|
# set a key when immutable will raise a `RuntimeError`.
|
222
212
|
#
|
223
213
|
# @example The key can be set before the entity is saved:
|
224
|
-
# require "google/cloud"
|
214
|
+
# require "google/cloud/datastore"
|
225
215
|
#
|
226
|
-
#
|
227
|
-
# datastore = gcloud.datastore
|
216
|
+
# datastore = Google::Cloud::Datastore.new
|
228
217
|
# task = Google::Cloud::Datastore::Entity.new
|
229
218
|
# task.key = datastore.key "Task"
|
230
219
|
# datastore.save task
|
231
220
|
#
|
232
221
|
# @example Once the entity is saved, the key is frozen and immutable:
|
233
|
-
# require "google/cloud"
|
222
|
+
# require "google/cloud/datastore"
|
234
223
|
#
|
235
|
-
#
|
236
|
-
# datastore = gcloud.datastore
|
224
|
+
# datastore = Google::Cloud::Datastore.new
|
237
225
|
# task = datastore.find "Task", "sampleTask"
|
238
226
|
# task.persisted? #=> true
|
239
227
|
# task.key = datastore.key "Task" #=> RuntimeError
|
@@ -249,10 +237,9 @@ module Google
|
|
249
237
|
# Indicates if the record is persisted. Default is false.
|
250
238
|
#
|
251
239
|
# @example
|
252
|
-
# require "google/cloud"
|
240
|
+
# require "google/cloud/datastore"
|
253
241
|
#
|
254
|
-
#
|
255
|
-
# datastore = gcloud.datastore
|
242
|
+
# datastore = Google::Cloud::Datastore.new
|
256
243
|
#
|
257
244
|
# task = Google::Cloud::Datastore::Entity.new
|
258
245
|
# task.persisted? #=> false
|