TaffyDB In-Memory JavaScript Database

2.7.3 · maintenance · verified Wed Apr 22

TaffyDB is an open-source JavaScript library that provides an in-memory database solution for both browser and Node.js environments. It allows developers to store and manipulate JSON data as 'tables' using a uniform, SQL-like interface. Currently at version 2.7.3, the library emphasizes stability and reliability, having been used in production for many years. It differentiates itself by offering a JavaScript-centric data selection engine with features like insert, update, unique, and count, all while being compatible with various DOM libraries and modern browsers (IE9+, FF3+, Safari 5+, Chrome 1.0+) and Node.js 0.10+. While stable, the project's focus appears to be on expanding regression test coverage rather than rapid feature development, suggesting a maintenance-oriented release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a TaffyDB instance with JSON data, perform basic queries using SQL-like syntax (e.g., less than), update records, and select specific fields.

const TAFFY = require('taffy').taffy;

const product_db = TAFFY([
  {
    "item": 1,
    "name": "Blue Ray Player",
    "price": 99.99
  },
  {
    "item": 2,
    "name": "3D TV",
    "price": 1799.99
  },
  {
    "item": 3,
    "name": "Soundbar",
    "price": 149.99
  }
]);

console.log('All products:', product_db().get());

// Query for items with price less than 150
const lowPricedItems = product_db({price: {lt: 150}}).get();
console.log('Low priced items (price < 150):', lowPricedItems);

// Update the price of an item
product_db({item: 1}).update({price: 89.99});
console.log('Updated Blue Ray Player:', product_db({item: 1}).first());

// Select only names
const productNames = product_db().select("name");
console.log('Product names:', productNames);

view raw JSON →