CroxyDB

0.0.26 · active · verified Wed Apr 22

CroxyDB is a versatile JavaScript database module designed for Node.js environments, currently at version 0.0.26. It provides a straightforward API for managing data with support for various storage backends including JSON files (default), YAML files, and external MongoDB instances. The library offers a familiar key-value store interface with advanced features like dot notation for nested object access (e.g., `db.set("x.y.z", "value")`), array manipulation (`push`, `unpush`, `delByPriority`, `setByPriority`), and robust configuration options for file-based adapters. While in an early pre-1.0 development stage, CroxyDB aims for ease of use and flexibility, allowing developers to switch between local file storage and a remote NoSQL database like MongoDB using a simple adapter system. Its current release cadence appears to be driven by feature additions and bug fixes rather than a strict schedule, as indicated by recent updates like the enhanced `db.subtract` function.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting various global configuration options for the database, performing core data operations like setting and retrieving values (including nested paths), manipulating arrays, checking for key existence, and deleting data. The example highlights asynchronous operations common with database interactions.

import db from 'croxydb';

// Configure database options before first operation
db.setReadable(true); // Makes the JSON DB file human-readable for easier inspection
db.noBlankData(true); // Automatically removes parent objects if child properties are deleted and it becomes empty
db.setAdapter("jsondb"); // Explicitly set default JSON adapter (optional, as it's default)
db.setFolder("my_app_data"); // Set custom folder name for database files
db.setFile("my_db"); // Set custom database file name (e.g., my_db.json)
db.setCheckUpdates(true); // Enable warnings for new package updates

async function runExample() {
  console.log('--- Initializing CroxyDB Example ---');
  // Basic key-value operations with dot notation
  await db.set("user.profile.name", "Alice");
  console.log('Set user name to Alice.');
  console.log('Retrieved user name:', await db.get("user.profile.name")); // Output: Alice

  // Array manipulation
  await db.push("shoppingCart", "Milk");
  await db.push("shoppingCart", "Bread");
  console.log('Shopping cart:', await db.get("shoppingCart")); // Output: [ 'Milk', 'Bread' ]
  await db.unpush("shoppingCart", "Milk");
  console.log('Shopping cart after removing Milk:', await db.get("shoppingCart")); // Output: [ 'Bread' ]

  // Check existence and delete operations
  console.log('Does user profile exist?', await db.has("user.profile")); // Output: true
  await db.delete("user.profile");
  console.log('Does user profile exist after delete?', await db.has("user.profile")); // Output: false

  // View all data
  console.log('All data currently in DB:', await db.all()); // Output: { shoppingCart: [ 'Bread' ] } (if noBlankData is true)

  // Clean up all data
  await db.deleteAll();
  console.log('All data after deleteAll:', await db.all()); // Output: {}
  console.log('--- CroxyDB Example Finished ---');
}

runExample().catch(console.error);

view raw JSON →