Excel-DB
A Node.js wrapper that treats Excel files as a lightweight database with a Schema-like API.
Features
- ✅ Schema-based validation - Define your data structure with types and constraints
- ✅ Primary keys and unique constraints - Automatic validation and constraint checking
- ✅ CRUD operations - Create, Read, Update, Delete with a simple API
- ✅ Automatic file management - Creates Excel files and worksheets as needed
- ✅ Modern ES6+ JavaScript - Clean, modern codebase
- ✅ Built on ExcelJS - Reliable Excel file handling
Installation
npm install @guru322/excel-db
Quick Start
import Model from '@guru322/excel-db';
// Define a model with schema
const User = new Model('User', {
id: { type: 'string', primary: true },
name: { type: 'string', required: true },
email: { type: 'string', unique: true },
age: { type: 'number' }
});
// Create a new user
const user = await User.create({
name: 'John Doe',
email: 'john@example.com',
age: 30
});
// Find user by ID
const foundUser = await User.find(user.id);
// Get all users
const allUsers = await User.findAll();
// Update user
const updatedUser = await User.update(user.id, { age: 31 });
// Delete user
await User.delete(user.id);
Schema Definition
Define your data structure with validation rules:
const schema = {
fieldName: {
type: 'string|number|boolean|date', // Data type
primary: true, // Primary key (one per model)
unique: true, // Unique constraint
required: true // Required field
}
};
API Reference
Model Methods
create(data)
- Create a new record
find(id)
- Find record by primary key
findAll()
- Get all records
update(id, data)
- Update record by primary key
delete(id)
- Delete record by primary key
Error Handling
The package includes custom error types:
ValidationError
- Thrown when data doesn't match schema
UniqueConstraintError
- Thrown when unique constraints are violated
License
MIT