Giter Club home page Giter Club logo

hyper-jdb's Introduction

Hyper JSON Database (HyperJDB)

version license downloads

An amazing and simple json database

Instalation

npm i hyper-jdb

Table of contents

Usage

// Using Node.js `require()`
const hyperJDB = require('hyper-jdb');

// Using ES6 imports
import hyperJDB from 'hyper-jdb';

const database = new hyperJDB("users") // This will create the folder `databases` and the `users.json` file

Methods

set(key, value)

Sets a value into the database.

database.set("language", "english")
/*
    {
        "language": "english"
    }
*/

// You can use dots to specify a new property 
database.set("user1.name", "Álvaro")

/* 
    {
        "language": "english",
        "user1": {
            "name": "Álvaro"
        }
    }
*/

get(key)

Gets an existing key from the database.
Returns the value of the given key.

/*
    {
        "user1": {
            "name": "Álvaro",
            "age": 16
        },
        "user2": {
            "name": "Juan",
            "age": 20
        }
    }
*/

database.get("user1.name") // "Álvaro"
database.get("user2.age") // 20

has(key)

Searches the given key.
Returns true if it exists or false if not.

/*
    {
        "user1": {
            "name": "newalvaro9",
            "hobbies": ["Gym", "Coding]
        }
    }
*/

database.has("user1.hobbies") // true
database.has("user1.age") // false

delete(key)

Deletes an existing key from the database.

/*
    {
        "user1": {
            "name": "Álvaro",
            "age": 16,
            "hobbies": ["Gym", "Coding", "Cycling"]
        }
    }
*/

database.delete("user1.hobbies[1]") // Deletes Coding property as it is hobbies[1]

/*
    {
        "user1": {
            "name": "Álvaro",
            "age": 16,
            "hobbies": ["Gym", "Cycling"]
        }
    }
*/

push(key, value)

Pushes to the given array a new value.
Returns the updated array.

/*
    {
        "user1": {
            "name": "Álvaro",
            "age": 16,
            "hobbies": ["Gym", "Coding", "Cycling"]
        }
    }
*/

database.push("user1.hobbies", "Climbing")

/*
    {
        "user1": {
            "name": "Álvaro",
            "age": 16,
            "hobbies": ["Gym", "Coding", "Cycling", "Climbing"]
        }
    }
*/

add(key, quantity)

Adds to the given key the quantity provided (must be a Number).
Returns the updated key value.

/*
    {
        "user1": {
            "name": "Álvaro",
            "money": 430
        }
    }
*/

// Adds 150 to 430 money property
database.add("user1.money", 150) // 580

/*
    {
        "user1": {
            "name": "Álvaro",
            "money": 580
        }
    }
*/

substract(key, quantity)

Substracts from the given key the quantity provided (must be a Number).
Returns the updated key value.

/*
    {
        "user1": {
            "name": "Álvaro",
            "money": 430
        }
    }
*/
// Substracts 240 from 430 money 
database.add("user1.money", 240) // 190

/*
    {
        "user1": {
            "name": "Álvaro",
            "money": 190
        }
    }
*/

drop()

Clears all the data in the .json file

database.drop() // Clears the database 

Help

Have any doubts or suggestions?
Send me a private message on Discord: @newalvaro9

License

MIT

Copyright 2023, Álvaro Poblador

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.