微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NeDB

编程之家收集整理的这个编程导航主要介绍了NeDB编程之家,现在分享给大家,也给大家做个参考。

NeDB 介绍

Other NeDB - 用JavaScript编写的嵌入式数据库。可用于Node.js,nw.js,electron和浏览器,100%JavaScript,无二进制依赖。API是MongoDB的一个子集,速度很快。

安装与测试

npm和bower上的模块名称是nedb。

npm install nedb --save # Put latest version in your package.json

npm test # You'll need the dev dependencies to launch tests

bower install nedb # For the browser versions,which will be in browser-version/out

您可以将NeDB用作仅内存数据存储或持久数据存储。一个数据存储区相当于MongoDB集合。构造函数如下使用,new Datastore(options)

例子

// Type 1: In-memory only datastore (no need to load the database)

var Datastore = require('nedb')

,db = new Datastore();

// Type 2: Persistent datastore with manual loading

var Datastore = require('nedb')

,db = new Datastore({ filename: 'path/to/datafile' });

db.loadDatabase(function (err) { // Callback is optional

// Now commands will be executed

});

// Type 3: Persistent datastore with automatic loading

var Datastore = require('nedb')

,db = new Datastore({ filename: 'path/to/datafile',autoload: true });

// You can issue commands right away

// Type 4: Persistent datastore for a Node Webkit app called 'nwtest'

// For example on Linux,the datafile will be ~/.config/nwtest/nedb-data/something.db

var Datastore = require('nedb')

,path = require('path')

,db = new Datastore({ filename: path.join(require('nw.gui').App.dataPath,'something.db') });

// Of course you can create multiple datastores if you need several

// collections. In this case it's usually a good idea to use autoload for all collections.

db = {};

db.users = new Datastore('path/to/users.db');

db.robots = new Datastore('path/to/robots.db');

// You need to load each database (here we do it asynchronously)

db.users.loadDatabase();

db.robots.loadDatabase();

GitHub:https://github.com/louischatriot/nedb

网站描述:用JavaScript编写的嵌入式数据库

NeDB

官方网站:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。