npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dbb

v0.2.1

Published

An easy to use database.

Downloads

3

Readme

dbb

Build Status Dependency Status devDependency Status Coverage Status

NPM

An easy to use database.

Example

var DBB = require('dbb');
var db = DBB('db.json');

db('keys').set('key', 'value');
db('posts').insert({ title: 'DBB is amazing' });

In db.json:

{
  "keys": {
    "key": "value"
  },
  "posts": [
    {
      "_id": "851e4d6-df24-42fb-b478-4a0c93d117e1",
      "title": "DBB is amazing"
    }
  ]
}

To query the data:

db('keys').get('key', function(err, key) {
  // do something with key
});
db('posts').find({title: 'DBB is amazing'}, function(err, post) {
  // do something with post
});

Table of Contents

$ npm install dbb --save

DBB stores data in a field which can be either be an object or an array.

{
  "field": {},
  "field": []
}

get and set method are for a document, also called an object.

// document
"field": {
  "key": "value",
  "key1": 1,
  "key2": 2
}

find, insert, and save are for a collection, which is basically an array.

// collection
"field": [
  { _id: "89cbfd78-8ec8-4338-8140-7a3efa5e89c6", name: "phil", age: 7 },
  { _id: "12f3af49-b2e8-4e60-ae1c-9fb259ae6670", name: "jack", age: 20 },
  { _id: "6f33c2bd-7bbf-4b4d-a8e6-1973a3fa4f63", name: "steve", age: 99 }
]

For each DBB's method, there is a synchronous version of it. For example, get and getSync or find and findSync.

Documents

Collections

DBB(file, options);

Specify what JSON file to use. If it doesn't exist, the JSON file will be created.

Arguments

  1. file (String): JSON file name.
  2. options (Object): Provide options for DBB to used. Currently, there is only one option which is backup. The backup creates a POST request to Hastebin and adds the link to the DBB_BACKUPS field. You can set how long every hour the backup should save.

Examples

var DBB = require('dbb');
var db = DBB('db.json');
// create a back up every 4 hours
DBB('db.json', {backup: 4});
db(field)

Arguments

  1. field (String): Specify what field to query.

Returns

(Object): Methods to use to query the database.

Examples

db(); // default
db('users');
db('posts').insert({title: 'hello world!'}); // converts to array

In json:

{
  "default": {},
  "users": {},
  "posts": [
    {"title": "hello world!"}
  ]
}

Documents

Get a key from the database.

Arguments

  1. key (String): Name of the key.
  2. callback(err, value) (Function): A callback which is called when reading the JSON file has finished, or an error occurs. Value is the key's value.

Examples

db().get('key', function(err, value) {
  if (err) throw err;
  // do something with value
});

Synchronous key.

Arguments

  1. key (String): Name of the key.

Returns

(*): Key's value

Examples

var key = db().get('key');
// do something with key

Get the whole object in the database.

Arguments

  1. callback(err, object) (Function): A callback which is called when reading the JSON file has finished, or an error occurs.

Examples

db().getAll(function(object) {
  // do something with the object.
});

Get the whole object in the database.

Arguments

  1. callback(err, object) (Function): A callback which is called when reading the JSON file has finished, or an error occurs.

Returns

(Object): Object in the database that holds all the key-value pairs.

Examples

var object = db().getAllSync();
// do something with object

Set a key with a value in the database.

Arguments

  1. key (String): Name of the key.
  2. value (*): Value of the key.
  3. callback(err) (Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.

Examples

db().set('key', 'value', function(err, value) {
  if (err) throw err;
  // key is now save in the database
  // do something with value
});

Synchronous set. Returns undefined.

Arguments

  1. key (String): Name of the key.
  2. value (*): Value of the key. the JSON file has finished, or an error occurs. Value is the key's value.

Examples

db().setSync('key', 'value');

Collections

Find a document (object) in the database.

Arguments

  1. document (Object): Document also known as a object.
  2. callback(err, doc) (Function): A callback which is called when reading to the JSON file has finished, or an error occurs. Doc is the document (object).

Examples

db().find({name: 'Phil'}, function(err, doc) {
  if (err) throw err;
  // do something with doc
});

Synchronous find.

Arguments

  1. document (Object): Document also known as a object.

Returns

(Object): Document.

Examples

var phil = db().findSync({name: 'Phil'});

Get the whole collection in the database.

Arguments

  1. callback(err, docs) (Function): A callback which is called when reading to the JSON file has finished, or an error occurs. Docs is an array.

Examples

db().findAll(function(err, docs) {
  if (err) throw err;
  // do something with docs
});

Synchronous findAll.

Returns

(Array): Collection of docs.

Examples

var docs = db().getAll();

Insert a document (object) into the database.

Arguments

  1. document (Object): Document also known as a object.
  2. callback(err, doc) (Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs. Doc is the document inserted.

Examples

db().insert({name: 'Phil', email: '[email protected]'}, function(err, doc) {
  if (err) throw err;
  // do something with doc
});

Synchronous insert. Returns undefined.

Arguments

  1. document (Object): Document also known as a object.

Examples

db().insert({name: 'Phil', email: '[email protected]'});

Remove a key in the database.

Arguments

  1. key (String): Name of the key.
  2. callback(err) (Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.

Examples

db().remove('key', function(err) {
  if (err) throw err;
  // key is now remove from the database
});
db('users').remove({name: 'Phil'}, function(err) {
  if (err) throw err;
  // document is now remove from the database
});

Synchronous sync. Returns undefined.

Arguments

  1. key (String): Name of the key.

Examples

db().removeSync('key');
db('users').removeSync({name: 'Phil'});

Save a document in the database.

Arguments

  1. document (*): Usually an object.
  2. callback(err) (Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.

Examples

db('users').find({name: 'phil'}, function(err, user) {
  if (err) throw err;
  user.money++;
  user.emails.push('[email protected]');
  user.posts = [];
  db('users').save(user, function(err) {
    if (err) throw err;
  });
});

Synchronous save. Returns undefined.

Arguments

  1. document (*): Usually an object.

Examples

var user = db('users').find({name: 'phil'});
user.name = 'jack';
db('users').saveSync(user);

DBB is a convenient method for storing data without setting up a database server. However, if you need high performance and scalability more than simplicity, you should stick to databases like MongoDB.

MIT