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

LinvoDB 特性: 嵌入式文档数据库

程序名称:LinvoDB 特性:

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

LinvoDB 特性: 介绍

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

LinvoDB 特性: 官网

https://github.com/Ivshti/linvodb3

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

相关推荐