
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
A lightweight, feature-rich persistent key-value store with TTL, compression, encryption, and event support
A lightweight, feature-rich persistent key-value store with TTL, compression, encryption, and event support.
npm install breezedb
import BreezeDB from 'breezedb';
// Create a new database
const db = new BreezeDB('./mydata.json');
// Set values
db.set('user:1', { name: 'Alice', age: 30 });
db.set('config', { theme: 'dark', lang: 'en' });
// Get values
const user = db.get('user:1');
console.log(user); // { name: 'Alice', age: 30 }
// Set with expiration (TTL)
db.set('session:abc', { token: 'xyz' }, 3600); // expires in 1 hour
// Delete keys
db.delete('user:1');
// Check existence
if (db.has('config')) {
console.log('Config exists!');
}
// Get all keys
console.log(db.keys()); // ['config', 'session:abc']
// Database info
console.log('Size:', db.size());
console.log('Empty:', db.isEmpty());
import BreezeDB from 'breezedb';
import type { BreezeDBOptions } from 'breezedb';
interface User {
name: string;
age: number;
email?: string;
}
// Type-safe database operations
const db = new BreezeDB('./users.json');
// Set with type inference
db.set<User>('user:1', { name: 'Alice', age: 30 });
// Get with type assertion
const user = db.get<User>('user:1');
if (user) {
console.log(user.name); // TypeScript knows this is a string
}
// Configuration with types
const options: BreezeDBOptions = {
compression: true,
encryption: true,
encryptionKey: process.env.DB_KEY,
autoSave: true,
};
const secureDb = new BreezeDB('./secure.json', options);
// Set with TTL (in seconds)
db.set('cache:data', { result: [1, 2, 3] }, 300); // expires in 5 minutes
// Update TTL for existing key
db.setTTL('cache:data', 600); // extend to 10 minutes
// Get remaining TTL
const remaining = db.getTTL('cache:data'); // seconds remaining
// Clear TTL (make permanent)
db.clearTTL('cache:data');
const db = new BreezeDB('./data.json', {
compression: true, // Enable gzip compression
});
// Automatically compresses large datasets
db.set('big-data', hugeArray);
const db = new BreezeDB('./secure.json', {
encryption: true,
encryptionKey: 'your-secret-key-here',
});
// Data is encrypted at rest
db.set('secret', 'confidential-data');
const operations = [
{ type: 'set', key: 'key1', value: 'value1' },
{ type: 'set', key: 'key2', value: 'value2', ttl: 60 },
{ type: 'delete', key: 'old-key' },
];
const results = db.batch(operations);
console.log(results); // Array of operation results
// Listen to database events
db.on('set', ({ key, value, oldValue, ttl }) => {
console.log(`Set ${key} = ${value}`);
});
db.on('get', ({ key, value }) => {
console.log(`Got ${key} = ${value}`);
});
db.on('delete', ({ key, oldValue }) => {
console.log(`Deleted ${key}`);
});
db.on('expired', ({ keys }) => {
console.log(`Expired keys: ${keys.join(', ')}`);
});
db.on('save', ({ filePath }) => {
console.log(`Saved to ${filePath}`);
});
db.on('error', error => {
console.error('Database error:', error);
});
// Auto-save is enabled by default
const db = new BreezeDB('./data.json', {
autoSave: false, // Disable auto-save
});
// Save manually (async)
await db.save();
// Save manually (sync)
db.saveSync();
// Load from disk
await db.load();
const db = new BreezeDB('./data.json', {
// Auto-save settings
autoSave: true, // Enable auto-save (default: true)
autoSaveInterval: 5000, // Auto-save interval in ms (default: 5000)
// TTL settings
ttlCleanupInterval: 60000, // TTL cleanup interval in ms (default: 60000)
// Compression
compression: false, // Enable compression (default: false)
// Encryption
encryption: false, // Enable encryption (default: false)
encryptionKey: null, // Encryption key (required if encryption enabled)
// Formatting
pretty: false, // Pretty-print JSON (default: false)
});
new BreezeDB(filePath, options)
filePath
(string): Path to the database fileoptions
(object): Configuration optionsset(key, value, ttl?)
Set a key-value pair with optional TTL in seconds.
get(key)
Get a value by key. Returns undefined
if not found or expired.
has(key)
Check if a key exists and is not expired.
delete(key)
Delete a key. Returns true
if the key existed.
clear()
Remove all keys from the database.
setTTL(key, ttl)
Set TTL for an existing key. Returns true
if successful.
getTTL(key)
Get remaining TTL in seconds. Returns null
if no TTL set.
clearTTL(key)
Remove TTL from a key. Returns true
if TTL was cleared.
batch(operations)
Execute multiple operations atomically.
keys()
Get array of all non-expired keys.
values()
Get array of all non-expired values.
entries()
Get array of all non-expired [key, value] pairs.
size()
Get number of non-expired keys.
isEmpty()
Check if database is empty.
save()
Save database to disk (async).
saveSync()
Save database to disk (sync).
load()
Load database from disk (async).
close()
Close database and clean up resources.
BreezeDB is designed for applications that need:
For larger datasets or high-concurrency scenarios, consider using a dedicated database server.
// Handle errors with events
db.on('error', error => {
console.error('Database error:', error);
});
// Or with try-catch for specific operations
try {
await db.save();
} catch (error) {
console.error('Save failed:', error);
}
BreezeDB automatically creates backup files:
database.json
- Main database filedatabase.json.backup
- Previous version backupdatabase.json.tmp
- Temporary file during writesIf the main file becomes corrupted, BreezeDB will attempt to restore from the backup automatically.
See the examples directory for more usage examples:
MIT © Jesse Palmer
Pull requests are welcome! Please feel free to submit issues and enhancement requests.
[1.0.0] - 2024-06-15
Core Features
TypeScript Support
Developer Experience
API Methods
set(key, value, ttl?)
- Set key-value pairs with optional TTLget(key)
- Retrieve values by keyhas(key)
- Check key existencedelete(key)
- Remove keysclear()
- Clear all datakeys()
, values()
, entries()
- Iteration methodssize()
, isEmpty()
- Utility methodssetTTL()
, getTTL()
, clearTTL()
- TTL managementbatch()
- Batch operationssave()
, saveSync()
, load()
- Persistence controlclose()
- Resource cleanupConfiguration Options
autoSave
- Automatic saving to diskautoSaveInterval
- Save frequency controlcompression
- Enable gzip compressionencryption
- Enable AES encryptionencryptionKey
- Encryption key specificationpretty
- Pretty-print JSON outputEvent System
set
, get
, delete
events for data operationsexpired
event for TTL expiration notificationsbatch
event for bulk operation completionclear
event for database clearingsave
, load
events for persistence operationsttl-set
, ttl-cleared
events for TTL managementerror
event for error handling/examples/basic.js
/examples/advanced.js
FAQs
A lightweight, feature-rich persistent key-value store with TTL, compression, encryption, and event support
The npm package breezedb receives a total of 0 weekly downloads. As such, breezedb popularity was classified as not popular.
We found that breezedb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.