Registry / database / wio.db

wio.db

JSON →
library4.0.22jsnpmunverified

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.

npm install wio.db
INSTALL
IMPORT
SIG · WIO.DB
W
wio.db
databasejavascriptv4.0.22
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JsonDatabase
✓ import { JsonDatabase } from 'wio.db';
✗ import wiodb from 'wio.db'; // No default export
For ESM environments and TypeScript. Wio.db primarily exports named classes.
YamlDatabase
✓ const { YamlDatabase } = require('wio.db');
✗ const YamlDatabase = require('wio.db').YamlDatabase; // Direct access is less idiomatic for multiple exports
For CommonJS environments. Destructuring is the standard approach.
All exports
✓ import { JsonDatabase, YamlDatabase } from 'wio.db';
✗ import { Database } from 'wio.db'; // 'Database' is not an exported symbol
Ensure you are importing the specific named classes provided by the library.

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();
Debug
Known issues
gotchaWio.db requires Node.js version 12 or greater to function correctly. Running on older Node.js versions may lead to unexpected errors or stability issues.
fix
Upgrade your Node.js installation to version 12 or higher. For example, using nvm: `nvm install 16 && nvm use 16`.
affects: <12.0.0
breakingThe `<db>.arrayHasValue` method has been removed in Wio.db v4. This functionality is no longer available.
fix
Migrate your code to use alternative array manipulation methods or implement custom logic to check for array values. Consider using `<db>.pull` with a custom filter function or `<db>.get` and manual array iteration.
affects: >=4.0.0
breakingThe static property `JsonDatabase.DBCollection` has been removed in Wio.db v4. This property is no longer accessible.
fix
Review your code for any reliance on `JsonDatabase.DBCollection`. This property was internal and its removal indicates a refactoring of how database collections are managed. You may need to adapt your application logic if you were directly accessing it.
affects: >=4.0.0
breakingThe `<db>.totalDBSize` property has been removed in Wio.db v4. You can no longer directly access the total database size via this property.
fix
Utilize the new `<db>.info` property to get database statistics, which may include size-related information. If specific size metrics are required, you might need to calculate them manually based on the database file's size or content.
affects: >=4.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ECMAScript Module (ESM) file (e.g., a `.mjs` file or a project with `"type": "module"` in `package.json`).
fix
Change your import statement to use ESM syntax: `import { JsonDatabase, YamlDatabase } from 'wio.db';`
TypeError: JsonDatabase is not a constructor
You are calling `JsonDatabase()` or `YamlDatabase()` without the `new` keyword.
fix
Always instantiate database classes with `new`: `const db = new JsonDatabase({ databasePath: './data.json' });`
Error: Database path is required
The `databasePath` option was omitted or left undefined when initializing `JsonDatabase` or `YamlDatabase`.
fix
Provide a valid string path for your database file: `const db = new JsonDatabase({ databasePath: './my-database.json' });`
Upgrade
Version history
4.0.22latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
2
Resources
wio.db — npm install wio.db · libregistry