best.db
v1.2.2
Published
An easy and quick storage unit that relies on objects to store data in JSON format, with TypeScript support
Downloads
27
Maintainers
Readme
What is best.db ?
- It is a easy and quick storage
- Support Typescript & Javascript
Installation
- You need to install the package on your project
npm i best.dbUpdates
- Version (1.2.2) Backup Function Fixed
- Version (1.2.1) PushIndex, PullIndex added
- Version (1.0.9) Support Typescript & Javascript
- Version (1.1.8) You can control the data file path individually for each file
- Version (1.1.6) Added Some Features in Push and Pull Functions
- Version (1.0.7, 1.0.8, 1.1.1, 1.1.3, 1.1.4, 1.1.5, 1.1.7) => Fix Some Errors
- Version (1.0.9) => Added Fetch
- Version (1.1.2) => Change (.) To (..)
How To Use
[-] Typescript
import BestDB from "best.db";
const db = BestDB(); // path = database.json | by default
// OR
const db = BestDB({ path: "./my-database.json" });[-] Javascript
const BestDB = require("best.db").BestDB;
const db = new BestDB(); // path = database.json | by default
// OR
const db = new BestDB({ path: "my-database.json"});[-] Set Function
- Set Data if it is an object, string, number, array, or boolean
db.set(`key`, value); // To Set a Data
db.set(`key`, "This is Value"); // => true
db.set(`key..name`, "test"); // => key = { name: "test" };
db.set(`key..data`, "Hello World"); // => key = { name: "test", data: "Hello World" };
db.set(`key..number`, 0); // => key = { name: "test", data: "Hello World", number: 0 };
db.set(`key..array`, []); // => key = { name: "test", data: "Hello World", number: 0, array: [] };[-] Get & Fetch Functions
- To Get/Fetch The Data From Database(JSON) by key
db.get('key'); // To Get The Data By Key
db.get('key'); // => This is Value
db.get(`key..name`); // => test;
db.fetch('key'); // To fetch The Data By Key
db.fetch('key'); // => This is Value
db.fetch(`key..name`); // => test;[-] Delete Function
- To delete specific data or data from the database
db.delete('key'); // To Delete Data By Key
db.delete('key'); // => true
db.delete(`key..data`); // => key = { name: "test", number: 0, array: [] };[-] Has Function
- To verify whether this data exists or not ( return true or false )
db.has('key'); // To Get True Or False
db.has('key'); // => true
db.has(`key..name`); // => true
db.has(`key..data`); // => false[-] Add Function
- To Add a Number
db.add('key', value);
db.add('key', 5); // => key = 5;
db.add(`key..number`, 1); // => key = { name: "test", number: 1, array: [] };[-] Subtract Function
- To Subtract a Number
db.subtract('key', value);
db.subtract('key', 5); // key = 0
db.subtract('key..number', 1); // => key = { name: "test", number: 0, array: [] };[-] Push Function
- To Push Element/s To Database
- Merge: If you need to merge a array (Look To Examble)
db.push('key', value, merge=false);
db.push('key', "Push"); // key = ["Push"]
db.push('key', ["Push2", "Push3"], true) // key = ["Push", "Push2", "Push3"]
db.push('key..array', "Push 1"); // => key = { name: "test", number: 0, array: ["Push 1"] };
db.push('key..array', ["Push2", "Push3"], true) // key = { name: "test", number: 0, array: ["Push 1", "Push2", "Push3"] }[-] Push Index Function
- Pushes an element into an array at a specific index.
db.pushIndex('key', value, index); // key = ["Push"]
db.pushIndex('key', "SLASH", 1); // key = ["Push", "SLASH"]
db.pushIndex('key', "SLASH", 0); // key = ["SLASH", "Push"][-] Pull Function
- To Pull Element/s from Database
- arrayPull: If you need to Pull some data from array (Look To Examble)
db.pull('key', element, arrayPull=false); // To Pull Element/s From Data
db.pull('key', "Push"); // key = ["Push2", "Push3"]
db.pull('key', ["Push2", "Push3"], true) // key = []
db.pull('key..array', "Push 1"); // => key = { name: "test", number: 0, array: ["Push2", "Push3"] };
db.pull('key..array', ["Push2", "Push3"], true); // => key = { name: "test", number: 0, array: [] };[-] Pull Function
- Removes an element from an array at a specific index.
db.pullIndex('key', index); // key = ["Push", "SLASH"]
db.pullIndex('key', 1); // key = ["Push"]
db.pullIndex('key', 0); // key = ["SLASH"][-] All Function
- All To Get All Database
db.all();
// Exmaple => [ { ID: `test`, data: `Hello World` } ][-] Backup & Reset Functions
- Backup To Make a backup
- Reset To Delete All Database
db.backup("Filepath");
db.reset();Developer
- Developed By :
SLASH
