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

dashdb

v1.2.6

Published

Beautifully straight forward NoSQL JSON document DB.

Downloads

84

Readme

Quick, simple, durable JSON document DB for quick alpha rollouts, complete with AWS S3 backups with customizable chron scheduling.

DashDB

npm monthly downloads github license

npm install dashdb --save

Purpose & Features

For (1) quickly spinning up alpha projects, (2) without worry about database drivers, connection strings, and separate databases, (3) non-relational or relational style JSON document storing, (4) complete with backups and custom scheduling onto AWS S3, (5) with document hashing, (6) atomic file writing, (7) UUID like id generation, (8) primary key overrides, and (9) created and modified timestamps and generation (with modifiable keys).

Getting Started - Easy Start

var users = require('dashdb')('users');

// view all available methods on the users collection
console.log(users);

Options - Intermediate / Advanced Start

var options = {
	pk: 'id', /* primary key */
	pkEntropy: 32, /* primary key entropy */
	hk: 'hash', /* hash key */
	ck: 'created', /* created key */
	mk: 'modified' /* modified key */,
	uid: null, /* user id for any temporary writes, user permissions */
	gid: null, /* group id for any temporary writes, group permissions */
	autoWrite: true, /* whether data is automatically written to filesystem on any change, except for empty() */
	backupSchedule: '* 0 * * *', /* chron schedule for every midnight, @see https://www.npmjs.com/package/node-schedule */
	s3BucketName: '', /* bucket where data backups will be uploaded onto */
	s3BucketPath: 'dashdb/', /* defaulting to uploading any s3 files into a folder, in the bucket */
	s3AccessKey: '', /* aws access key for s3 put object permissions */
	s3SecretAccessKey: '', /* aws secret access key for s3 put object permissions */
	s3FileKey: `moment().format('YYYY/MM') + '/' + moment().format() + '-' + path.basename(filepath)` /* js eval to create file key onto s3 */
};

var users = require('dashdb')('users', options);

AWS S3 Backups - Configuration

To keep things simple yet flexible, our DashDB's AWS backups work on a collection by collection basis. That way, you can set them all to the same bucket, same backup schedule, same folder - or not!

Every backup is timestamped and fully customizable. For ease and convenience, here are the relevant options you'd need to initialize any collection for easy and automatic backups.

Please note: this is not a typical chron, but stays alive with the node application. In other words, if your app goes down, so will this backup protocol. While this might seem like a weakness, this can be a strenth in prototyping quickly. If you use any keep-alive script to maintain your app, or even Elastic Beanstalk, your data backups should work well.

var options = {
	backupSchedule: '* 0 * * *', /* chron schedule for every midnight, @see https://www.npmjs.com/package/node-schedule */
	s3BucketName: '', /* bucket where data backups will be uploaded onto */
	s3BucketPath: 'dashdb/', /* defaulting to uploading any s3 files into a folder, in the bucket */
	s3AccessKey: '', /* aws access key for s3 put object permissions */
	s3SecretAccessKey: '', /* aws secret access key for s3 put object permissions */
	s3FileKey: `moment().format('YYYY/MM') + '/' + moment().format() + '-' + path.basename(filepath)` /* js eval to create file key onto s3 */
};

var users = require('dashdb')('users', options);

AWS S3 Backups - Run or Scheduling

To prevent any scenario with duplciative data backups onto S3, from say having multiple instances of any collection loaded for a number of users, use either the s3() or scheduleS3() methods on any collection with the main script for your app.

require('dashdb')('users').s3() starts backing up your collection data onto S3 without delay

require('dashdb')('users').scheduleS3() initiates the backup schedule for your data, according to the backupSchedule you've specified, or the default timing for once every day at midnight

For example, okay use: After defining your ExpressJS app, calling scheduleS3() onto each collection.

For example, not okay use: Calling scheduleS3() whenever a request is made and completing a query against any collection.

Primary Key

By default, the primary key is simply id and DashDB auto-generates that identifier for each row (or JSON document). Alternatively, you have the option of overriding the auto-generated identifier by simply passing your own value for the id.

Additionally, you can override the default id naming convention with the following option, along with the entropy involved in generating the UUID like value, if you're relying on DashDB to generate that primary key:

var options = {
	pk: 'id', /* primary key */
	pkEntropy: 32, /* primary key entropy */
};

var users = require('dashdb')('users', options);

Document Hashing

To help with enforcing uniqueness of data records througout your application, DashDB creates and stores a document hash. This is generated by taking hashing the entire record, minus its primary key, created key, modified key, or its resulting hash key.

You can override the default hash naming convention with the following option, or completely disable the hashing mechanism by passing an empty string:

var options = {
	hk: 'hash' /* hash key */
};

var users = require('dashdb')('users', options);

Auto Write - Syncing or Committing

By default, any manipulations onto your collection data will be persisted to the saved version on your filesystem. By passing a boolean of false to option autoWrite, you can disable this and manually call either sync() or commit() on any collection and save any manipulations to your collection data.

var options = {
	autoWrite: true /* whether data is automatically written to filesystem on any change, except for empty() */
};

var users = require('dashdb')('users', options);

require('dashdb')('users').commit() persists any collection data manipulation or additions onto the filesystem

require('dashdb')('users').sync() is an alias of commit()

Atomic File Writes

For accomodating potentially heavy and or concurrent file writes between multiple users, DashDB leverages the work from write-file-atomic and exposes two parameters (both require integers) that can help ensure the intregity of data during race conditions or high concurrency:

var options = {
	uid: null, /* user id for any temporary writes, user permissions */
	gid: null /* group id for any temporary writes, group permissions */
};

var users = require('dashdb')('users', options);

Query Methods

require('dashdb')('users').all() retrieves all the records for that collection

require('dashdb')('users').append(item1, item2, ...) inserts any number of items into your collection

require('dashdb')('users').add(item1, item2, ...) is an alias of append()

require('dashdb')('users').create(item1, item2, ...) is an alias of append()

require('dashdb')('users').delete(predicate) removes any records matching that predicate object

require('dashdb')('users').empty() completely removes all records from the collection and should be used with caution

require('dashdb')('users').update(predicate, values) updates any records matching the predicate object with the values object

require('dashdb')('users').where(predicate) retrieves all records matching the predicate object

require('dashdb')('users').filepath returns the data path to where the collection json is stored on disk