cheet-sheet-json-db
v1.0.2
Published
A simple file-based database system
Maintainers
Readme
Max-DB
A lightweight and simple database package for managing entities in a local JSON-based database. This package allows you to define entities, store them in JSON files, and manage basic CRUD operations. It supports handling references between entities and ensures data integrity across different files.
Usage
After installing max-db, you can import and use it like this:
import the package to your server an add :
import { connectDatabase } from "cheet-sheet-json-db";
// Example usage
async function initDatabase() {
await connectDatabase();
console.log("Database connected successfully!");
}
initDatabase();After restarting the application => ⚠️ Database directory 'D:\FullStack_JS\ProjectModels\Db-Json\data' does not exist. Creating... ✅ Database initialized. Server listening on Port 8000
// import Entity and extend your classes
import Entity from "cheet-sheet-json-db/entity.js"; // Adjust this if the file is in a different location
class User extends Entity {
constructor({ name, fullname, isAdmin = false }) {
super();
this.name = name;
this.fullname = fullname;
this.isAdmin = isAdmin;
}
}
export default User;// create new user
// First read all the data in the local DB
const users = await User.readData();
// logic... // Check for duplicate user by name
if (users.some((user) => user.name === data.name)) {
throw new HttpError("User already exists", 409);
}
//
await User.writeData(users);