Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded database for electron, react-native and NodeJS apps?

I have a javascript application that I've implemented for mobile apps using react-native and its desktop counterpart using the electron framework. The mobile application uses react-native-sqlite-storage native module to save preferences and data (5 - 6 tables) whereas I use node-sqlite3 for the electron app.

Both, the mobile and desktop apps share a lot of functionality but due to the use of different database plugins, have a lot of differences. Also, for the desktop app, as node-sqlite3 is a native dependency, I have to build the app installers for Windows and macOS separately. That's a pain!

So, what I need is a database solution that is :-

  • embeddable into the app
  • efficient and performant compared to sqlite3
  • supports syncing to a remote database
  • supports macOS, Windows, and Linux
  • encrypts the data written within the database
  • consistent API across JS runtimes (Browser / NodeJS / JavascriptCore)

Here's a list of those that I've come across and that seem appealing:-

  • NeDB
  • RxDB
  • PouchDB

So, what are your suggestions and how have you implemented anything similar for your apps?

like image 444
Ashishkumar Pandey Avatar asked May 04 '18 10:05

Ashishkumar Pandey


People also ask

What database should I use for Electron app?

NEDB is a mongo API compatible, file-based database. It's a great fit for electron apps. In this post, I'll walk through my NEDB setup. It's fairly simple and is being used in production at HTTPSLocalhost app.

Which database we can use with React Native?

Firebase. Firebase supports the real-time NoSQL database for the development of react native applications. It is chosen mainly for its offline data change and data synchronization practices.

What is the best database for node JS?

“Node. js can only be used with MongoDB (which is the most popular NoSQL database).”

Can you use node js with Electron?

Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. By embedding Chromium and Node. js into a single binary file, Electron allows you to create cross-platform apps that work on Windows, macOS, and Linux with a single JavaScript codebase.


1 Answers

I've been testing PouchDB, RxDB (which relies on PouchDB with RxJS streams for queries), Realm-JS (native database like sqlite3), FireStore. NeDB doesn't support remote sync.

I won't go into performance metrics details on each database, but PouchDB has been very slow and heavy on memory when querying more than 20.000 items (tried with indexeddb/websql adapter).

RxDB was generally much faster with that many items, especially when subscribing to query changes (tried with indexeddb/websql adapter too). Also schema and migrations are very handy.

FireStore is a good choice and comes with very easy setup of server and client components, but you'll need to be comfortable to run on a google platform. There is some flexibility with firebase functions if you want some control over server logic and there is customizable ACLs for your collections. Speed has been good and on par with RxDB. Comes with a very good auth module if you want it.

If you want to be able to scale much much more on the client side, which you probably don't, or if you want to make complex queries, I'd really recommend using something like realm. You'll need to compile for each platform like you've experienced with sqlite3, but there is sync, offline persistence, rich queries and great performance. There is just no way that javascript based solutions like PouchDB, RxDB or FireStore can compete, even with sqlite backends, since much of the computation will still happen in your precious JS thread. realm is doing much of its heavy lifting on the native library. I've been able to do LIKE "abc" queries on 100.000 items, returning hundreds of results, within less than hundred milliseconds and without noticeably freezing my UI or pumping up memory usage heavily. Supports client migrations too, which is nice.

In the end, there are multiple answers: 1. Want to host everything yourself and don't need massive scale client side (you can sync against subsets of your server data with filters), RxDB ist very good and comes with nice set of features. 2. Want very easy setup, nice modules like auth, server functions etc, and don't need massive scale on the client (can also sync against server data subsets with filters), FireStore is great. 3. Need lots of lots of data on the client, realm is my preference. I personally really dislike the realm sync platform for its pricing model (though technically it's cool), but the database itself is free and maybe you could try and implement a custom sync.

Take my results with a grain of salt, I've had some very specific challenges like large, non-relational collections and fulltext-search, your use-case will probably differ a lot.

like image 172
quambo Avatar answered Sep 23 '22 14:09

quambo