0.1.1 • Published 1 year ago

@fabrisoftware/lowdb v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

LowDB | Simple Json Database

lowdb is a simple database that stores data in .json files

instalation

npm i @fabrisoftware/lowdb

Jump To

How To Use

require lowdb on you project

const lowdb = require('@fabrisoftware/lowdb');
const db = new lowdb.asyncDb.Database({
    name: 'test', // name of json file
    directory: './database' // directory to save the database
})

this generate this structure

node-projectroot
└── database
    └── test.json

set

this method saves a value in the database

/*
key: key of value to store on database
value: value to store on database
*/
db.set(key, value)

// example

db.set("Jonh.age", 20);
db.set("Jonh.isAdult", true);

json file structure

{
    "Jonn": {
        "age": 20
        "isAdult": true
    }
}

get

this get data on database

db.get(key) // this return value of key

// example

if(db.get("Jonh.isAdult")){
    console.log("Yes!");
}else{
    console.log("No!");
}

// this print "Yes!"

has

this comprobe if key exists in database

db.has(key) // this returns bolean value

// example
if(db.has("jonh")){
    console.log("this user exists!");
}

delete

this delete data on database

db.delete(key) // this delete the data key

// example

// first you check if the key exists
if(db.has("jonh")){
    db.delete("jonh"); 
}

json data structure

{} //void object
0.1.2-dev

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago