nixabase
Version:
A lightweight and flexible database for JSON and TXT with memory caching and image compression
126 lines (82 loc) • 3.26 kB
Markdown
# Nixabase
Nixabase is a lightweight, flexible, and efficient database management system for Node.js applications. It provides a simple interface for storing and retrieving data in both JSON and TXT formats, with additional features like memory caching and image compression.
## Features
- **Dual Format Support**: Store data in either JSON or TXT format.
- **Memory Caching**: Improve read performance with optional in-memory caching.
- **File Upload**: Built-in support for file uploads, including image compression.
- **Asynchronous Operations**: All database operations are asynchronous for better performance.
- **Error Handling**: Robust error handling for database operations.
- **Flexible Configuration**: Customize database behavior through various options.
## Installation
Install Nixabase using npm:
```bash
npm install nixabase
```
## Usage
### Initializing the Database
```javascript
const Nixabase = require('nixabase');
const db = new Nixabase('path/to/database.json', {
format: 'json', // or 'txt'
performance: {
memory: {
enabled: true,
maxItemCount: 1000
},
imageCompression: {
enabled: true,
level: 6,
quality: 80,
resize: { width: 800, height: 600 }
}
}
});
```
### Basic Operations
```javascript
// Save data
await db.save('user1', { name: 'John Doe', age: 30 });
// Retrieve data
const user = await db.get('user1');
console.log(user); // { name: 'John Doe', age: 30 }
// Update data
await db.update('user1', { name: 'John Doe', age: 31 });
// Delete data
await db.delete('user1');
```
### File Operations
```javascript
// Upload a file
await db.uploadFile('path/to/image.jpg', 'profile_pic');
// Retrieve a file
const fileBuffer = await db.getFile('profile_pic');
```
## API Reference
### `constructor(filePath, options)`
Creates a new Nixabase instance.
- `filePath`: Path to the database file.
- `options`: Configuration options (optional).
- `format`: 'json' or 'txt' (default: 'json').
- `performance`: Performance-related options.
### `async save(key, value)`
Saves a key-value pair to the database.
### `async get(key)`
Retrieves a value from the database by its key.
### `async update(key, value)`
Updates an existing key-value pair in the database.
### `async delete(key)`
Deletes a key-value pair from the database.
### `async uploadFile(sourcePath, destinationKey)`
Uploads a file to the database with optional image compression.
### `async getFile(key)`
Retrieves a file from the database.
## Performance Optimization
Nixabase offers performance optimization through memory caching and image compression. These features can be enabled and configured in the constructor options.
## Error Handling
Nixabase uses async/await and throws errors when operations fail. It's recommended to use try-catch blocks when working with Nixabase methods.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
## Author
Nixabase is created and maintained by Nixaut.