嵌入式文档数据库 LinvoDB

稿件来源: 互联网   撰稿作者: 匿名   发表日期: 2015-03-09   阅读次数: 376   查看权限: 游客查看

LinvoDB 是一个 Node.js/NW.js 的嵌入式数据库引擎,类似 MongoDB 和类 Mongoose 数据库,提供类似的接口,基于 NeDB 开发。

特性:

  • 类 MongoDB 的查询引擎

  • 基于 LevelUP 的持久化,可选择不同后端

  • NW.js 友好 - JS-only backend is Medea

  • 高性能 - steady performance unaffected by DB size - queries are always indexed

  • 自动索引

  • Live queries - make the query, get constantly up-to-date results

  • Schemas - built-in schema support

  • Efficient Map / Reduce / Limit

示例代码:

var LinvoDB = require("linvodb3");
var modelName = "doc";
var schema = { }; // Non-strict always, can be left empty
var options = { };
// options.filename = "./test.db"; // Path to database - not necessary 
// options.store = { db: require("medeadown") }; // Options passed to LevelUP constructor 
var Doc = new LinvoDB(modelName, schema, options); // New model; Doc is the constructor
 
LinvoDB.dbPath // default path where data files are stored for each model
LinvoDB.defaults // default options for every model

插入数据:

// Construct a single document and then save it
var doc = new Doc({ a: 5, now: new Date(), test: "this is a string" });
doc.b = 13; // you can modify the doc 
doc.save(function(err) { 
    // Document is saved
    console.log(doc._id);
});
 
// Insert document(s)
// you can use the .insert method to insert one or more documents
Doc.insert({ a: 3 }, function (err, newDoc) {
    console.log(newDoc._id);
});
Doc.insert([{ a: 3 }, { a: 42 }], function (err, newDocs) {
    // Two documents were inserted in the database
    // newDocs is an array with these documents, augmented with their _id
 
    // If there's an unique constraint on 'a', this will fail, and no changes will be made to the DB
    // err is a 'uniqueViolated' error
});
 
// Save document(s)
// save is like an insert, except it allows saving existing document too
Doc.save([ doc, { a: 55, test: ".save is handy" } ], function(err, docs) { 
    // docs[0] is doc
    // docs[1] is newly-inserted document with a=55 and has an assigned _id
 
    // Doing that with .insert would throw an uniqueViolated error for _id on doc, because it assumes all documents are new
});

更多教程:https://github.com/Ivshti/linvodb3

 

 

关键词: 数据库,nodejs   编辑时间: 2015-03-10 16:12:56

  • 感到高兴

    0

    高兴
  • 感到支持

    0

    支持
  • 感到搞笑

    0

    搞笑
  • 感到不解

    0

    不解
  • 感到谎言

    0

    谎言
  • 感到枪稿

    0

    枪稿
  • 感到震惊

    0

    震惊
  • 感到无奈

    0

    无奈
  • 感到无聊

    0

    无聊
  • 感到反对

    0

    反对
  • 感到愤怒

    0

    愤怒
0%(0)
0%(0)
共有0 条评论 发言请遵守【相关规定

网友评论

会员头像
发 表同步腾讯微博    验证码:  点击更新请先登陆
  • 暂无评论
关闭模块文章图片 article Pictrue
  • 我的妈妈爸爸
  • 基于koa2+mysql+vue2.0+Element阳光内容管理系统
  • 代码覆盖率工具 Istanbul 入门教程
  • 全栈工程师的武器——MEAN
  • 9款超炫的 CSS3 复选框(Checkbox)
  • 微信开发在线翻译功能
  • CSS3那些不为人知的高级属性
  • 给easyui的datebox添加清空事件
  • flash写字效果
  • kendoUI系列教程之DropDownList下拉菜单
  • kendoUI系列教程之datetimepicker日期时间选择
  • kendoUI系列教程之datepicker日期选择
  • kendoUI系列教程之combobox下拉列表框
  • kendoUI系列教程之colorpicker
  • kendoUI系列教程之calendar日历表
  • kendoUI系列教程之autocomplete自动补齐