lastorage
v0.1.3
Published
Data storage for React Native use AsyncStorage
Downloads
13
Maintainers
Readme
lastorage
Data storage for React Native use AsyncStorage
Installation
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
Usage
Methods
- 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
import Lastorage from "lastorage";
Create And Init Database
// 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
Drop
todos.drop();
Insert Row
todos.insert({
title: 'Task 1',
body: 'Body of task 1',
status: 1,
});
// the insert method return _id
Insert Multiple Rows
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
Get All Rows
todos.find();
Find Rows
todos.find({ title: 'Task 1' });
Count Rows
todos.count();
Limit Rows
todos.limit(2);
Find One Row
todos.findOne({ name: 'Task 1' });
Update Row
todos.update({ _id: '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed' }, { name: 'Task 1 updated' })
Delete Row
todos.remove({ name: 'Task 1' });
Text Search
todos.find({ name: /Task/ });
View Example
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT