sqlite3 vs expo-sqlite vs pouchdb vs realm vs react-native-sqlite-storage
Database Libraries for Web and Mobile Development Comparison
1 Year
sqlite3expo-sqlitepouchdbrealmreact-native-sqlite-storageSimilar Packages:
What's Database Libraries for Web and Mobile Development?

These libraries provide various solutions for managing local databases in web and mobile applications. They enable developers to store, retrieve, and manipulate data efficiently, catering to different use cases and requirements. The choice of library can significantly impact performance, ease of use, and the overall architecture of the application, making it essential to understand their unique features and capabilities.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
sqlite31,489,5336,3363.35 MB155a year agoBSD-3-Clause
expo-sqlite68,56540,18069.6 MB7507 days agoMIT
pouchdb49,20917,2335.53 MB168a year agoApache-2.0
realm35,7285,894887 MB614a month agoapache-2.0
react-native-sqlite-storage27,9152,791-1804 years agoMIT
Feature Comparison: sqlite3 vs expo-sqlite vs pouchdb vs realm vs react-native-sqlite-storage

Data Model

  • sqlite3:

    sqlite3 adheres to a traditional relational data model, allowing for structured data storage with support for SQL queries. This is suitable for applications that require strong data integrity and complex relationships.

  • expo-sqlite:

    expo-sqlite provides a simple key-value data model using SQLite, making it easy to store and retrieve data without complex schemas. It is suitable for applications with straightforward data storage needs.

  • pouchdb:

    PouchDB uses a document-oriented data model, allowing for flexible and dynamic data structures. This model is beneficial for applications that require schema-less data storage and easy data manipulation.

  • realm:

    Realm employs an object-oriented data model, allowing developers to work with native objects directly. This simplifies data handling and enhances performance, especially for mobile applications with complex data relationships.

  • react-native-sqlite-storage:

    react-native-sqlite-storage utilizes a relational data model, supporting complex queries and relationships between tables. This is ideal for applications that require structured data and advanced querying capabilities.

Performance

  • sqlite3:

    sqlite3 offers high performance for server-side applications, with fast read and write operations. It is well-suited for applications that require direct access to the database without additional overhead.

  • expo-sqlite:

    expo-sqlite offers good performance for basic CRUD operations but may not be optimized for complex queries or large datasets. It is best for lightweight applications with moderate data needs.

  • pouchdb:

    PouchDB is designed for offline-first applications and provides good performance for syncing data across devices. However, performance may vary based on the complexity of the data and sync operations.

  • realm:

    Realm is known for its exceptional performance, especially in mobile environments. It supports real-time data updates and efficient querying, making it ideal for applications with heavy data usage.

  • react-native-sqlite-storage:

    react-native-sqlite-storage delivers high performance for complex queries and large datasets, making it suitable for applications that require efficient data manipulation and retrieval.

Ease of Use

  • sqlite3:

    sqlite3 requires knowledge of SQL for effective usage, which may pose a challenge for developers unfamiliar with SQL syntax. However, it provides powerful capabilities for those who understand it.

  • expo-sqlite:

    expo-sqlite is easy to set up and use within Expo projects, making it accessible for developers who are already familiar with the Expo ecosystem. It requires minimal configuration and setup.

  • pouchdb:

    PouchDB has a straightforward API and is easy to integrate into web and mobile applications. Its document-oriented approach simplifies data handling, making it user-friendly for developers.

  • realm:

    Realm is designed to be easy to use with a simple API for data manipulation. Its object-oriented approach allows developers to work with data intuitively, reducing the learning curve.

  • react-native-sqlite-storage:

    react-native-sqlite-storage has a steeper learning curve due to its extensive features and SQL syntax. However, it provides powerful capabilities for those willing to invest time in learning.

Sync Capabilities

  • sqlite3:

    sqlite3 does not offer synchronization features, as it is primarily a local database solution. Developers need to manage data synchronization manually if needed.

  • expo-sqlite:

    expo-sqlite does not provide built-in synchronization capabilities. It is best used for applications that do not require data to be shared across devices.

  • pouchdb:

    PouchDB excels in synchronization, allowing data to sync seamlessly with CouchDB. This makes it ideal for applications that require offline capabilities and data consistency across devices.

  • realm:

    Realm provides real-time synchronization capabilities, allowing data to be updated across devices instantly. This is particularly useful for collaborative applications that require up-to-date information.

  • react-native-sqlite-storage:

    react-native-sqlite-storage does not offer built-in sync capabilities, focusing instead on local data storage and manipulation. Developers need to implement their own synchronization logic if required.

Community and Support

  • sqlite3:

    sqlite3 has a large user base and extensive documentation, making it easy for developers to find help and resources. It is a well-established library with a strong reputation.

  • expo-sqlite:

    expo-sqlite benefits from the larger Expo community, providing ample resources and support for developers. Its integration with Expo ensures ongoing updates and improvements.

  • pouchdb:

    PouchDB has a strong community and good documentation, making it easy for developers to find support and resources. It is actively maintained and frequently updated.

  • realm:

    Realm has a robust community and excellent support resources, including documentation and tutorials. Its popularity in mobile development ensures ongoing updates and improvements.

  • react-native-sqlite-storage:

    react-native-sqlite-storage has a dedicated community, but its support may not be as extensive as some other libraries. Documentation is available, but developers may encounter challenges due to the complexity of the library.

