ndb-rails 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c25aa0b6dd8eda13f3bc8145b9c5f19279ada07c94901b8a7432cf44c79a239c
4
- data.tar.gz: 69704a666b52a4add4e7b31cee812c75e3d706f5325e5e681529fbcae79ad88b
3
+ metadata.gz: 36faa77fbcb1e44d523252eb2869a286de0e463f39b20c6f387396b87cffae96
4
+ data.tar.gz: 9e5071e77a89c1e76193c6a85e929e32d4613dd184c38fbae8ed510bf90899ab
5
5
  SHA512:
6
- metadata.gz: 5ce06b1eedc5f385ec7a2613683e8c19b9e8b7fb2930d754beaee0daf3a6dfc508bb9b20ae40bfdc3a3f050e0505a682465f09b2539e5701fab15ea9794934ab
7
- data.tar.gz: 16c17a1ce7c5acc2aafa41847c40b47c9c2f8b28219e7e3f345adb7d1f459ff078596c72161b1ef21789afcb98761b6032a63563bee34674837a6236f204ce47
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 "del"), "_id", "v" and "doc"
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"])
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ndb
4
4
  module Rails
5
- VERSION = "0.3.1"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndb-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thadeu