ndb-rails 0.3.2 → 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 +3 -2
- data/lib/ndb/rails/record.rb +21 -0
- data/lib/ndb/rails/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: 36faa77fbcb1e44d523252eb2869a286de0e463f39b20c6f387396b87cffae96
|
|
4
|
+
data.tar.gz: 9e5071e77a89c1e76193c6a85e929e32d4613dd184c38fbae8ed510bf90899ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41b000dbd96455396f3534c7feed13ae49a94295a01a3cdaeb411bbd44004c577e8ebdbe33400fb2f47ee8e69af43dd47b57fa071ec0aa8d4b4b421932661732
|
|
7
|
+
data.tar.gz: c3a43e41796660a41d260063d16ab43824ec56e8bef9155eb4d89b65f6cf1b4cd57fb4d0d9f9d26fd03e8225a40638eaf68c6252e1be002ef28dc2079035b8ba
|
data/README.md
CHANGED
|
@@ -141,7 +141,8 @@ Call.where(status: "retry").destroy_all # loads and destroys each record with i
|
|
|
141
141
|
|
|
142
142
|
- Every load asks for the version (`_v`). `save`, `update` and `destroy` put the id and `_v` in the filter of the write. If another writer changed the document first, the filter matches nothing and you get `Ndb::StaleObjectError` (code `stale_object`).
|
|
143
143
|
- `find_or_create_by` is atomic. It checks validations and runs the `save` and `create` callbacks, then sends one upsert: the attributes you pass are the filter, and the other attributes go in `$setOnInsert`, so a writer that created the document first is never overwritten and you get that document. An invalid record is returned unsaved (the `!` form raises `Ndb::RecordInvalid`). Only the attributes you pass must be equality values.
|
|
144
|
-
- `delete_all` and `destroy_all` on a model without a `where` are refused by the daemon (`Ndb::EmptyFilter`); `delete_all` needs the id or an indexed field in the `where`.
|
|
144
|
+
- `delete_all` and `destroy_all` on a model without a `where` are refused by the daemon (`Ndb::EmptyFilter`); `delete_all` needs the id or an indexed field in the `where`. To empty the whole collection, use `Call.truncate!`.
|
|
145
|
+
- `Call.truncate!` removes every document, with no callbacks, and keeps the definition and indexes. `Call.drop!` removes the collection, its definition and its watch consumers; the next use of the model declares it again. Both take the same time for 10 or 10 million documents, and watch consumers get one `"truncate"` event.
|
|
145
146
|
- Setting an attribute to `nil` and saving removes the field from the document.
|
|
146
147
|
- A duplicate id raises `RecordNotUnique` (code `duplicate_id`).
|
|
147
148
|
- `persisted?`, `new_record?`, `destroyed?`, `id` and `version` work as in ActiveRecord.
|
|
@@ -302,7 +303,7 @@ client = Ndb::Rails.client
|
|
|
302
303
|
|
|
303
304
|
begin
|
|
304
305
|
client.watch(Call.collection_name, "relay", where: { status: "answered" }) do |event|
|
|
305
|
-
# event has "pos", "op" ("put" or "
|
|
306
|
+
# event has "pos", "op" ("put", "del" or "truncate"), "_id", "v" and "doc"
|
|
306
307
|
handle(event)
|
|
307
308
|
|
|
308
309
|
client.ack(Call.collection_name, "relay", event["pos"])
|
data/lib/ndb/rails/record.rb
CHANGED
|
@@ -68,6 +68,27 @@ module Ndb
|
|
|
68
68
|
where(primary_key => ids).delete_all
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# Removes every document of the collection, with no callbacks, and
|
|
72
|
+
# keeps its definition and indexes. The cost does not depend on the
|
|
73
|
+
# number of documents. Watch consumers get one "truncate" event.
|
|
74
|
+
def truncate!
|
|
75
|
+
ensure_collection!
|
|
76
|
+
|
|
77
|
+
Rails.client.truncate(collection_name)
|
|
78
|
+
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Removes the collection: documents, definition and watch consumers.
|
|
83
|
+
# The next use of the model declares it again, empty.
|
|
84
|
+
def drop!
|
|
85
|
+
Rails.client.drop(collection_name)
|
|
86
|
+
|
|
87
|
+
@ensured_client = nil
|
|
88
|
+
|
|
89
|
+
true
|
|
90
|
+
end
|
|
91
|
+
|
|
71
92
|
def collection_name
|
|
72
93
|
@collection_name || model_name.plural
|
|
73
94
|
end
|
data/lib/ndb/rails/version.rb
CHANGED