ndb 1.3.0 → 1.5.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/ndb/collection.rb +19 -0
- data/lib/ndb/errors.rb +8 -1
- data/lib/ndb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8cdac865a5507730c08c850f8982acf578b35005b51537bf60648d615a6bbfd
|
|
4
|
+
data.tar.gz: ab26096f42ac1ac5e055dd143221a9fc40a8d88d376f583837d5e1e2e7e1e21a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ea00b7edb9f4ba148939943901497fe892fb5d4b3f11ff6690f5b2265346966a3af1ada3f22041d022104ebb3f6fd6c497d1aa6c66c3989d4d2e2e13a268ac4
|
|
7
|
+
data.tar.gz: e561c0031c5c775e5de8005118e7b37e4778c2def7d240d06bfbfc3e47f0ee1530ab86f4607096bd769607b9603f08af85c4b287f60f6b46dc0b14d09bae9e8a
|
data/lib/ndb/collection.rb
CHANGED
|
@@ -211,6 +211,14 @@ module Ndb
|
|
|
211
211
|
def after(token) = with(after: token)
|
|
212
212
|
def fields(*names) = with(fields: names.flatten.map(&:to_s))
|
|
213
213
|
|
|
214
|
+
# Adds relations of other collections to each row ("lookup"):
|
|
215
|
+
#
|
|
216
|
+
# orders.query(status: "paid").lookup(
|
|
217
|
+
# customer: { belongs_to: "customers", fk: "customer_id" },
|
|
218
|
+
# items: { has_many: "order_items", fk: "order_id", sort: { pos: 1 }, limit: 50 }
|
|
219
|
+
# )
|
|
220
|
+
def lookup(relations) = with(lookup: (@options[:lookup] || {}).merge(Ndb.deep_stringify(relations)))
|
|
221
|
+
|
|
214
222
|
# The rows of one request: one page with limit, every row without it.
|
|
215
223
|
def all = page.rows
|
|
216
224
|
|
|
@@ -271,6 +279,17 @@ module Ndb
|
|
|
271
279
|
|
|
272
280
|
# A client for addr: unix:///path/to/ndb.sock or tcp://host:port. Without
|
|
273
281
|
# addr it reads NDB_URL. See Ndb::Client for the options.
|
|
282
|
+
# deep_stringify gives value with every Hash key as a String (Symbols
|
|
283
|
+
# come from Ruby code, the daemon reads JSON).
|
|
284
|
+
def self.deep_stringify(value)
|
|
285
|
+
case value
|
|
286
|
+
when Hash then value.to_h { |k, v| [k.to_s, deep_stringify(v)] }
|
|
287
|
+
when Array then value.map { |v| deep_stringify(v) }
|
|
288
|
+
when Symbol then value.to_s
|
|
289
|
+
else value
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
274
293
|
def self.connect(addr = nil, **opts)
|
|
275
294
|
Client.new(url: addr, **opts)
|
|
276
295
|
end
|
data/lib/ndb/errors.rb
CHANGED
|
@@ -64,6 +64,10 @@ module Ndb
|
|
|
64
64
|
# restore of a collection with pitr: off.
|
|
65
65
|
class PitrOff < Error; end
|
|
66
66
|
|
|
67
|
+
# A lookup that is not valid, whose other side has no index, or that
|
|
68
|
+
# attaches too many documents.
|
|
69
|
+
class LookupError < Error; end
|
|
70
|
+
|
|
67
71
|
# The daemon error code -> the Ruby class.
|
|
68
72
|
CODE_TO_ERROR = {
|
|
69
73
|
"unauthorized" => Unauthorized,
|
|
@@ -93,7 +97,10 @@ module Ndb
|
|
|
93
97
|
"confirm_required" => ConfirmRequired,
|
|
94
98
|
"collection_exists" => CollectionExists,
|
|
95
99
|
"out_of_window" => OutOfWindow,
|
|
96
|
-
"pitr_off" => PitrOff
|
|
100
|
+
"pitr_off" => PitrOff,
|
|
101
|
+
"lookup_invalid" => LookupError,
|
|
102
|
+
"lookup_unindexed" => LookupError,
|
|
103
|
+
"lookup_too_large" => LookupError
|
|
97
104
|
}.freeze
|
|
98
105
|
|
|
99
106
|
def self.error_for(code, message, status)
|
data/lib/ndb/version.rb
CHANGED