data-store-local
v1.0.0
Published
data-store-assignment
Downloads
3
Maintainers
Readme
Key Value Data-Store
This is a file based Key value data store built using node js
Core Functionalities
- Supports CREATE , READ , DELETE and UPDATE operation
- Restricts key size to 32 chars and value size to 16KB
- Allows client to instantiate the class and work on
- File can be created using optional file path , if it is not provided it will be created in current working directory
- Allows only one client to access file at a time
- Every key will have a optional timeToLive property
- Uses Singleton approach
- Thread safe
Steps to run file locally:
- run
npm i
to install dependencies - run
npm start
to run the application [ This will run the sample client file provided in the repo ] - run
npm test
to run tests
Usage
Import the data store
let dataStore = require("./src/dataStore")
Creating an instance for the dataStore
This takes two arguments clientId and file path(optional)
note: clientId
is a four digit number provided by user, it restricts the file access to only one client process at any given time in a computer
let clientId = 2343; //sample clientId
let myDataStore = new dataStore(clientId);
let instance = myDataStore.getInstance()
Create operation
let key = "person1";
let value = { age: 22, userId: 2345, city: "chennai" };
let timeToLive = 3;
instance.create(key, value, timeToLive);
Read operation
let myValue = instance.get("person1");
Delete operation
instance.delete("person1");
Update operation
let newValue = { age: 24, userId: 2345, city: "pune" };
instance.update("person1", newValue);