https://github.com/recabasic/dynabase
World's fastest TKV (Table-Key-Value) database with KV support for Node.js. Written in TypeScript with both CommonJS and ESM support.
https://github.com/recabasic/dynabase
database in-memory-database in-memory-storage key-value kv nosql table-key-value tkv
Last synced: 3 months ago
JSON representation
World's fastest TKV (Table-Key-Value) database with KV support for Node.js. Written in TypeScript with both CommonJS and ESM support.
- Host: GitHub
- URL: https://github.com/recabasic/dynabase
- Owner: recabasic
- License: gpl-3.0
- Created: 2025-02-18T13:28:43.000Z (8 months ago)
- Default Branch: develop
- Last Pushed: 2025-02-19T09:22:58.000Z (8 months ago)
- Last Synced: 2025-06-28T18:05:56.634Z (4 months ago)
- Topics: database, in-memory-database, in-memory-storage, key-value, kv, nosql, table-key-value, tkv
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/dynabase
- Size: 56.6 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dynabase
World's fastest TKV (Table-Key-Value) database with KV support for Node.js. Written in TypeScript with both CommonJS and ESM support.
[](https://www.npmjs.com/package/dynabase)
[](https://github.com/HolaClient/dynabase/blob/main/LICENSE)
[](https://nodejs.org)## Features
- 🚀 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## Installation
```bash
npm install dynabase
```## Quick Start
### Key-Value Mode (KV)
```javascript
const 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');
}
```### Table-Key-Value Mode (TKV)
```javascript
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');
}
```## API Reference
### Initialization
```typescript
interface DatabaseConfig {
path: string; // Storage directory path
type: 'tkv' | 'kv'; // Database type
compress?: boolean; // Enable JSON compression
}await db.init(config: DatabaseConfig): Promise
```### Core Operations
#### KV Mode
- `set(key: string, value: any): boolean`
- `get(key: string): any`
- `delete(key: string): boolean`#### TKV Mode
- `set(table: string, key: string, value: any): boolean`
- `get(table: string, key: string): any`
- `delete(table: string, key: string): boolean`### Additional Functions
#### Reset Table/Database
```javascript
// In KV mode: resets entire database
await db.reset('default');// In TKV mode: resets specific table
await db.reset('tableName');
```#### Manual Flush
```javascript
// Force write to disk
await db.flush();
```#### Database Info
```javascript
const info = db.info();
/*
{
version: string;
author: string;
async: boolean;
initStatus: boolean;
type: 'tkv' | 'kv';
compression: boolean;
storagePath: string;
functions: string[];
}
*/
```## Storage
- Data is stored in JSON files in the specified directory
- KV mode uses a single `default.json` file
- TKV mode creates separate JSON files for each table
- Automatic persistence every 5 seconds
- Safe process termination handling## Best Practices
1. **Initialization**
- Always await `db.init()` before using other functions
- Choose appropriate mode (KV/TKV) based on your data structure2. **Data Types**
- Values can be any JSON-serializable data
- Keys must be strings
- Table names must be strings3. **Performance**
- Use compression for large datasets
- Group related data in tables (TKV mode)
- Use KV mode for simple key-value storage4. **Error Handling**
- All async operations return Promises
- Check return values for operation success
- Handle potential errors in async operations## License
GNU General Public License v3.0
## Authors
[CR072](https://github.com/CR072),
[HolaClient](https://github.com/HolaClient)