Skip to content

AbmSourav/localdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocalDB

LocalDB is a NodeJS CRUD API. It uses local file system for CRUD operation. It's a promise based API.



Installation

npm i @abmsourav/localdb


API

GET localDB.get()

POST localDB.set(jsonObject)

INSERT localDB.insert(jsonObject, jsonObject)

UPDATE localDB.update(jsonObject, jsonObject)

DELETE localDB.remove(jsonObject)

SEARCH localDB.search(string, string, bool)

SEARCH localDB.searchByValue(string, bool)


Initialization

create a json file on your project root and initialize like below. Please note: It must be a json file.

const ldb = localDB('./db.json');

API Uses

const {localDB} = require('@abmsourav/localdb');
const ldb = localDB('./db.json');

const data = {names: "Sourav", email: "[email protected]"};

// add new data
ldb.set(data)
	.catch( (err) => console.log(err) );

// Insert data on and existing object
ldb.insert({"id": "1247flsf"}, {"Full Name": "Keramot UL Islam"})	// 1. find the object, 2. add property and value
	.catch( (err) => console.log(err) );

// get data from localDB
ldb.get()
	.then( (data) => console.log(data) ) // [ {name: 'Sourav', email: '[email protected]'} ]
	.catch( (err) => console.log(err) );

// update data
ldb.update({"id": "abm"}, {name: "AbmSourav"}) // args: 1.where update'll made, 2.new data
	.catch( err => console.log(err) );

// Delete data
ldb.remove({name: "Abm Sourav"})
	.catch( err => console.log(err) );

// Search unique data
ldb.search("id", "123454ls")	// key and value
	.then( data => console.log(data) );

// search all matches data
ldb.search("name", "Sourav", false)	// key, value and unique
	.then( data => console.log(data) );

// Search all data that matches this value 
ldb.searchByValue("Abm Sourav")
	.then( data => console.log(data) );

// Search unique data that matches the value
ldb.searchByValue("Abm Sourav", true)
	.then( data => console.log(data) );

.