NEDB persistance in Electron app

久未见 提交于 2019-12-23 17:10:42

问题


I am trying to connect to nedb from electron app. CRUD operations work great. BUT I don't see db file (D:/my.db, checked for hidden files). File exists somewhere, because it keeps data even after machine reboot. I suspect that electron threats my path as relative, but I can find it anywhere.

var Datastore = require('nedb'), db = new Datastore({filename : 'D:/my.db', autoload: true});
var doc = { hello: 'world'
           , n: 5
           , today: new Date()
           , nedbIsAwesome: true
           , notthere: null
           , notToBeSaved: undefined  // Will not be saved
           , fruits: [ 'apple', 'orange', 'pear' ]
           , infos: { name: 'nedb' }
           };

db.insert(doc, function (err, newDoc) {   // Callback is optional
   // newDoc is the newly inserted document, including its _id
   // newDoc has no key called notToBeSaved since its value was undefined
});

回答1:


The doc says

If you specify a filename, the database will be persistent, and automatically select the best storage method available (IndexedDB, WebSQL or localStorage) depending on the browser.




回答2:


I found a way to work around this. When creating the datastore in the main.js and making it global, nedb won't use the indexedDB but a local file as specified.

Then in the renderer process get the datastore via Electron.Remote



来源:https://stackoverflow.com/questions/37310666/nedb-persistance-in-electron-app

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