{"id":17406,"library":"wio.db","title":"Wio.db","description":"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.","status":"active","version":"4.0.22","language":"javascript","source_language":"en","source_url":"https://github.com/wioenena-q/JS-WioDB","tags":["javascript","quick.db","database","discord.js","wio.db","turkish","json","yaml","typescript"],"install":[{"cmd":"npm install wio.db","lang":"bash","label":"npm"},{"cmd":"yarn add wio.db","lang":"bash","label":"yarn"},{"cmd":"pnpm add wio.db","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM environments and TypeScript. Wio.db primarily exports named classes.","wrong":"import wiodb from 'wio.db'; // No default export","symbol":"JsonDatabase","correct":"import { JsonDatabase } from 'wio.db';"},{"note":"For CommonJS environments. Destructuring is the standard approach.","wrong":"const YamlDatabase = require('wio.db').YamlDatabase; // Direct access is less idiomatic for multiple exports","symbol":"YamlDatabase","correct":"const { YamlDatabase } = require('wio.db');"},{"note":"Ensure you are importing the specific named classes provided by the library.","wrong":"import { Database } from 'wio.db'; // 'Database' is not an exported symbol","symbol":"All exports","correct":"import { JsonDatabase, YamlDatabase } from 'wio.db';"}],"quickstart":{"code":"import { JsonDatabase, YamlDatabase } from 'wio.db';\n\n// Initialize a JSON database instance\nconst db = new JsonDatabase({\n  databasePath: './databases/myJsonDatabase.json'\n});\n\n// Initialize a YAML database instance\nconst yamldb = new YamlDatabase({\n  databasePath: './databases/myYamlDatabase.yml'\n});\n\n// --- JSON Database Operations ---\n\n// Set a value\ndb.set('user_settings.theme', 'dark');\nconsole.log(\"Set 'user_settings.theme' to 'dark'\");\n\n// Get a value\nconst theme = db.get('user_settings.theme');\nconsole.log(`Retrieved theme: ${theme}`); // Expected: dark\n\n// Check if a key exists\nconst hasSetting = db.has('user_settings.theme');\nconsole.log(`Does 'user_settings.theme' exist? ${hasSetting}`); // Expected: true\n\n// Push to an array\ndb.push('recent_logins', 'user123');\ndb.push('recent_logins', 'admin456');\nconsole.log(`Recent logins: ${db.get('recent_logins')}`); // Expected: [ 'user123', 'admin456' ]\n\n// Add a number\ndb.add('user_points', 100);\ndb.add('user_points', 50);\nconsole.log(`User points: ${db.get('user_points')}`); // Expected: 150\n\n// Get all data (top 5 entries)\nconst allData = db.all(5);\nconsole.log('All JSON DB data (top 5):', allData);\n\n// Delete a key\ndb.delete('user_settings.theme');\nconsole.log(\"Deleted 'user_settings.theme'\");\nconsole.log(`Does 'user_settings.theme' exist after delete? ${db.has('user_settings.theme')}`); // Expected: false\n\n// Get DB info\nconsole.log('JSON DB Info:', db.info);\n\n// --- YAML Database Operations (similar) ---\nyamldb.set('config.port', 3000);\nconsole.log(`YAML config port: ${yamldb.get('config.port')}`);\n\n// To destroy databases and clean up files (uncomment to run)\n// db.destroy();\n// yamldb.destroy();\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js installation to version 12 or higher. For example, using nvm: `nvm install 16 && nvm use 16`.","message":"Wio.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.","severity":"gotcha","affected_versions":"<12.0.0"},{"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.","message":"The `<db>.arrayHasValue` method has been removed in Wio.db v4. This functionality is no longer available.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"The static property `JsonDatabase.DBCollection` has been removed in Wio.db v4. This property is no longer accessible.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"The `<db>.totalDBSize` property has been removed in Wio.db v4. You can no longer directly access the total database size via this property.","severity":"breaking","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your import statement to use ESM syntax: `import { JsonDatabase, YamlDatabase } from 'wio.db';`","cause":"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`).","error":"ReferenceError: require is not defined"},{"fix":"Always instantiate database classes with `new`: `const db = new JsonDatabase({ databasePath: './data.json' });`","cause":"You are calling `JsonDatabase()` or `YamlDatabase()` without the `new` keyword.","error":"TypeError: JsonDatabase is not a constructor"},{"fix":"Provide a valid string path for your database file: `const db = new JsonDatabase({ databasePath: './my-database.json' });`","cause":"The `databasePath` option was omitted or left undefined when initializing `JsonDatabase` or `YamlDatabase`.","error":"Error: Database path is required"}],"ecosystem":"npm","meta_description":null}