TaffyDB: A Javascript database for your browser

Tagged:  

Have you ever built an Ajax application that has some data that needs to be saved and queried for the current session, but not for multiple sessions. Well, instead of creating a temporary database table Ian Smith has come up with a better solution called Taffy DB.

Taffy DB is like having a SQL database in your browser! The Taffy DB is accessed through JavaScript, so it is great for Ajax applications. The library is under 10KB and plays well with other libraries like jQuery and the Yahoo! User Interface.

Below is how the library is described on the official Taffy DB Website

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:

  • 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

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

Below are some examples of how you would use the library.

Example #1:

Let's say you have a collection of products and you want to find every product that costs less $10 and is not a book. Simple, just write some JavaScript:

products.find({price:{lessthan:10}, type:{not:"Book"}});



Example #2:

Let's say you want to update every product from XZYDesign and set the status to not available:

products.update({status:"NA"},{manufacturer:"XZYDesign"});



Example #3:

Let's say you want to sort your products based on type, price ascending, and quantity ascending:

products.orderBy(["type",{"price":"asce"},{"quantity":"asce"}]);

Below are the methods that are available from the library.

  • Find Method
  • Update Method
  • Insert Method
  • Remove Method
  • OrderBy Method
  • ForEach Method
  • Get and First Methods

You can find an overview of all of these methods here.

You can read more about the library here.
You can download the library here.

You can see the library in action at Joe's Goals and Quote Wizard. I can see a lot of uses for this in some future applications. If you use this library in any of your applications I would love to hear about it (you can leave a comment about it or write a blog using your free Ajaxonomy account).

[...] TaffyDB: A Javascript database for your browser | Ajaxonomy (tags: javascript database web lazycoder) [...]

Hi,

TaffyDB would appear to be a smart way of using javascript arrays as a database, which has been widely discussed and used by many people including myself. My suggested extension would be to use php to get a chunk of selected data from a mySQL database and to load it into the arrays (TaffyDB). I already do this with several applications using javascript. It allows the data chunk to be manipulated client-side, dynamically ie. it allows the user to display the data in a different order or to select using various criteria, without having to call data from the server. This provides a best solution - It keep the data size on the client size small and allows it to be changed dynamically from memory. It also allow the user to get other chunks of data for their purposes by dynamically extracting the data from the database on the server.

The other approach I use is to build js files with the data chunks stored as array load entries.
______________________
name[0] ="john";
surname[0]="Smith";
_______________________
I have programs that build the js files from a database (can be on the server or off the server). These js files can be loaded dynamically into the arrays and used to display various information on the website. Pre-building the js files saves heaps of time especially when the data does not change very often.

Adding a system to load data on demand into TaffyDB would appear to be an obvious extension.

Cheers,

john

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <div> <blockquote> <object> <embed> <img> <param>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.