Data storage for React Native use AsyncStorage
npm install lastorage
or
yarn add lastorage
Add AsyncStorage library
npm install @react-native-async-storage/async-storage
# or
yarn add @react-native-async-storage/async-storage
On iOS, use CocoaPods to add the native RNAsyncStorage
to your project:
npx pod-install
View more documents in AsyncStorage
- Import
- Create And Init Database
- Drop
- Insert Row
- Insert Multiple Rows
- Get All Rows
- Find Rows
- Count Rows
- Limit Rows
- Find One Row
- Update Row
- Delete Row
- Text Search
import Lastorage from "lastorage";
// table name `todos`
const todos = new Lastorage('todos');
todos.init(() => {
todos.find();
});
// you should call the init method when you want get data from local storage
todos.drop();
todos.insert({
title: 'Task 1',
body: 'Body of task 1',
status: 1,
});
// the insert method return _id
todos.insertMany([
{
title: 'Task 1',
body: 'Body of task 1',
status: 1,
},
{
title: 'Task 2',
body: 'Body of task 2',
status: 1,
},
]);
// the insertMany method return array with _id
todos.find();
todos.find({ title: 'Task 1' });
todos.count();
todos.limit(2);
todos.findOne({ name: 'Task 1' });
todos.update({ _id: '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed' }, { name: 'Task 1 updated' })
todos.remove({ name: 'Task 1' });
todos.find({ name: /Task/ });
View Example
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT