Giter VIP home page Giter VIP logo

shell-json-db's Introduction

๐Ÿš Shell DB

ShellDB is a simple and easy-to-use JSON database ๐Ÿš

ShellDB is a simple and easy-to-use JSON database. If you are looking for a lightweight database that needs zero configuration and is flexible and fast, ShellDB is definitely the solution. Supports basic CURD queries.

ShellDB handles storing and retrieving data between JSON and a Javascript array of objects.

//Create Databse
const db=new Jdb('db')

//Create collection
const users=db.createCollection('users');

//saving collection
users.save({});

Features

  • Lightweight
  • Minimalist and easy to learn API
  • Query and modify data using plain JS
  • Atomic write
  • Interact with data on Shell DB efficiently including creating, reading, updating, and deleting (CRUD)

Install

npm i shell-json-db

Example

const {Jdb} = require('shell-json-db');

const db=new Jdb('db')
const users=db.createCollection('users');
users.save({});

Methods

Create DB

Shell DB must be created before working with it. For that use the Constructor method with the database name.

    const db=new Jdb('db_name','path')

This will create a directory with the database name in the path given, path is not mandatory by default, will create the same place

Create Collection

Collections are groups of JSON Objects. The objects within a collection may have different fields. In a relational database system, a collection is equivalent to a table. It exists within the database.

    const users=db.createCollection('users');

When creating a collection, if there are no objects to save, then the files should be created only if an insert happens

save() method allows you to insert one or more document into a collection.

    collection.save({name:'John'})

example

    const users=db.createCollection('users');
    users.save({name:'John'})

One object will be saved inside the collection after running save() ,ShellDB will add the _id field and generate a unique identifier for it before inserting.

Insert many

    users.save([{name:'John'},{name:'Mary'}])

find()

The find() method searches for JSON Objects that satisfy a given condition and returns the matching documents.

Syntax

collection.find({})

Example

    users.find({name:'John'})

    {
        _id:'TB1gd6-DbOM6lpg4YG8oJ'
        name:'john'
    }

Note : Currently, Find() does not support complex or multiple conditions. It only supports searching a single field.

Update

With the save() method, you can update a JSON object that satisfies a condition. Does not support complex or multiple conditions. It only supports searching a single field.

    users.save({
        _id:'TB1gd6-DbOM6lpg4YG8oJ'
        name:'Jack'
    })

Delete one

Use the delete() method to remove a single object from a collection that satisfies a condition. If more than one satisfies, delete only one.

users.delete({_id:'TB1gd6-DbOM6lpg4YG8oJ'})

Delete All

users.deleteAll()

Limits

It is possible to experience performance issues when you have JavaScript objects larger than 10MB. When you call save(), the entire collection is serialized and written to storage.

ShellDb is recommended for low-load use cases and POC work. We recommend MongoDB for higher loads

shell-json-db's People

Contributors

midhunz avatar

Watchers

 avatar

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.