NDDB Object Database

3.0.2 · maintenance · verified Wed Apr 22

NDDB (N-Dimensional DataBase) is a 100% JavaScript object database designed for both Node.js and browser environments. It offers a comprehensive set of features including indexing, views, hashes, joins, group-by operations, and various statistical functions (count, max, min, mean, stddev). The library supports saving and loading data from the file system (Node.js) and browser localStorage. Current stable version is 3.0.2, published approximately four years ago, suggesting a mature codebase in maintenance mode. Its key differentiators include a flexible API for complex data manipulation, support for cyclic objects, and a focus on developer-friendliness, making it suitable for applications requiring in-memory data management with advanced querying capabilities, such as simulations or interactive data visualizations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize NDDB, insert individual and multiple records, query the database using basic and advanced operators, and chain selection methods.

const NDDB = require('NDDB');

// Create a new database instance
let db = NDDB.db();

// Add a single item to the database
db.insert({
    painter: "Picasso",
    title: "Les Demoiselles d'Avignon",
    year: 1907
});

// Import a collection of items
let items = [
    { painter: "Dali", title: "Portrait of Paul Eluard", year: 1929, portrait: true },
    { painter: "Dali", title: "Barcelonese Mannequin", year: 1927 },
    { painter: "Monet", title: "Water Lilies", year: 1906 },
    { painter: "Monet", title: "Wheatstacks (End of Summer)", year: 1891 },
    { painter: "Manet", title: "Olympia", year: 1863 }
];
db.importDB(items);

// Retrieve the database size
console.log('Database size:', db.size()); // Expected: 6

// Select items based on criteria
let daliPaintings = db.select('painter', '=', 'Dali');
console.log('Dali paintings count:', daliPaintings.size()); // Expected: 2
console.log('First Dali painting title:', daliPaintings.first().title);

// Select items using LIKE operator (case sensitive)
let monetPaintings = db.select('painter', 'LIKE', 'M_net');
console.log('Monet-like paintings count:', monetPaintings.size()); // Expected: 3

// You can chain operations
let oldPaintings = db.select('year', '<', 1900).and('painter', 'LIKE', 'M_net');
console.log('Old Monet-like paintings count:', oldPaintings.size()); // Expected: 1 (Manet's Olympia)

view raw JSON →