ForerunnerDB

2.0.24 · active · verified Wed Apr 22

ForerunnerDB is a NoSQL JSON document database designed for both browser-based and Node.js applications, offering a MongoDB-like query language. The current stable version is 2.0.24, with a significant rewrite for version 3.0 actively under development in a separate repository (forerunnerdb-core). Key differentiators include its dual-environment support, advanced features like data views, joins, sub-queries, and collection groups, along with optional modules for AngularJS/Ionic integration, real-time data binding to the DOM (browser-only), persistent storage, data compression and encryption, and a built-in REST API server for Node.js. It is production-ready, battle-tested in applications serving millions of users daily, and maintained by Irrelon Software Limited. While no explicit release cadence is published, development is ongoing for the next major version.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the initialization of ForerunnerDB, creating a collection, inserting, querying (including comparisons), updating documents, and saving/loading the database state with basic persistence. It also shows a simple View creation.

import ForerunnerDB from 'forerunnerdb';

interface User { 
  _id?: string; 
  name: string; 
  age: number; 
  city: string; 
}

// Initialize ForerunnerDB and get a database instance
const fdb = new ForerunnerDB();
const db = fdb.db('myApplicationDB');

// To enable persistence in Node.js, specify a path
// ForerunnerDB also supports localStorage in browsers automatically
if (typeof window === 'undefined') { // Node.js environment
  const path = require('path');
  db.persist.dataDir(path.resolve(__dirname, 'data'));
}

async function runDbOperations() {
  // Load existing data if any
  await db.load();
  console.log('Database loaded.');

  // Get or create a collection
  const users = db.collection<User>('users');

  // Clear collection for a clean start (optional)
  users.remove({});

  // Insert some documents
  const insertedUsers = await users.insert([
    { name: 'Alice', age: 30, city: 'New York' },
    { name: 'Bob', age: 24, city: 'London' },
    { name: 'Charlie', age: 30, city: 'Paris' },
    { name: 'David', age: 28, city: 'New York' }
  ]);
  console.log('Inserted users:', insertedUsers.length);

  // Find all users
  const allUsers = users.find();
  console.log('All users:', allUsers);

  // Find users older than 25
  const olderUsers = users.find({ age: { '$gt': 25 } });
  console.log('Users older than 25:', olderUsers);

  // Update a user
  await users.update({ name: 'Bob' }, { $set: { age: 25, city: 'Berlin' } });
  const updatedBob = users.find({ name: 'Bob' });
  console.log('Updated Bob:', updatedBob);

  // Save the database state
  await db.save();
  console.log('Database saved.');

  // Demonstrate a View (virtual collection)
  const nyUsersView = db.view('nyUsersView')
    .from('users')
    .query({ city: 'New York' });

  console.log('Users in New York (via View):', nyUsersView.find());
}

runDbOperations().catch(console.error);

view raw JSON →