0.0.2 • Published 9 months ago
hyper-jdb v0.0.2
Hyper JSON Database (HyperJDB)
An amazing and simple json database
Instalation
npm i hyper-jdbTable 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` fileMethods
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") // 20has(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") // falsedelete(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
Copyright 2023, Álvaro Poblador