lazydb

0.1.4 • Public • Published

node-lazydb

A simple, lazy, json based data store for small projects. It's not fast, it's not horribly smart, but it just works™.

Creating a database

var lazydb = require('lazydb');
var users = lazydb('users.db');

Setting a key

Saves an object to 'key'

users.set('key', { data: 'contents' }, function (err) {
  if (!err) console.log('hooray!');
});

Getting a key

Gets the data associated with 'key' and returns the data object as data

users.get('key', function (err, data) {
  console.log(data.data); // 'contents'
});

Querying

Currently only supports one query per call.. returns a dictionary of findings

users.find({ data: 'contents' }, function (err, results) {
  for (var index in results) {
    console.log(index, JSON.stringify(results[index]));
  }
});

There is also a findOne function that will return a single matching item, rather than a set of all matches

users.findOne({ data: 'contents' }, function (err, result) {
    console.log(JSON.stringify(result));
});

Getting all documents

Returns a dictionary of all keys in the database

users.getAll(function (results) {
  for (var index in results) {
    console.log(index, JSON.stringify(results[index]));
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i lazydb

Weekly Downloads

5

Version

0.1.4

License

none

Last publish

Collaborators

  • nlf