Skip to content

afrzhussain/File-Based-Key-Value-Store

Repository files navigation

Installation

Install the dependencies and devDependencies

$ npm i

Usage

const Store = require("./index");

// create an instance
const mystore = new Store();
// or 
const mystore = new Store("/path-to-file");

Create functionality

.create( key(type : string,max-length: 32), JSON-data, time-to-live(type: Number), callBack function(optional))

mystore.create("key",{dat:"JSON-DATA"},timeToLive,()=>{
    // do operation after creating the data
    console.log(mystore.read("key"))
});

// throws Errors :
            // if key-value already exists
            // if invalid json format

Read functionality

.read( key(type : string,max-length: 32) , callBack function(optional))

mystore.read("key") 

// throws Errors :
            // if key-value does not exists
            // if no key given
            // time-to-live of key-value-data is expired

Delete functionality

.delete( key(type : string,max-length: 32) , callBack function(optional))

mystore.delete("key",()=>{
    // do operation after deletion
    console.log(mystore.read("key")) //throws error
});
// throws Errors :
            // if key-value does not exists
            // if no key given
            // time-to-live of key-value-data is expired

Mutli Thread Usage

const { Worker, isMainThread } = require('worker_threads');

 try{
        const two = new Worker("./test2.js");
        const one = new Worker("./test1.js");
    }
    catch(err)
    {
        console.log(err)
    }

About

Key-Value File Based Local Storage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published