Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a persistent offline database with electron and pouchdb

i am going to write a desktop-app that should be able to store its mass-data persistent and locally.

i want to write that app with electron. later, i want to port the app to mobile. i am experimenting here with nativescript and the angular-advanced-seed which tries to make it possible to reuse code on different platforms.

As Database-tool i want to use pouchdb because i didn't want to have the user setup/install an additional tool for having a database for the desktop-app which runs seperately.

Also, I like to use pouchdb, because it has this nice sync feature with couchdb, which i can possibly use later in the project when the need for sync with an online database will arise.

Now my Questions

  1. how can i use pouchdb to store data locally (it can be a mass of data that exceeds the localstorage limit) even when the app has been stopped by the user. i need to load that data in the app, when the user starts the desktop-app the next time. i read about pouchdb using leveldb, but i can't find the data persisted.

  2. is it possible in electron to have a database running inside the electron-app, so that i do not need to install for example mongodb on the users pc/mobile app too?

  3. it would be nice to have a solution that will work on mobile (ios/android) too, so that i have the offline capabilities too there without using a different approach for the data-storage

  4. Are there any other solutions (combinations of) database tools to satisfy my needs: A. same offline storage capabilities for mass data, that exceeds localstorage' space restrictions for Desktop (electron)/Mobile (Android/IOS) and Web and B. good sync-function to the online-pendant database like (pouchdb/couchdb or minimongo/mongodb) C. in-app database should have the same query api like the server-database (minimongo/mongodb)

thx in advance for your tipps.

like image 954
divramod Avatar asked Nov 07 '16 19:11

divramod


1 Answers

Pouchdb-Server works. I have an app setup with express-pouchdb.

'use strict'

console.log('Starting PouchDB...');

const express = require('express');
const PouchDB = require('pouchdb');
const app = express();

app.use('/', require('express-pouchdb')(PouchDB.defaults({prefix: '.db/'}), {
      overrideMode: {
        include: ['routes/fauxton']
      }
    })
);

app.listen(3000);

Then I just acquire this in your index.html file.

<script type="text/javascript">require('./pouchdb-app.js');</script>

Electron starts pulled the index.html and starts pouchdb for you.

Currently, I am trying to get rxdb to work.

Note:

overrideMode: {
   include: ['routes/fauxton']
}

Remove the above for production. See fauxton for information on it.


Just realized if you check out RxDB's electron example. It will help you run just Pouchdb-Server (if you don't want the express app) through using concurrently.

From the example, package.json:

  "scripts": {
    "start": "concurrently \"npm run server\" \"npm run electron\"",
    "electron": "electron .",
    "server": "pouchdb-server --host 0.0.0.0 -p 10102 -m -d /tmp/pouchdb-server/ -n true"

You, then, can use PouchDB instead Angular and just do the same as I did above to access the server.

like image 102
flamusdiu Avatar answered Sep 20 '22 20:09

flamusdiu