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

Improve API w/ findById, updateById, removeById #22

Closed klvs closed 8 years ago

klvs commented 8 years ago

findById, updateById, removeById are simple convenience wrappers for the existing API. They eliminate the need to do things like:

javascript
// current api
var entry = await this.model.find({
    where: {_id: 10}
});

entry = entry.pop();

console.log('entry name': entry.name);

// this PR
var entry = await this.model.findById(10);

console.log('entry name': entry.name);

Small contribution, but I thought it might be nice.

All of the aforementioned API changes break nothing and use the existing API (so updates should be painless). All are tested (see docs/test.js).

thewei commented 8 years ago

thank you!