Treat your data well with these React Native's AsyncStorage wrappers

App's data deserves your best treatment, so far you might have encountered React Native's AsyncStorage

AsyncStorage is a simple, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage.

It is recommended that you use an abstraction on top of AsyncStorage instead of AsyncStorage directly for anything more than light usage since it operates globally.

But here are some wrappers around it you might want to check.


react-native-db-models on GitHub

This wrapper is built on top of React Native Store and provides a better and improved Database layer for asynchronous DB transactions.

React Native DB Models fixes a lot of problems in react native store and also the DB class on top helps to provide more functionality and easy developing options.

var React = require("react-native");
var DB = require("./db.js");
var { AppRegistry, StyleSheet, Text, View, Image } = React;

var App = React.createClass({
  get_users: function () {
    DB.users.get_all(function (result) {
      console.log(result);
    });
  },
  render: function () {
    return (
      <View>
        <Text onPress={this.get_users}> Hello </Text>
      </View>
    );
  },
});

react-native-store on GitHub

A simple database base on react-native AsyncStorage.

var ReactNativeStore = require("react-native-store");

ReactNativeStore.table("articles").then(function (articles) {
  // Add Data
  var id = articles.add({
    title: "Title",
    content: "This is a article",
  });

  console.log(id); //row id
});

react-native-level on GitHub

leveldb api on top of React's AsyncStorage

var level = require("react-level");
var db = level("path/to/db", {
  /*...options...*/
});
db.put("blah");
db.batch([
  { type: "put", key: "tasty", value: "wheat" },
  { type: "put", key: "chicken", value: "feet" },
]);

react-native-simple-store on GitHub

A minimalistic wrapper around React Native's AsyncStorage.

var store = require("react-native-simple-store");

// save
store
  .save("coffee", {
    isAwesome: true,
  })
  .then(() => {
    return store.get("coffee").then((coffee) => {
      expect(coffee.isAwesome).toBe(true);
    });
  })
  .then(() => {
    return store.update("coffee", {
      isNotEssential: false,
    });
  })
  .then(() => {
    return store.get("coffee");
  })
  .then((coffee) => {
    expect(coffee.isNotEssential).toBe(false);
    expect(coffee.isAwesome).toBe(true);

    return store.delete("coffee");
  })
  .then(() => {
    store.get("coffee").then((coffee) => {
      expect(coffee).toEqual(null);
    });
  });