codingtuto / LiteJsonDB-Node

LiteJsonDB is a lightweight, local JSON database for Node.js. It provides a simple and intuitive API for managing JSON data. This package is a fork of the Python LiteJsonDB project, adapted for Node.js, and is currently about 45% complete
2 stars 3 forks source link

๐Ÿ“š LiteJsonDB Documentation

LiteJsonDB is a lightweight local JSON database for Node.js, designed to simplify JSON data management in your projects. This package is a fork of the Python LiteJsonDB project, adapted for Node.js. Currently, this project is about 45% complete, meaning it's already super functional but still has room for more cool features.

LiteJsonDB is like a nifty little vault for your JSON data. It provides a simple and intuitive API for adding, modifying, retrieving, and deleting data. You don't need to worry about the complexities of heavier database systems. With LiteJsonDB, you can focus on what really matters: your data.

๐Ÿ”ง Installation

To get started with LiteJsonDB, you need to install it via npm. It's super easy! Just run the following command in your terminal:

npm install litejsondb

๐ŸŽฏ Usage

๐Ÿ Initialization

Once installed, you can import LiteJsonDB and initialize your database like this:

const litejsondb = require('litejsondb');
const db = new litejsondb();

๐Ÿ“ฅ Adding Data

Adding data is a breeze with LiteJsonDB. Use the setData method to store information in the database:

db.setData('users/1', { name: 'Aliou', age: 30 });
db.setData('products/1', { name: 'Laptop', price: 999.99 });

๐Ÿ”„ Editing Data

To update existing data, use editData. You can modify information without erasing whatโ€™s already there:

db.editData('users/1', { age: 31 });

๐Ÿ“œ Getting Data

The getData method allows you to retrieve data from the database. You can specify the exact path of the data you want to access. Hereโ€™s how you can use it:

console.log('User 1:', db.getData('users/1'));
console.log('Product 1:', db.getData('products/1'));

Explanation:

โŒ Deleting Data

Need to delete data? No problem! The deleteData method allows you to remove specific information. You have two options:

  1. Delete Specific Entry: If you want to delete a specific entry, provide the exact key path:

    db.deleteData('products/1');
    

    This command will remove only the data located at 'products/1', leaving other data intact.

  2. Delete All Data Under a Path: If you want to delete all data under a specific key path, you can use a nested key path:

    db.deleteData('products');
    

    This will remove the entire 'products' section, including all entries within it, such as 'products/1' and any other nested products.

Explanation:

๐Ÿ” Searching Data

You can also search your data with searchData. This helps you find specific values anywhere in the database:

const searchResults = db.searchData(db.getData(), 'Aliou');
console.log(searchResults);

๐Ÿ› ๏ธ Utility Functions

LiteJsonDB includes some handy utility functions:

Hereโ€™s how you can use them:

const hashedPassword = db.hashPassword('myPassword123');
const isPasswordValid = db.checkPassword(hashedPassword, 'myPassword123');
const defaultValue = db.getOrDefault(testObj, 'country', 'Unknown');
const keyExists = db.keyExistsOrAdd(testObj, 'country', 'Unknown');

๐Ÿ“– Example Code

Hereโ€™s a small example to show you how everything works together:

const litejsondb = require('litejsondb');
const db = new litejsondb();

// Set initial data
db.setData('users/1', { name: 'Aliou', age: 30 });
db.setData('products/1', { name: 'Laptop', price: 999.99 });

// Edit data
db.editData('users/1', { age: 31 });

// Get data
console.log('User 1:', db.getData('users/1'));
console.log('Product 1:', db.getData('products/1'));

// Delete Data
db.deleteData('products/1');

// Show the entire database content
console.log('Database Content:', db.showDb());

๐Ÿ› ๏ธ Future Development

LiteJsonDB is a fork of our Python LiteJsonDB package. Iโ€™ve managed to reproduce about 45% of the work so far, and it's already functional with features like adding, editing, and deleting data. However, thereโ€™s still a lot to be done!

If you have skills in both Node.js and Python, you might want to dive into the code and contribute to the Node.js project. Currently, Iโ€™m focused more on Python development and may not have enough time to add all the desired features to this package.

Your contributions could help move the project forward and make it even better. Feel free to explore the code and get involved!

๐Ÿ’ฌ Contribution

If you want to contribute to the project, feel free to open issues or pull requests. Every contribution is welcome to help make this project even better!