最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NEDB persistance in Electron app - Stack Overflow

programmeradmin1浏览0评论

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
});

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
});
Share asked May 18, 2016 at 21:48 UriilUriil 12.7k11 gold badges53 silver badges71 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

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.

发布评论

评论列表(0)

  1. 暂无评论