GithubHelp home page GithubHelp logo

nosqldb's Introduction

Beautifully straight forward NoSQL JSON document DB.

NoSQL DB

npm monthly downloads github release github license

npm install nosqldb --save

Background

This project came from wanting the flexibility in a NoSQL DB syntax, but without the bloat of having an extra database service starting in the background. Sometimes, you just want to store JSON data in a local file, and have intuitive methods that help you store and retrive that data. This's exactly what NoSQL DB does.

Getting Started

Super straightforward. Here are the few steps:

  1. Bring NoSQL DB into your project with npm install nosqldb --save
  2. Create any new data collection with var users = require('nosqldb')('users')
  3. Run your node app. That's it!

Specifying Primary Key

Instead of using the default id primary key, you can pass any string to define your primary key. So if you wanted your users object to have a primary key of user_id, simply var users = require('nosqldb')('users', { primaryKey: 'user_id' }).

API

With each new data collection, you get a series of helpers that easily get your data in and out from local storage. So for clarity, if you var users = require('nosqldb')('users'), these methods are called on your users object.

.all()

Takes no parameters, simply returns all rows in your collection.

.saveItem(item)

Takes an item object, where keys and values are defined. This object will be appended to your collection.

.saveItems(item, item2, item3 ...)

Takes unlimited item objects as parameters, where each item's keys and values are defined. Each item is consecutively appended to your collection.

.create(item, item2, item3 ...)

Alias of saveItems.

.makeEmpty()

Takes no parameters, removes all rows and empties your collection.

.where(predicate)

Takes a predicate, where keys and values are defined. Only rows matching all keys and values in your predicate will be returned.

.findWhere(predicate)

Takes a predicate, where keys and values are defined. Only the first row matching all keys and values in your predicate will be returned.

.deleteWhere(predicate)

Takes a predicate, where keys and values are defined. Only rows matching all keys and values in your predicate will be removed from your collection.

.delete(predicate)

Alias of deleteWhere.

.keepWhere(predicate)

Takes a predicate, where keys and values are defined. Only rows matching all keys and values in your predicate will be saved in your collection. All other rows will be removed from your collection.

.keep(predicate)

Alias of keepWhere.

.updateWhere(predicate, updatedValues)

Takes a predicate and updatedValues, where each has keys and values defined. Only rows matching all keys and values in your predicate will be updated in your collection.

.update(predicate, updatedValues)

Alias of updateWhere.

Primary Key

By default, the primary key is simply id and NoSQL DB auto-generates that identifier for each row (or JSON document). Alternatively, you have the option of overriding the auto-generated identifier. Simply pass your own value for the id parameter in any document save or update method.

Document Hashing

By default, NoSQL DB auto-generates that identifier as a unique hash to that object. That means NoSQL DB maintains unique records for you, right out-the-box. Alternatively, you have the option of overriding this feature. Simply pass the string 'nonunique' for the id parameter in any document save method. This gets you non-unique records in your collection anytime.

Quick Notes

Currently, there's no chaining of methods. Also, you can't use any RegEx in your predicates. These are features that I'll be adding going forward, that is if people are wanting those features.

Also, this modules relies on Node's native fs module. So don't try running this in the browser or in any environment where Node's native fs module doesn't work. Again I'd love to add a browser port, maybe using Google's Level but only if people are wanting that in this project ;)

Happy coding! HQ

nosqldb's People

Contributors

haseebnqureshi avatar

Stargazers

Dmitri Russu avatar

Watchers

James Cloos avatar  avatar Preston Garland avatar  avatar

Forkers

dmitrirussu

nosqldb's Issues

Scale performance i/o latency

Because we're putting all the rows into one json file, this gets significantly slower after roughly 4k to 5k rows, since fs needs to read and then write that much data, every time.

Now comes the time to finally separate each row into its own json item. It'd also be a good idea to check entropy along our doc's hashed id, and also double-check concurrency in read-writes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.