@rnue/async-storage
Unreal implementation for @react-native-async-storage/async-storage
@rnue/async-storage provides a native Unreal backend for @react-native-async-storage/async-storage that uses the built in SQLiteCore Unreal plugin.
Design
@rnue/async-storage is designed as a sibling package that needs to be installed and linked to the Unreal project. Usage of the package is done by using @react-native-async-storage/async-storage.
This approach allows for more portable React Native code and preserves functionality of packages that depend on @react-native-async-storage/async-storage.
Installation
Install both packages in your JavaScript React Native application:
npm i @react-native-async-storage/async-storage@3.1.1 @rnue/async-storageThen run the linking command line tool:
npx @rnue/cli linkSee the @rnue/cli documentation for more information about the linking procedure.
Usage
The default export gives access to the default store:
import AsyncStorage from "@react-native-async-storage/async-storage";
await AsyncStorage.setItem("player-name", "John Doe");
const playerName = await AsyncStorage.getItem("player-name");Async Storage stores everything as strings. You must convert other types to JSON before storing them:
const settings = { playSounds: true, gameDifficulty: "hard" };
await AsyncStorage.setItem("settings", JSON.stringify(settings));
const value = await AsyncStorage.getItem("settings");
const restoredSettings = value === null ? null : JSON.parse(value);getItem() returns null if a key does not exist.
Named stores
createAsyncStorage() allows you to create isolated named stores:
import { createAsyncStorage } from "@react-native-async-storage/async-storage";
const playerOneStorage = createAsyncStorage("playerA");
const playerTwoStorage = createAsyncStorage("playerB");
await playerOneStorage.setItem("name", "john");
await playerTwoStorage.setItem("name", "bob");Stores are completely isolated. You can use the same key across multiple stores without worrying about collisions. Similarly, clear() only affects the store you call it on.
Supported API
| Method | Result |
|---|---|
getItem(key) | Returns the string value, or null when the key does not exist. |
setItem(key, value) | Stores one string value. |
removeItem(key) | Removes a value. |
getMany(keys) | Returns an object where each requested key is either a string or null. |
setMany(entries) | Sets multiple entries in one atomic transaction. |
removeMany(keys) | Removes multiple values in one atomic transaction. |
getAllKeys() | Return all keys with stored values for a store. |
clear() | Clears a store by removing all the stored values. |
All methods return promises.
Where is the data stored?
The plugin uses an SQLite database saved at the following path:
Saved/ReactNative/AsyncStorage/RNAsyncStorage.sqlite3The exact location of Saved might vary between platforms and build configurations. You can learn more about the Unreal Engine directory structure by reading the documentation.
The database is not encrypted and therefore we do not recommend storing sensitive data or secrets in AsyncStorage. If you do choose to do so, it is your responsibility to encrypt such data prior to storing it in AsyncStorage.