Node的 Flat JSON 文件数据库:lowdb

jopen 11年前

Node的 Flat JSON 文件数据库

  • 无服务器
  • 快捷
  • 事件触发
  • 来自 Lo-Dash 的 50+多个方法

LowDB构建在 Lo-Dash, 这使得它非常不同、独特,相比其他往往是基于MongoDBAPI的无服务器数据库。

LowDB powers JSON Server and JSONPlaceholder.

Usage

var low = require('lowdb')  low('songs').insert({title: 'low!'}) 

Database is automatically created and saved to db.json in a readable format.

{    "songs": [      {        "title": "low!",        "id": "e31aa48c-a9d8-4f79-9fce-ded4c16c3c4c"      }    ]  }

To query data, you can use Lo-Dash methods.

var songs = low('songs').where({ title: 'low!' }).value() 

Or LowDB equivalent short syntax.

var songs = low('songs', { title: 'low!' }) 

Changes can also be monitored.

low.on('add', function(name, object) {    console.log(object + 'added to' + name)  })

Benchmark

get    x 1000    0.837708 ms  update x 1000    4.433322 ms  insert x 1000    11.78481 ms  remove x 1000    24.60179 ms

项目主页:http://www.open-open.com/lib/view/home/1408799295975