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

streamdb

v0.1.7

Published

A Node.js document-oriented JSON DB & API development toolkit

Downloads

4

Readme



Key Features

  • Generated ids (incr, uid)
  • Timestamps (created_at, updated-at)
  • Queries (includes geo-search)
  • Splits JSON store files, as data grows
  • Uses Node Streams to literallly zoom through data

  • Schema validation & settings
  • Parent/subdocument refs
  • Mongoose inspired syntax and modeling

  • Built with Express Framework
  • Simple CRUD starter routes
  • Helper methods to help you customize routes faster
  • Launch as standalone, or mount onto existing server

Launch server with one line of code
Simple promise-based CRUD methods
Automatically creates router + model files

Table of Contents

Usage

Install:

$ npm i streamdb

To use CLI without global install, prefix commands with npx:

$ npx streamdb create --db sampleDB

Or, install a global copy as well:

$ npm i -g streamdb

Create DB:

In terminal:

$ streamdb create --db sampleDB

Or, run in file:

const streamdb = require('streamdb')

streamdb.createDb({ dbName: 'sampleDB' })
  .then(res => console.log(res))
  .catch(e => console.log(e))

Add Collections:

In terminal:

$ streamdb sampleDB --add users 

Or, run in file:

const streamdb = require('streamdb')
const db = new streamdb.DB('sampleDB')

db.addCollection('users')
  .then(res => console.log(res))
  .catch(e => console.log(e))

Add Documents:

const streamdb = require('streamdb')
const db = new streamdb.DB('sampleDB')

const documents = [
  {
    firstname: 'Bugs',
    lastname: 'Bunny',
    email: '[email protected]'
  },
  {
    firstname: 'Scooby',
    lastname: 'Doo',
    email: '[email protected]'
  },
  {
    firstname: 'Tom',
    lastname: 'Cat',
    email: '[email protected]'
  }
]

db.collection('users').insertMany(documents)
  .then(res => console.log(res))
  .catch(e => console.log(e))

Read Documents:

const streamdb = require('streamdb')
const db = new streamdb.DB('sampleDB')

db.collection('users').getById(1)
  .then(res => console.log(res))
  .catch(e => console.log(e))

// using queries:
// db.collection('users')
//  .where('id = 1')
//  .and('firstname = Bugs')
//  .find()
//  .then(..)

// Response object: 
//{
//  success: true,
//  data: [
//    {
//      id: 1,
//      firstname: 'Bugs',
//      lastname: 'Bunny',
//      email: '[email protected]'
//    }
//  ]
//}

Update Documents:

const streamdb = require('streamdb')
const db = new streamdb.DB('sampleDB')

const docUpdate = {
  id: 1,
  email: [email protected]
}

db.collection('users').updateOne(docUpdate)
  .then(res => console.log(res))
  .catch(e => console.log(e))

// using queries:
// db.collection('users')
//  .where('id = 1')
//  .setProperty('email', '[email protected]')
//  .then(..)

// Response object: 
//{
//  success: true,
//  message: 'Document 1 updated successfully'
//  data: [
//    {
//      id: 1,
//      firstname: 'Bugs',
//      lastname: 'Bunny',
//      email: '[email protected]'
//    }
//  ]
//}

Delete Documents:

const streamdb = require('streamdb')
const db = new streamdb.DB('sampleDB')

db.collection('users').deleteMany([2,3])
  .then(res => console.log(res))
  .catch(e => console.log(e))

// Response object: 
//{
//  success: true,
//  message: '2 documents removed from "users" collection'
//  data: [2,3]
//}

Starter Collection Routes

Creating new collections scaffolds a new Router file with the following routes you may edit/add to:

Example GET (all documents) route in template:


Using Schema Validation

Starter Schema Model Template:

Edit template if you wish to add validation and document settings:

// User Model
const streamdb = require('streamdb')
const Schema = streamdb.Schema

const User = new Schema({
    id: streamdb.Types.$incr,
    firstname: String,
    lastname: String,
    email: {
    	type: String,
	required: true,
        maxlength: 100
    }
}, 
    {
        strict: false,
        timestamps: {
            created_at: true,
            updated_at: true
    }
})

module.exports = streamdb.model('User', User)

Launching/Using Server

const streamdb = require('streamdb')

const app = streamdb.server('sampleDB', 'api', 3000)

// open browser (or send GET query)..
// get all --> get(): http://localhost:3000/api/users
// get by id --> getById(1): http://localhost:3000/api/users/1

// sending POST request with JSON data in body..
// add many --> insertMany(docs): http://localhost:3000/api/users

// in POST body:
// [{
//  "firstname": "john",
//  "lastname": "smith",
//  "email": "[email protected]"
//	},
//	{
//  "firstname": "mary",
//  "lastname": "jane",
//  "email": "[email protected]"
//	}]

▲ back to top


Tests

Tests are implemented using the Jest Framework, and located in the __tests__ directory.

To run tests, fork/clone a copy of https://github.com/fabiantoth/streamdb.git locally, install all dev/dependencies and run:

$ npm test

Run coverage report:

$ npm run test-coverage

What's Next

  • [x] ~~remove legacy 'default' workflow from codebase~~
  • [x] ~~add populate() to chainQuery helper~~
  • [ ] add 'unique' index schema option
  • [ ] add text-search feature
  • [ ] build demo w/FE Framework
  • [ ] refactor cache to support multiple dbs
  • [ ] add CI automation

Stability Notice

  • streamDB is mainly for prototyping, do not use in production, or use sensitive/important data.
  • Early v0.x.x updates may be breaking, experimental, or temporary (keep track of updates, CHANGELOG).