sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.02k stars 268 forks source link

Remove from table where id = ? #177

Closed zippax closed 6 years ago

zippax commented 6 years ago

Thank you for the lib, I tried to use it on my project and I see that all function works fine when I want to insert, update, and read data.

also when I want to remove whole table it work fine with simple code: storage.remove('users')

my question is how to remove single item with id number. I tried the code in the document but it seems not work or maybe I didn't do it as it should be

my try :

example to insert 4 records :

insert(){
    for (var i = 0; i < 5; i++) {
      storage.save({
        key: 'users',   // Note: Do not use underscore("_") in key!
        data: {
          id: i,
            username: 'User # ' + i,
        }
      });
    }
  }

example to delete from users table where id = 4

delete(){
    storage.remove({
        key: 'users',
        id: 4
    })
  }

I hope I find a solution to fix that.

Thanks

sunnylqm commented 6 years ago

You did not use id in save(id is not part of data)

zippax commented 6 years ago

Thank you for your replay. issue fixed

storage.save({
     key: 'users',
     id: 4,
     data: {
       username: 'User # 4',
     }
   });