How to Choose: sqlite3 vs expo-sqlite vs pouchdb vs realm vs react-native-sqlite-storage
  • sqlite3:

    Choose sqlite3 if you are working in a Node.js environment and need a lightweight, fast SQL database. It is suitable for server-side applications that require direct access to SQLite databases without additional abstraction.

  • expo-sqlite:

    Choose expo-sqlite if you are developing a React Native application using Expo and need a simple SQLite solution with easy integration. It is ideal for projects that require basic local data storage without complex features.

  • pouchdb:

    Choose PouchDB if you need a NoSQL database that can sync with CouchDB and work offline. It is suitable for applications that require data synchronization across devices and offline capabilities, making it great for mobile and web apps.

  • realm:

    Choose Realm if you need a high-performance mobile database with real-time data synchronization and reactive architecture. It is ideal for applications that require complex data relationships and real-time updates, especially in mobile environments.

  • react-native-sqlite-storage:

    Choose react-native-sqlite-storage if you need a robust SQLite implementation for React Native with support for complex queries and transactions. It is best for applications that require extensive data manipulation and performance optimization.

README for sqlite3

⚙️ node-sqlite3

Asynchronous, non-blocking SQLite3 bindings for Node.js.

Latest release Build Status FOSSA Status N-API v3 Badge N-API v6 Badge

Features

Installing

You can use npm or yarn to install sqlite3:

  • (recommended) Latest published package:
npm install sqlite3
# or
yarn add sqlite3
  • GitHub's master branch: npm install https://github.com/tryghost/node-sqlite3/tarball/master

Prebuilt binaries

sqlite3 v5+ was rewritten to use Node-API so prebuilt binaries do not need to be built for specific Node versions. sqlite3 currently builds for both Node-API v3 and v6. Check the Node-API version matrix to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.

The module uses prebuild-install to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for sqlite3 versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:

  • darwin-arm64
  • darwin-x64
  • linux-arm64
  • linux-x64
  • linuxmusl-arm64
  • linuxmusl-x64
  • win32-ia32
  • win32-x64

Unfortunately, prebuild cannot differentiate between armv6 and armv7, and instead uses arm as the {arch}. Until that is fixed, you will still need to install sqlite3 from source.

Support for other platforms and architectures may be added in the future if CI supports building on them.

If your environment isn't supported, it'll use node-gyp to build SQLite, but you will need to install a C++ compiler and linker.

Other ways to install

It is also possible to make your own build of sqlite3 from its source instead of its npm package (See below.).

The sqlite3 module also works with node-webkit if node-webkit contains a supported version of Node.js engine. (See below.)

SQLite's SQLCipher extension is also supported. (See below.)

API

See the API documentation in the wiki.

Usage

Note: the module must be installed before use.

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');

db.serialize(() => {
    db.run("CREATE TABLE lorem (info TEXT)");

    const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (let i = 0; i < 10; i++) {
        stmt.run("Ipsum " + i);
    }
    stmt.finalize();

    db.each("SELECT rowid AS id, info FROM lorem", (err, row) => {
        console.log(row.id + ": " + row.info);
    });
});

db.close();

Source install

To skip searching for pre-compiled binaries, and force a build from source, use

npm install --build-from-source

The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required.

If you wish to install against an external sqlite then you need to pass the --sqlite argument to npm wrapper:

npm install --build-from-source --sqlite=/usr/local

If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the -dev package with your package manager, e.g. apt-get install libsqlite3-dev for Debian/Ubuntu. Make sure that you have at least libsqlite3 >= 3.6.

Note, if building against homebrew-installed sqlite on OS X you can do:

npm install --build-from-source --sqlite=/usr/local/opt/sqlite/

Custom file header (magic)

The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files.

npm install --build-from-source --sqlite_magic="MyCustomMagic15"

Note that the magic must be exactly 15 characters long (16 bytes including null terminator).

Building for node-webkit

Because of ABI differences, sqlite3 must be built in a custom to be used with node-webkit.

To build sqlite3 for node-webkit:

  1. Install nw-gyp globally: npm install nw-gyp -g (unless already installed)

  2. Build the module with the custom flags of --runtime, --target_arch, and --target:

NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

You can also run this command from within a sqlite3 checkout:

npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

Remember the following:

  • You must provide the right --target_arch flag. ia32 is needed to target 32bit node-webkit builds, while x64 will target 64bit node-webkit builds (if available for your platform).

  • After the sqlite3 package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa).

    • For example, npm test of the node-webkit's package would fail.

Visit the “Using Node modules” article in the node-webkit's wiki for more details.

Building for SQLCipher

For instructions on building SQLCipher, see Building SQLCipher for Node.js. Alternatively, you can install it with your local package manager.

To run against SQLCipher, you need to compile sqlite3 from source by passing build options like:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/

node -e 'require("sqlite3")'

If your SQLCipher is installed in a custom location (if you compiled and installed it yourself), you'll need to set some environment variables:

On OS X with Homebrew

Set the location where brew installed it:

export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`

node -e 'require("sqlite3")'

On most Linuxes (including Raspberry Pi)

Set the location where make installed it:

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
export CXXFLAGS="$CPPFLAGS"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose

node -e 'require("sqlite3")'

Custom builds and Electron

Running sqlite3 through electron-rebuild does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your npm install sqlite3 --build-from-source command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):

--runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

In the case of MacOS with Homebrew, the command should look like the following:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

Testing

npm test

Contributors

Acknowledgments

Thanks to Orlando Vazquez, Eric Fredricksen and Ryan Dahl for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.

This module was originally created by Mapbox & is now maintained by Ghost.

Changelog

We use GitHub releases for notes on the latest versions. See CHANGELOG.md in git history for details on older versions.

License

node-sqlite3 is BSD licensed.

FOSSA Status