Wio.db

4.0.22 · active · verified Wed Apr 22

wio.db is a Turkish-origin, human-readable database module for Node.js, currently in version 4.0.22. It serves as a lightweight, file-based key-value store, offering an alternative to packages like quick.db, and is frequently used in discord.js bot development. The library provides distinct implementations for JSON and YAML file formats, allowing developers to choose based on their data persistence preferences. While a specific release cadence is not explicitly stated, the project appears actively maintained with recent updates and bug fixes, indicated by its 4.x versioning. Key features include intuitive data manipulation methods for setting, getting, deleting, and querying data, alongside array and mathematical operations directly on stored values. It differentiates itself by emphasizing a human-readable storage format and offering both JSON and YAML options, rather than relying solely on a single serialization method.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize JSON and YAML database instances, perform common data operations like setting, getting, checking existence, pushing to arrays, performing math operations, retrieving all data, and deleting entries, using both JSON and YAML databases.

import { JsonDatabase, YamlDatabase } from 'wio.db';

// Initialize a JSON database instance
const db = new JsonDatabase({
  databasePath: './databases/myJsonDatabase.json'
});

// Initialize a YAML database instance
const yamldb = new YamlDatabase({
  databasePath: './databases/myYamlDatabase.yml'
});

// --- JSON Database Operations ---

// Set a value
db.set('user_settings.theme', 'dark');
console.log("Set 'user_settings.theme' to 'dark'");

// Get a value
const theme = db.get('user_settings.theme');
console.log(`Retrieved theme: ${theme}`); // Expected: dark

// Check if a key exists
const hasSetting = db.has('user_settings.theme');
console.log(`Does 'user_settings.theme' exist? ${hasSetting}`); // Expected: true

// Push to an array
db.push('recent_logins', 'user123');
db.push('recent_logins', 'admin456');
console.log(`Recent logins: ${db.get('recent_logins')}`); // Expected: [ 'user123', 'admin456' ]

// Add a number
db.add('user_points', 100);
db.add('user_points', 50);
console.log(`User points: ${db.get('user_points')}`); // Expected: 150

// Get all data (top 5 entries)
const allData = db.all(5);
console.log('All JSON DB data (top 5):', allData);

// Delete a key
db.delete('user_settings.theme');
console.log("Deleted 'user_settings.theme'");
console.log(`Does 'user_settings.theme' exist after delete? ${db.has('user_settings.theme')}`); // Expected: false

// Get DB info
console.log('JSON DB Info:', db.info);

// --- YAML Database Operations (similar) ---
yamldb.set('config.port', 3000);
console.log(`YAML config port: ${yamldb.get('config.port')}`);

// To destroy databases and clean up files (uncomment to run)
// db.destroy();
// yamldb.destroy();

view raw JSON →