World's fastest TKV (Table-Key-Value) database with KV support for Node.js. Written in TypeScript with both CommonJS and ESM support.
- π Ultra-fast in-memory database with file persistence
- π¦ Supports both KV (Key-Value) and TKV (Table-Key-Value) modes
- πΎ Automatic data persistence
- π Automatic file descriptor management
- π Safe process termination handling
- π JSON storage with compression option
- π¦ Both ESM and CommonJS support
npm install dynabaseconst db = require('dynabase');
async function main() {
// Initialize in KV mode
await db.init({
path: "./data", // Storage directory
type: "kv", // Database type
compress: true // Enable compression
});
// Set values
db.set('user1', { name: 'John', age: 30 });
// Get values
const user = db.get('user1');
// Delete values
db.delete('user1');
}const db = require('dynabase');
async function main() {
// Initialize in TKV mode
await db.init({
path: "./data", // Storage directory
type: "tkv", // Database type
compress: true // Enable compression
});
// Set values
db.set('users', 'user1', { name: 'John', age: 30 });
// Get values
const user = db.get('users', 'user1');
// Delete values
db.delete('users', 'user1');
}interface DatabaseConfig {
path: string; // Storage directory path
type: 'tkv' | 'kv'; // Database type
compress?: boolean; // Enable JSON compression
}
await db.init(config: DatabaseConfig): Promise<boolean>set(key: string, value: any): booleanget(key: string): anydelete(key: string): boolean
set(table: string, key: string, value: any): booleanget(table: string, key: string): anydelete(table: string, key: string): boolean
// In KV mode: resets entire database
await db.reset('default');
// In TKV mode: resets specific table
await db.reset('tableName');// Force write to disk
await db.flush();const info = db.info();
/*
{
version: string;
author: string;
async: boolean;
initStatus: boolean;
type: 'tkv' | 'kv';
compression: boolean;
storagePath: string;
functions: string[];
}
*/- Data is stored in JSON files in the specified directory
- KV mode uses a single
default.jsonfile - TKV mode creates separate JSON files for each table
- Automatic persistence every 5 seconds
- Safe process termination handling
-
Initialization
- Always await
db.init()before using other functions - Choose appropriate mode (KV/TKV) based on your data structure
- Always await
-
Data Types
- Values can be any JSON-serializable data
- Keys must be strings
- Table names must be strings
-
Performance
- Use compression for large datasets
- Group related data in tables (TKV mode)
- Use KV mode for simple key-value storage
-
Error Handling
- All async operations return Promises
- Check return values for operation success
- Handle potential errors in async operations
GNU General Public License v3.0