Running PouchDB within an Atom package


#1

I’m getting the following error when trying to startup PouchDB 5.0.0 within an Atom package.

This is likely an Atom issue, as I understand Atom does not allow write permissions within a package. However, there is talk of PouchDB working within Atom on the discussion boards.

err {type: "OpenError", name: "OpenError", cause: Error: IO error: database/LOCK: No such file or directory at Error (native), message: "IO error: database/LOCK: No such file or directory"}

Simple code, taken from the PouchDB demo:

const PouchDB = require('pouchdb');

let db = new PouchDB('database');

function dbInit() {
  console.log('seeding db...');
  console.log(db);

  let todo = {
    _id: 'mydoc',
    title: 'test'
  };
  db.put(todo).then(function(response) {
    // handle response
  }).catch(function(err) {
    console.log(err);
  });

  db.get('mydoc').then(function(doc) {
    console.log(doc);
  }).then(function(response) {
    // handle response
  }).catch(function(err) {
    console.log(err);
  });
}

dbInit();

Storage limits with pouchDB and Electron
#2

I’m not sure what this is intended to mean, but one of the major motivations for Atom is to allow reads and writes to the local file system.

The error message seems to indicate that it is attempting to open a file database/LOCK and is unable to because it does not exist. Perhaps the working directory where PouchDB is trying to create your database is one where you don’t have permissions?


#3

Permissions don’t seem to be the problem. I’ve tried with the main directory permission as: drwxrwxrwx.

The error seems to be related to leveldown / levelup installation.

Uncaught (in promise) Error: leveldown not available (specify another backend using the 'db' option).

I’ve tried npm install leveldown within the pouchdb directory, as well as the electron installation method: HOME=~/.electron-gyp node-gyp rebuild --target=0.34.0 --arch=x64 --dist-url=https://atom.io/download/atom-shell within the leveldown directory. No luck.


#4

The issue with LevelDOWN is that you need to recompile it for Atom. There is a tutorial here: https://github.com/nolanlawson/pouchdb-electron#using-leveldb-via-leveldown

Also if you have trouble compiling it for various platforms, you can always use the IndexedDB or the WebSQL adapters instead (also described in the tutorial).


#5

That’s true, you have to compile PouchDB for electron.

I finally figured the underlying issue out.

I was compiling from Typescript -> JS from a different directory. The database path wasn’t compiling properly in the build. Using an absolute path worked.

let db = new PouchDB(__dirname + '/db.json');