如何在NeDB中实现持久存储? [英] How to achieve persistent storage in NeDB?

查看:400
本文介绍了如何在NeDB中实现持久存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在节点Webkit中尝试了NeDB,它在内存数据上可以正常工作,但不能存储在持久性存储中.

I tried NeDB in node-webkit it's working fine on in memory data but not able to store in persistent storage.

推荐答案

肯定没有node-webkit或nedb专家,但这就是我做到的方法和有效的方法.

definitely no node-webkit or nedb expert but this is how I did it and it worked.

mvanderw在评论中已经提到,一定要确保选中自动加载选项.

As already mentioned by mvanderw in the comments, definitely make sure to check the autoload option.

例如,这是我对一个简单的node-webkit/angular todo应用程序的配置:

This is for example my configuration for a simple node-webkit/ angular todo app:

var Datastore = require('nedb'),                                                                                                                                              
    path = require('path'),
    db = new Datastore({ filename: path.join(require('nw.gui').App.dataPath, 'todo.db'), autoload: true });

当我重新启动应用程序时,所有待办事项仍然存在,我已经准备好了.

When I restart the app, all todos are still there and I'm ready to go.

希望这会有所帮助

斯科特要求的示例

var Datastore = require('nedb'), 
path = require('path'),
db = new Datastore({
  filename:path.join(require('nw.gui').App.dataPath, 'todo.db'),
  autoload: true
}); 

var todoServices = angular.module('todoServices', []);

todoServices.factory('Todo', function($q) {
  return { 
    getAll: function(){ 
      var defer = $q.defer();
      db.find({ 
        //...some criteria
      },
      function(err, docs) {
        defer.resolve(docs);
      });
      return defer.promise;
    }, //...moar code
  }
});

类似这样的事情...

Something like this...

这篇关于如何在NeDB中实现持久存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