Is PouchDB with LevelDB adapter supposed to create a local file?

纵然是瞬间 提交于 2019-12-12 23:07:15

问题


This leaflet example (Leaflet.TileLayer.PouchDBCached) is using an "idb" adapter and for electron/node it looks like I want to use a "leveldb" adapter. So I followed the instructions here: PouchDB in Node.js

In Node.js, the adapter situation is much simpler than in browsers. By default, if you create a PouchDB like this one:

var pouch = new PouchDB('./path/to/db');

then a LevelDB-based database will be created in the directory ./path/to/db. The LevelDB implementation uses LevelDOWN.

In my "main.js" (Electron entry point) I create a db like this:

var dbPath = path.join(__dirname, 'main-db');
var myDB = new PouchDB(dbPath);
console.log('myDB', myDB.adapter);

And though the adapter type is reported as "leveldb" it does not show up on disk.

Question: Where is the database created? I've looked in my app directory, in the node_modules/pouchdb directory. I've even looked for "hidden files" (this is on OSX). What gives? If I dump the db instance to the console, it looks like it was created (in memory). Am I "doing it wrong"?


回答1:


So it turns out I had a couple of things going wrong.

  1. The path I was using was incorrect. Even though I was trying to create the pouchDB instance from a Javascript file attached to an index.html file inside my app folder, this path did not work: './db/todo-db'. I was able to create the db instance using this path: './app/db/todo-db'.

    This seems odd to me and I don't understand it. The __dirname reports that my JS context was './path/to/app/ – so I am already inside the app folder.

  2. I was getting an error message about a mismatch between the NODE version which levelDB (the adapter I was requesting) was compiled for. I was able to solve this by using electron-rebuild in a postinstall call:

In my package.json:

  "scripts": {
    "start": "electron .",
    "postinstall": "electron-rebuild",
   etc.
  }


来源:https://stackoverflow.com/questions/43129478/is-pouchdb-with-leveldb-adapter-supposed-to-create-a-local-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!