### Install KubitDB Packages Source: https://github.com/developerkubilay/kubitdb/blob/main/README.md Installation commands for the local JSON-based database and the online database variant via npm. ```bash npm i kubitdb npm i kubitdbonline ``` -------------------------------- ### Complete KubitDB Usage Example for Game Application (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt A comprehensive example demonstrating typical KubitDB usage patterns for a game application, including setting player data, managing resources, and performing calculations. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("./data/gamedata"); // Initialize player data db.set('player', { name: 'Hero', class: 'Warrior', created: Date.now() }); // Set initial stats db.set('gold', 100); db.set('experience', 0); db.set('level', 1); // Player earns gold and experience db.add('gold', 50); db.add('experience', 100); // Player buys an item if (db.get('gold') >= 30) { db.subtract('gold', 30); db.push('inventory', { item: 'Health Potion', quantity: 5 }); } // Calculate potential earnings without modifying database const bonusGold = db.math('gold', '*', 2); console.log(`Potential bonus: ${bonusGold} gold`); // Check current state console.log('Gold:', db.get('gold')); // Output: 120 console.log('Experience:', db.get('experience')); // Output: 100 console.log('Has inventory:', db.has('inventory')); // Output: true // View all game data console.log('All data:', db.fetchAll()); // Output: { // "player": { "name": "Hero", "class": "Warrior", "created": 1699900000000 }, // "gold": 120, // "experience": 100, // "level": 1, // "inventory": [{ "item": "Health Potion", "quantity": 5 }] // } ``` -------------------------------- ### Initialize and Configure KubitDB Source: https://github.com/developerkubilay/kubitdb/blob/main/README.md Demonstrates how to import the library and initialize a new database instance. Users can specify a custom filename or path for the JSON storage. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); // Or with custom path: // const db = new kubitdb("./kubitdb.json"); ``` -------------------------------- ### Initialize KubitDB Instance Source: https://context7.com/developerkubilay/kubitdb/llms.txt Creates a new database instance linked to a local JSON file. If the specified file path does not exist, the library automatically creates the file and necessary directory structures. ```javascript const kubitdb = require('kubitdb'); // Default initialization (uses kubitdb.json) const db = new kubitdb(); // Custom file name (automatically adds .json extension) const db = new kubitdb("mydata"); // Custom file path with explicit .json extension const db = new kubitdb("./data/storage.json"); ``` -------------------------------- ### Perform CRUD and Mathematical Operations Source: https://github.com/developerkubilay/kubitdb/blob/main/README.md Covers essential database operations including setting values, adding/subtracting numbers, pushing to arrays, checking existence, and clearing data. These methods support both Turkish and English aliases. ```javascript db.set('test', 'true'); db.add('test', 50); db.push('serverSettings', { whitelist: "on", playerCount: "12" }); db.has('prefix'); db.get('para'); db.subtract('para', 400); db.delete('serverStatus'); db.all(); db.clear(); db.math('apple', '+', 10); ``` -------------------------------- ### Store Values in KubitDB Source: https://context7.com/developerkubilay/kubitdb/llms.txt Sets a key-value pair in the database. Supports strings, numbers, and objects, with 'ayarla' provided as a Turkish alias for the 'set' method. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); // Store a string value db.set('username', 'john_doe'); // Store a number value db.set('score', 100); // Store an object value db.set('config', { theme: 'dark', language: 'en' }); // Turkish alias db.ayarla('test', 'evet'); ``` -------------------------------- ### Check Key Existence with has/varmı (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt Checks if a key exists in the database and has a truthy value. Returns a boolean. Supports Turkish alias 'varmı'. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('prefix', '!'); db.set('enabled', true); // Check existing keys console.log(db.has('prefix')); // Output: true console.log(db.has('enabled')); // Output: true // Check non-existent key console.log(db.has('missing')); // Output: false // Turkish alias console.log(db.varmı('prefix')); // Output: true ``` -------------------------------- ### Retrieve Values from KubitDB Source: https://context7.com/developerkubilay/kubitdb/llms.txt Fetches data associated with a specific key. Returns undefined if the key is missing, and provides multiple English and Turkish method aliases for convenience. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('money', 500); db.set('player', { name: 'Alice', level: 25 }); // English methods const money = db.get('money'); // Returns: 500 const player = db.fetch('player'); // Returns: { name: 'Alice', level: 25 } // Turkish aliases const para = db.al('money'); // Returns: 500 const oyuncu = db.bak('player'); // Returns: { name: 'Alice', level: 25 } ``` -------------------------------- ### Retrieve All Data with fetchAll/getAll/all/hepsi/hepsinial (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt Retrieves all data stored in the database as a JavaScript object. Supports multiple aliases in English and Turkish. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('money', 500); db.set('username', 'player1'); db.set('inventory', ['sword', 'shield']); // Get all data const allData = db.fetchAll(); console.log(allData); // Output: { // "money": 500, // "username": "player1", // "inventory": ["sword", "shield"] // } // Using aliases const data1 = db.getAll(); // Same result const data2 = db.all(); // Same result // Turkish aliases const data3 = db.hepsi(); // Same result const data4 = db.hepsinial(); // Same result ``` -------------------------------- ### Clear All Data with clear/clearAll/deleteAll/temizle (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt Removes all data from the database, resetting it to an empty object. Supports multiple aliases in English and Turkish. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('key1', 'value1'); db.set('key2', 'value2'); console.log(db.fetchAll()); // Output: { "key1": "value1", "key2": "value2" } // Clear all data db.clear(); console.log(db.fetchAll()); // Output: {} // Using aliases db.set('test', 'data'); db.clearAll(); // Clears database db.deleteAll(); // Clears database // Turkish alias db.set('test', 'data'); db.temizle(); // Clears database console.log(db.fetchAll()); // Output: {} ``` -------------------------------- ### Perform Numeric Addition Source: https://context7.com/developerkubilay/kubitdb/llms.txt Increments a numeric value stored at a key. If the key does not exist, it initializes the key with the provided value. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); // Add to existing value db.add('coins', 50); // Turkish alias db.ekle('coins', 100); ``` -------------------------------- ### Push Values to Arrays Source: https://context7.com/developerkubilay/kubitdb/llms.txt Appends a value to an array stored in the database. If the key does not exist, it creates a new array containing the value. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); // Push to non-existent key (creates array) db.push('items', 'sword'); // Push objects to array db.push('serverSettings', { whitelist: 'on', playerCount: '12' }); // Turkish alias db.it('logs', { timestamp: Date.now(), action: 'login' }); ``` -------------------------------- ### Perform Math Operations with math/hesapla (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt Performs mathematical calculations on a stored numeric value without modifying the database. Supports addition (+), subtraction (-), multiplication (*), and division (/). Supports Turkish alias 'hesapla'. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('apple', 50); // Addition (does not modify stored value) const added = db.math('apple', '+', 10); console.log(added); // Output: 60 console.log(db.get('apple')); // Output: 50 (unchanged) // Subtraction const subtracted = db.math('apple', '-', 20); console.log(subtracted); // Output: 30 // Multiplication const multiplied = db.math('apple', '*', 2); console.log(multiplied); // Output: 100 // Division const divided = db.math('apple', '/', 5); console.log(divided); // Output: 10 // Turkish alias const result = db.hesapla('apple', '+', 25); console.log(result); // Output: 75 ``` -------------------------------- ### Delete Key or Subtract Value with delete/del/sil (JavaScript) Source: https://context7.com/developerkubilay/kubitdb/llms.txt Deletes a key from the database when called with one argument. When called with two arguments, it subtracts the second value from the stored number. Supports aliases 'del' and 'sil' (Turkish). ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); db.set('serverStatus', 'online'); db.set('health', 100); // Delete a key entirely db.delete('serverStatus'); console.log(db.has('serverStatus')); // Output: false // Subtract value using delete with index db.set('points', 500); db.delete('points', 100); console.log(db.get('points')); // Output: 400 // Using aliases db.del('points', 50); console.log(db.get('points')); // Output: 350 // Turkish alias db.sil('points', 25); console.log(db.get('points')); // Output: 325 ``` -------------------------------- ### Perform Numeric Subtraction Source: https://context7.com/developerkubilay/kubitdb/llms.txt Decrements a numeric value stored at a key. Supports multiple aliases including the Turkish 'cıkar' method. ```javascript const kubitdb = require('kubitdb'); const db = new kubitdb("kubitdb"); // Subtract from existing value db.subtract('balance', 250); // Using aliases db.substr('balance', 100); // Turkish alias db.cıkar('balance', 50); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.