thewei / react-native-store

A simple database base on react-native AsyncStorage.
https://github.com/thewei/react-native-store
Other
569 stars 74 forks source link

Remove with filter doesn't work #16

Closed augnustin closed 8 years ago

augnustin commented 9 years ago

Hi there,

Great lib! I can't make the remove method work with a filter though.

    this.model = await reactNativeStore.model("link");
    // ...
    await this.model.remove({
      where: {
        _id: id,
      }
    });

Since it is not in your test suite either, I can't make myself confortable it actually works.

kintsugi commented 9 years ago

Hi, thanks for the issue. Is the data you are operating on created before v0.2.0? Before then, the _id field was not written to disk.

However, to be sure I created a new react project to test with this test code and got this output which shows that removing by the _id field works.

If your data is created before v0.2.0, it just needs to be re-added to the database to have a _id field. Something like this should work:

this.model = await reactNativeStore.model("link");
var all_data = this.model.remove();
for(var i in all_data) {
    this.model.add(all_data[i]);
}
thewei commented 8 years ago

Now we had api removeById, you can use this api to remove data by id.