Implement Database Features to Your Javascript Application Easily

Written by Kevin Liew on 13 Sep 2012
20,734 Views • Javascript

Introduction

If you dealed with JSON object or Javascript object data oftenly, you might have thought how good would it be to manipulate the object data just like how we manipulate database with SQL. Introducing TaffyDB! TaffyDB is a libary to bring powerful database funtionality to that concept and rapidly improve the way you work with data inside of JavaScript. It treats objects as records, and a group of objects as table. It also has built-in method to retrieve,  insert and update data objects. It's a good helper when dealing with large amount of object data.

Features

  • Small file size, extremely fast queries
  • Powerful JavaScript centric data selection engine
  • Database inspired features such as count, update, and insert
  • Robust cross browser support
  • Easily extended with your own functions
  • Compatible with any Javascript libraries and Server side JS

Examples

Create a database

// Create DB and fill it with records
var friends = TAFFY([
	{"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
	{"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},
	{"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},
	{"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}	
]);

Access Data

// Kelly's record
var kelly = friends({id:2}).first();

// Kelly's last name
var kellyslastname = kelly.last;

// Get an array of record ids
var cities = friends().select("id");

// Get an array of distinct cities
var cities = friends().distinct("city");

// Apply a function to all the male friends
friends({gender:"M"}).each(function (r) {
   alert(r.name + "!");
});

SPECIFICATIONS & DOWNLOAD

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.