DailyJS

LowDB

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

libraries JSON databases node modules

LowDB

Posted by Alex R. Young on .
Featured

libraries JSON databases node modules

LowDB

Posted by Alex R. Young on .

LowDB (GitHub: typicode / lowdb, License: MIT, npm: lowdb) by typicode is a JSON database that uses Lo-Dash. Rather than using a MongoDB-inspired API, it feels more like functional JavaScript.

Data is queried using familiar chained operators, ending in value when you want to obtain the result:

var topFiveSongs = low('posts')  
  .where({ published: true })
  .sortBy('views')
  .first(5)
  .value();

LowDB accepts some configuration options, allowing you to control how it behaves. For example, if you want to use it like an in-memory database, then you can set autoSave to false:

var low = require('lowdb')  
low.autoSave = false;  

There's also a short syntax API for the basic operations. To perform a where query, you can do this:

low('songs', {title: 'low!'})  
// -> low('songs').where({title: 'low!'}).value()

low('songs', {published: false}, {published: true})  
// -> low('songs').updateWhere({published: false}, {published: true}).value()

It doesn't seem to work with localStorage, which I think would be cool, but it might work with Browserify.