Tuesday, March 11th, 2008
Taffy DB Javascript Database
Working client-side with data can be challenging and projects have tried to address this in different fashions. Ian Smith, creator of Joe's Goals, has his own approach. He's created Taffy DB, a lightweight Javascript database
that allows you to insert, update, delete, order, loop, and query against a client-side collection of data. The great thing about it is that it's library agnostic and can work with all of the popular frameworks.
The idea came to me as I was working on Joe’s Goals 2.0 and I realized that one of the hardest parts about building any Web 2.0 application is working with data. There is no good way to use JavaScript by itself to gather, search, and maintain a collection of data. There are lots of great ways to great interfaces now days, but what about the data behind them? Taffy DB is the result of the research and testing I did for Joe’s Goals and is now avaliable for everyone to use.
Some of the key features include:
- Under 10K!
- 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
The syntax to use the libary is very straightforward:
Updating:
-
-
friends.update(
-
{
-
state:"CA",
-
married:"Yes"
-
},
-
{
-
name:"Joyce"
-
}
-
);
Inserting:
-
-
friends.insert(
-
{name:"Brian",
-
gender:"M",
-
married:"No",
-
age:52,
-
state:"FL",
-
favorite_foods:["fruit","steak"]
-
});
In addition, Taffy DB provides 12 different conditional statements (e.g.: "greaterthan", "equal", "like") to help build advanced queries that can further filter your results.
Ian has created a Getting Started Guide which will help in getting up to speed on the full capabilities of Taffy DB.












I’ve seen a ton of these kind of systems, but I’ve never seen one on the client-side. To be honest, I’ve never even thought of the idea. This is great stuff. It’s probably not the first time such a simple idea has been implemented in JavaScript, but it’s the first time I’ve seen it, so to me it’s entirely new and amazing. I might actually use this in my web application (whenever that gets done).
Hmm, once i worked on something like this, but i stoped because its not safe
Anyone can go to firebug and execute some js that delete all your database etc
Maybe i am wrong but i don’t think so
I wrote a similar library for JavaScript that follows the ActiveRecord pattern but never released it publicly because there isn’t a ton of use for a client-side database other than long life single page apps. I really like the interface that Ian put on this DB though, it fits in better with the normal JavaScript programming style than ActiveRecord does. Suggestion: Make your documentation page wider than 400px because you’re wasting my screen space ;-).
poft: Not if you implement some sort of security mechanism. I mean, if you just allow any SQL query to be run on your server at any time, then yes, it’s unsafe. But you have to implement some sort of authorization system just like you would in a normal application.
would be fun to get this into a dojo.data store. You could even persist w/ dojox.storage…that’d be pretty sweet, particularly for browsers that don’t yet have sqlite built in.
Will it work on IE7?
infact I would like to ask that can any library like Dojo can cater a buggy IE7/8 ’s Cookie bug issue and store things normally?
@porf & musicfreak.
You both missed the point. This isn’t a library that allows you to write Javascript to connect to your server side database.
This is a database written in Javascript that runs in the browser. It’s a bit like cookies with an SQLeque interface.
hım i traying that’d be pretty sweet, particularly for browsers that don’t yet have sqlite built in.