Posts tagged as:

database

Database in Javascript : Taffy DB

by Roberto on April 17, 2010

in General

If you need to implement a database on client side in Javascript I suggest to consider Taffy DB.
Taffy DB is a small library that can simplify the work a lot when you have to deal with many data structure in Javascript :

Taffy DB is a free and opensource JavaScript library that acts as thin data layer inside Web 2.0 and Ajax applications.

What makes it cool:

  • 10K file size!
  • Simple, JavaScript Centric Syntax
  • Fast
  • Easy to include in any web application
  • Compatible with major Ajax libraries: YUI, JQuery, Dojo, Prototype, EXT, etc
  • CRUD Interface (Create, Read, Update, Delete)
  • Sorting
  • Looping
  • Advanced Queries

Think of it as a SQL database in your web browser.

Example of use :

// Create a table
var friends = new TAFFY([]);
 
//Insert records in the table
friends.insert(
	{name:"Brian",
	gender:"M",
	married:"No",
	age:52,
	state:"FL",
	favorite_foods:["fruit","steak"]
	});
 
//Update records matching a condition
friends.update(
	{
	state:"CA",
	married:"Yes"
	},
	friends.find(
		{name:"Joyce"}
		)
	);
 
//Remove 
friends.remove({name:"Brian"});
 
//Order the records
friends.orderBy(["age",{"name":"desc"}]);

See the getting started guide for documentation and more examples.
I’m using this library in a new Google Gadget I’m writing.
This gadget uses the user’s contacts and I needed an easy way to manage the contacts list on client side using Javascript. Taffy DB is very useful for me in this scenario.

{ 1 comment }