ndb 0.3.1 → 0.3.3
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/README.md +11 -1
- data/lib/ndb/client.rb +18 -0
- data/lib/ndb/errors.rb +5 -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: '09d3bc06821cc8a971df3508d9df292c94ca580f2ce915768ced2be364c2bb4c'
|
|
4
|
+
data.tar.gz: 86538aa192b2417ddc9468cb1228986b734cf69a74ddf731fae361bb9d33ff06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 745b55dc3216abc5a32b3b616a27613cbdef93e3202dcec90c61e6b1ba970a4eb8a75cb704b8f7d14c0d3579bfe0401d68c3beb7c2cf53e6c17be67ff4f3d9f6
|
|
7
|
+
data.tar.gz: 5b06794ba7a0c534e23e0bd96299a2cdfea160caa259ff1fe8e306b932218c62834f5630b4a42d0b126651599cfac0cf2b1d3883c7e74aaa7920450afc435cc6
|
data/README.md
CHANGED
|
@@ -103,6 +103,16 @@ ndb.delete("calls", { status: "failed" }, many: true)
|
|
|
103
103
|
- The contract errors are `Ndb::UnknownOperator`, `NoUpdate`, `ConflictingUpdate`, `InvalidField`, `UnindexedMany` and `EmptyFilter`, all under `Ndb::InvalidUpdate`.
|
|
104
104
|
- A duplicate `_id` raises `Ndb::UniqueViolation` (code `duplicate_id`). A broken unique field raises it too (code `unique_violation`).
|
|
105
105
|
|
|
106
|
+
### Truncate and drop
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
ndb.truncate("calls") # every document goes; the definition and indexes stay => {"collection" => "calls", "truncated" => true}
|
|
110
|
+
ndb.drop("calls") # the collection, its definition and its watch consumers go
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- Both take the same time for 10 or 10 million documents. Watch consumers get one event with `"op" => "truncate"` (no `_id`), then the new changes.
|
|
114
|
+
- A direct-mode collection raises `Ndb::ReadOnlyCollection`. A collection declared in `ndb.yml` comes back, empty, when the daemon restarts after a drop.
|
|
115
|
+
|
|
106
116
|
## Expiry (TTL like Redis)
|
|
107
117
|
|
|
108
118
|
The collection needs `expires_field`.
|
|
@@ -233,7 +243,7 @@ A watch streams the changes of a collection to a named consumer: first the event
|
|
|
233
243
|
```ruby
|
|
234
244
|
begin
|
|
235
245
|
ndb.watch("calls", "relay", where: { status: "failed" }) do |event|
|
|
236
|
-
# event has "pos", "op" ("put" or "
|
|
246
|
+
# event has "pos", "op" ("put", "del" or "truncate"), "_id", "v" and "doc"
|
|
237
247
|
handle(event)
|
|
238
248
|
|
|
239
249
|
ndb.ack("calls", "relay", event["pos"])
|
data/lib/ndb/client.rb
CHANGED
|
@@ -145,6 +145,20 @@ module Ndb
|
|
|
145
145
|
json(post(coll, "ack", consumer: consumer, pos: pos))
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
# Removes every document of the collection and keeps its definition and
|
|
149
|
+
# indexes. The cost does not depend on the number of documents. Watch
|
|
150
|
+
# consumers get one event with op "truncate". {"collection", "truncated"}
|
|
151
|
+
def truncate(coll)
|
|
152
|
+
json(request("POST", "#{path(coll)}/truncate?confirm=#{confirm(coll)}", nil))
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Removes the collection: its documents, its definition and the positions
|
|
156
|
+
# of its watch consumers. A collection declared in ndb.yml comes back,
|
|
157
|
+
# empty, when the daemon restarts. {"collection", "dropped"}
|
|
158
|
+
def drop(coll)
|
|
159
|
+
json(request("DELETE", "#{path(coll)}?confirm=#{confirm(coll)}", nil))
|
|
160
|
+
end
|
|
161
|
+
|
|
148
162
|
def ensure_collection(coll, definition = {})
|
|
149
163
|
json(request("PUT", path(coll), definition))
|
|
150
164
|
end
|
|
@@ -201,6 +215,10 @@ module Ndb
|
|
|
201
215
|
"/v1/c/#{URI.encode_www_form_component(coll).gsub('+', '%20')}"
|
|
202
216
|
end
|
|
203
217
|
|
|
218
|
+
def confirm(coll)
|
|
219
|
+
URI.encode_www_form_component(coll)
|
|
220
|
+
end
|
|
221
|
+
|
|
204
222
|
def id_path(coll, id)
|
|
205
223
|
"#{path(coll)}/#{URI.encode_www_form_component(id).gsub('+', '%20')}"
|
|
206
224
|
end
|
data/lib/ndb/errors.rb
CHANGED
|
@@ -52,6 +52,9 @@ module Ndb
|
|
|
52
52
|
# consumer cannot resume from its position and must start over.
|
|
53
53
|
class HistoryTruncated < Error; end
|
|
54
54
|
|
|
55
|
+
# truncate or drop without the collection name as confirm.
|
|
56
|
+
class ConfirmRequired < Error; end
|
|
57
|
+
|
|
55
58
|
# The daemon error code -> the Ruby class.
|
|
56
59
|
CODE_TO_ERROR = {
|
|
57
60
|
"unauthorized" => Unauthorized,
|
|
@@ -77,7 +80,8 @@ module Ndb
|
|
|
77
80
|
"conflicting_update" => ConflictingUpdate,
|
|
78
81
|
"invalid_field" => InvalidField,
|
|
79
82
|
"unindexed_many" => UnindexedMany,
|
|
80
|
-
"empty_filter" => EmptyFilter
|
|
83
|
+
"empty_filter" => EmptyFilter,
|
|
84
|
+
"confirm_required" => ConfirmRequired
|
|
81
85
|
}.freeze
|
|
82
86
|
|
|
83
87
|
def self.error_for(code, message, status)
|
data/lib/ndb/version.rb
CHANGED