Search code examples
javascriptydn-db

ydn-db: how do I clear a collection?


I want to do something analogous to SQL's DELETE FROM table1. There is a remove function that takes something called a KeyRange but I'm not sure how to create a KeyRange that represents "all keys" or if that's even possible.

I can do this:

storage.values("mytable").done(function(result) {
  _.each(result, function(r) {
    storage.remove("mytable", r._id);
  });
});

But not only is that ugly, I'd need to do extra work with promises in order to have a callback that's only executed once all the results are finished deleting.

Any hints?


Solution

  • There is clear method. The different is use remove if you know record (s), otherwise use clear. clear is faster than remove. Btw you can use remove method to clear whole table by giving null as argument. Then you got number of records removed.