In order to develop a mobile application with maximum DIL [Disconnected, Intermittent, Low-bandwidth] functionality, local data storage is essential. Within the React Native ecosystem, there are a number of options to consider.
Simple Storage Solutions
AsyncStorage is an asynchronous, unencrypted, persistent, key-value storage system. AsyncStorage is a perfect solution if the data to be stored is simple, lightweight, and not sensitive in nature. This solution is supported in bare and managed workflows in Expo.
SecureStore is another asynchronous, persistent, key-value storage option available in React Native. SecureStore enables the storage of key-value pairs in an encrypted data store. The size limit is 2048 bytes for the value. This solution is also supported in bare and managed workflows in Expo.
Persisting simple data in key-value pairs is highly useful but it is typical that mobile applications will require the storage of more complex data structures. Because of this need, there are many options to choose from.
SQlite vs. NoSQL
SQLite is a relational database management system (RDMS). It uses tables where data is defined by columns and stored in rows. Each table has a unique name and may relate to one or more other tables in the database through common values. NoSQL databases are document-based, key-value pairs, graph databases or wide-column stores. They also do not have standard schema definitions that need to be adhered to. Additionally, NoSQL data stores are typically not relational.
SQL databases have a predefined schema. NoSQL databases have a dynamic schema for unstructured data. Therefore, migrations are necessary when schema changes are made when leveraging a SQL/SQLite database. For apps with the need to store unstructured or constantly changing data structures, a NoSQL solution is best.
SQL/SQLite databases are a better fit for complex query intensive applications. SQLite implementations often will have an abstraction layer to allow developers to interact with the database in the native language of the project. SQLite also implements most of the Structured Query Language (SQL) standard. This allows developers to implement custom SQL queries if needed. In general, NoSQL databases don’t have standard interfaces to perform complex queries. Typically the queries themselves in NoSQL are not as powerful as SQL query language.
React Native Datastore Options
This is a list with a brief description of some of the options for client-side mobile application data storage solutions capable of handling more complex data than AsyncStorage or SecureStore.
The React Native SQLite module creates a client-side SQLite database that can be queried through a WebSQL-like API. SQLite is a small, fast, reliable, and self-contained SQL database engine. It is one of the most commonly used database engines and is leveraged by all kinds of applications on any platform and is supported in Expo managed and bare workflows. SQLite data stores can be encrypted using SQLite Encryption Extension (SEE) or plugins like SQLiteCrypt and SQLCipher. Unfortunately, it does not look like these libraries are supported in Expo managed workflows at the time of this writing (December 2019).
Realm is an object-oriented NoSQL database. As such it provides memory-efficient access to data by using Realm objects, which usually consume less RAM than native objects. Realm also has faster performance than SQLite and some other data storage solutions. The client-side datastore includes a built-in framework for seamless data syncing with Realm backend storage solutions. Custom security protocols for each of the different device platforms is also one of the strengths of Realm. As of this writing (December 2019), Realm is not supported in Expo managed workflow.
Pouchbase is a client-side datastore with a JSON-based NoSQL interface. It can be used as an abstraction layer over SQLite or by default it ships with IndexedDB adapter for the browser, and a LevelDB adapter in Node.js. The primary reason to adopt PouchDB is to leverage the built-in framework to enable data synchronization with CouchDB server-side data storage solutions. Client-side PouchDB instances can be encrypted using the Simple-Cryptor-Pouch plugin. As of this writing (December 2019), PouchDB is not supported in Expo managed workflow.
Disclaimer on the react-native-couchbase-lite repo: “This package is not an official couchbase plugin and is not supported in any way by couchbase. If you have issues with it please do not use the couchbase forums but raise an issue here instead. Although this package does work as described it may not be fully featured and may not be suitable for your requirements. This package is just a thin layer over the CBL REST API, PRs and suggestions are welcome!”
It does not appear like the developers of Couchbase are currently supporting a React Native implementation of their client-side data storage solution. The best React Native compatible client-side data storage solution with built-in server-side Couchbase syncing at the time of writing (December 2019) is PouchDB.
If you are looking for application support as it relates to building applications in disconnected, intermittent, and low bandwidth environments (DIL), contact us here. Bytelion has developed a portfolio of apps meant to sustain connectivity and support local data storage.