kive.db
v1.0.0
Published
Modern key-value database for Node.js with MongoDB-like interface
Maintainers
Readme
kive.db ✨
A modern, fast, and efficient key-value database for Node.js
Features
- 🚀 Blazing fast performance with memory caching
- 📝 Schema validation with custom rules
- 🔍 Powerful query builder
- 💾 Persistent storage with atomic writes
- 🧵 Concurrent access support
- 📦 Zero-dependency (optional dependencies for advanced features)
Installation
npm install kive.db@latestQuick Start (ES Modules)
import { KiveDB, Schema } from 'kive.db';
// Initialize with custom options
const db = new KiveDB({
storagePath: './mydata', // Custom storage location
cacheSize: 2000, // Increase cache size
});
// Define a schema
const blogSchema = new Schema({
title: { type: String, required: true },
content: String,
tags: [String],
views: { type: Number, default: 0 },
publishedAt: { type: Date, default: Date.now }
});
// Create a model
const Blog = db.model('Blog', blogSchema);
// Add middleware
blogSchema.pre('save', async (data) => {
console.log(`Saving blog: ${data.title}`);
});
// Usage example
async function main() {
const article = await Blog.create({
title: 'Getting Started with kive.db',
content: '...',
tags: ['database', 'nodejs']
});
console.log('Created article:', article);
// Find articles with more than 100 views
const popular = await Blog.find()
.where('views').gt(100)
.limit(5)
.exec();
console.log('Popular articles:', popular);
}
main().catch(console.error);CommonJS Usage
const { KiveDB, Schema } = require('kive.db');
// ... same API as ESM versionAPI Reference
new KiveDB(options)
Create a new database instance.
Options:
storagePath: Path to store data files (default: './data')cacheSize: Maximum items in cache (default: 1000)writeBufferSize: Bytes to buffer before writing (default: 16384)
Schema(definition)
Define a schema for your data.
Definition properties:
type: Data type (String, Number, Date, etc.)required: Mark field as requireddefault: Default valuevalidate: Custom validation function/regex
Model API
create(data): Create new documentfindById(id): Find by primary keyfind([query]): Create query builderupdateOne(query, update): Update first matching documentdeleteOne(query): Delete first matching documentcompact(): Optimize storage
Query Builder
Chainable methods:
where(field): Field to queryequals(value): Exact matchgt(value): Greater thanlt(value): Less thanin(array): Match any value in arraylimit(n): Maximum resultsskip(n): Skip first n resultsexec(): Execute queryfindOne(): Get first result
Performance Tips
Increase cache size for read-heavy applications:
const db = new KiveDB({ cacheSize: 5000 });Batch writes by default - no need to manually batch operations.
Run compaction periodically for large datasets:
await Blog.compact();Use indexes for frequently queried fields (automatic for
_id).
License
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.
Contact
If you have any questions, feel free to reach out to the author:
- Name: Iscordian
- Email: [email protected]
- Discord: iscordian.dev
- Discord Server: https://discord.gg/GQBWcyR9Cp
