This package has been created by Haspr for use in their in-house projects. Others are free to use this package and leave their feedback for improvements
License - Copyright (c) 2022, Haspr. All rights reserved.
Use the package manager yarn or npm to install haspr-rndb.
yarn add haspr-rndb
or
npm install haspr-rndb
- High Performance VM Storage
- Offline Storage for instant access
- CRUD Operations are a breeze
- Works with Both React Native and Expo
In order to use the database, you have to first declare it in your App.js file before the functions for best performance You only have to do this once at the top level of your React Native or Expo App, which will usually be App.js
import HasprDB from 'haspr-rndb'
import React from 'react'
import { View, Text } from 'react-native'
HasprDB() //` Start the Database
export default function App() {
return (
<View>
<Text>Your App Here...</Text>
</View>
)
}
You can use the build in operations create, read and remove to perform crud operations
The create function can be used to create simple strings, Objects, Nested Objects, Arrays, and Booleans. The Create functions can also be used to update values as it creates new values and keeps the existing data intact.
import HasprDB, { create } from 'haspr-rndb'
import React from 'react'
import { View, Text, TouchableOpacity } from 'react-native'
HasprDB() //` Start the Database
export default function App() {
const saveUser = () => {
const OTP = 861245
create('pin', OTP)
const result = create('user.auth.name', 'The Rock')
console.log(result)
// result >>{ user: { auth: { name: "The Rock" } } }
navigation.navigate('VerifyPin')
}
return (
<View>
<TouchableOpacity onPress={saveUser}>Save Pin</TouchableOpacity>
</View>
)
}
The read function can be used to read simple strings, Objects, Nested Objects, Arrays, and Booleans using string path of objects connected with dots, e.g. , one may want to check if user is logged in from an object, read('user.auth.isLogin') if exists will return the value TRUE
import HasprDB, { read } from 'haspr-rndb'
import React from 'react'
import { View, Text, TouchableOpacity } from 'react-native'
HasprDB() //` Start the Database
export default function App() {
const pin = read('pin')
console.log(pin)
// result >> 861245
const user = read('user.auth')
console.log(user)
// result >> { name: "The Rock" }
return (
<View>
<TouchableOpacity onPress={saveUser}>Save Pin</TouchableOpacity>
</View>
)
}
The remove function can be used to delete simple strings, Objects, Nested Objects, Arrays, and Booleans using string path of objects connected with dots.
import HasprDB, { remove } from 'haspr-rndb'
import React from 'react'
import { View, Text, TouchableOpacity } from 'react-native'
HasprDB() //` Start the Database
export default function App() {
// Remove Single Data
const deletePin = () => remove('pin')
// Remove Nested Data
const deleteName = () => remove('user.auth.name')
// Remove Multiple Data
const deleteMultiple = () => remove(['user.auth', 'theme'])
// Clear All Data and Reset DB
const deleteAllData = () => remove()
return (
<View>
<TouchableOpacity onPress={deletePin}>Delete Pin</TouchableOpacity>
<TouchableOpacity onPress={deleteName}>Delete Name</TouchableOpacity>
<TouchableOpacity onPress={deleteMultiple}>Delete Multiple</TouchableOpacity>
<TouchableOpacity onPress={deleteAllData}>Delete Everything</TouchableOpacity>
</View>
)
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
If you have any feedback, please reach out to us at [email protected]