Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Better Data Management
       with TaffyDB

       taffydb.com
Who here considered
 themselves a JavaScript
Programmer 5 years ago?
Three Types of JavaScript Developer
Three Types of JavaScript Developer
Three Types of JavaScript Developer
Three Types of JavaScript Developer
Three Types of JavaScript Developer
Three Types of JavaScript Developer
It all started with arrays
It all started with arrays

var todos = [
    [quot;Home To Dosquot;,1,false,[
       [quot;Replace light bulbsquot;,false...
It all started with arrays

var todos = [
     [quot;Home To Dosquot;,1,false,[
        [quot;Replace light bulbsquot;,fal...
Functions like this

function checkTask (list,task) {
   for(var li = 0;li<todos;li++) {
      if (todos[li][0] == list) {...
JavaScript Object Literals




                   {}
JavaScript Object Literals

Useful for storing related name value pairs:

     {country:quot;United Statesquot;,
     gove...
JavaScript Object Literals

Useful for storing related name value pairs:

     {country:quot;United Statesquot;,
     gove...
This is TaffyDB
This is TaffyDB

• A wrapper for object literals (records)
This is TaffyDB

• A wrapper for object literals (records)
• Provides a JavaScript centric API (using arrays/objects)
This is TaffyDB

• A wrapper for object literals (records)
• Provides a JavaScript centric API (using arrays/objects)
• Us...
This is TaffyDB

•   A wrapper for object literals (records)
•   Provides a JavaScript centric API (using arrays/objects)
...
This is TaffyDB

•   A wrapper for object literals (records)
•   Provides a JavaScript centric API (using arrays/objects)
...
Create a data collection


// create a populated data collection
var jsConfSpeakers = TAFFY([
    {quot;namequot;:quot;Joh...
Insert




jsConfSpeakers.insert(
   {quot;namequot;:quot;Richard D. Worthquot;,quot;topicquot;:quot;jQuery UIquot;}
 );
Getting records


jsConfSpeakers.first();
// returns {quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!qu...
Getting records


jsConfSpeakers.first();
// returns {quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!qu...
Remove

// delete is a reserved word
// use remove function instead

jsConfSpeakers.remove(0);
Update


jsConfSpeakers.update({quot;topicquot;:quot;TBDquot;},0);
// updates the first record, sets topic = quot;TBDquot;
Advanced filtering

// Use Object Literals to construct quot;where clausesquot;

jsConfSpeakers.find({name:quot;Chris Ande...
Advanced filtering

// Use Object Literals to construct quot;where clausesquot;

jsConfSpeakers.find({name:quot;Chris Ande...
Advanced filtering

// Use Object Literals to construct quot;where clausesquot;

jsConfSpeakers.find({name:quot;Chris Ande...
Let's see it in action...
.forEach() in details

collection.forEach(
  function (r,index) {
      //whatever logic here
  },[optional filter]);
.forEach() in details

collection.forEach(
  function (r,index) {
      //whatever logic here
  },[optional filter]);


//...
TaffyDB is Batteries Included
TaffyDB is Batteries Included

Events:
• onUpdate, onInsert, onRemove
TaffyDB is Batteries Included

Events:
• onUpdate, onInsert, onRemove

JSON Support
TaffyDB is Batteries Included

Events:
• onUpdate, onInsert, onRemove

JSON Support

typeOf() methods
TaffyDB is Batteries Included

Events:
• onUpdate, onInsert, onRemove

JSON Support

typeOf() methods

Object Methods
• is...
TaffyDB is Batteries Included

Events:
• onUpdate, onInsert, onRemove

JSON Support

typeOf() methods

Object Methods
• is...
Does it scale?
Sites Using TaffyDB
Joe's Goals (joesgoals.com)
QuoteWizard (quotewizard.com)
VitaList (vitalist.com)
MostRecent (mostrecent.net)
http://taffydb.com

Learn - Download - Find Help
      Contribute Code
Better Data Management using TaffyDB
Better Data Management using TaffyDB
Better Data Management using TaffyDB
Better Data Management using TaffyDB
Better Data Management using TaffyDB
Upcoming SlideShare
Loading in …5
×

Better Data Management using TaffyDB

7,337 views

Published on

From JSConf 2009. Ian Smith talks about doing better in browser data management using the TaffyDB JavaScript library.

Published in: Technology

Better Data Management using TaffyDB

  1. Better Data Management with TaffyDB taffydb.com
  2. Who here considered themselves a JavaScript Programmer 5 years ago?
  3. Three Types of JavaScript Developer
  4. Three Types of JavaScript Developer
  5. Three Types of JavaScript Developer
  6. Three Types of JavaScript Developer
  7. Three Types of JavaScript Developer
  8. Three Types of JavaScript Developer
  9. It all started with arrays
  10. It all started with arrays var todos = [ [quot;Home To Dosquot;,1,false,[ [quot;Replace light bulbsquot;,false,quot;Ianquot;], [quot;Clean out deskquot;,false,quot;Ianquot;]] ], [quot;Work To Dosquot;,0,true,[ [quot;Fix bug with formquot;,false,quot;Ianquot;], [quot;Draft requirements docquot;,false,quot;Ianquot;], [quot;Learn JavaScript Objectsquot;,false,quot;Ianquot;]] ] ];
  11. It all started with arrays var todos = [ [quot;Home To Dosquot;,1,false,[ [quot;Replace light bulbsquot;,false,quot;Ianquot;], [quot;Clean out deskquot;,false,quot;Ianquot;]] ], [quot;Work To Dosquot;,0,true,[ [quot;Fix bug with formquot;,false,quot;Ianquot;], [quot;Draft requirements docquot;,false,quot;Ianquot;], [quot;Learn JavaScript Objectsquot;,false,quot;Ianquot;]] ] ]; // update Fix bug with form to complete todos[1][3][0][1] = true;
  12. Functions like this function checkTask (list,task) { for(var li = 0;li<todos;li++) { if (todos[li][0] == list) { for (var ta = 0; ta < todos[li][3]; ta++) { if (todos[li][3][ta][0] == task) { todos[li][3][ta][1] == true; } } } } } checkTask(quot;Work To Dosquot;,quot;Draft requirements docquot;);
  13. JavaScript Object Literals {}
  14. JavaScript Object Literals Useful for storing related name value pairs: {country:quot;United Statesquot;, government:quot;Democracyquot;, president:quot;Barrak Obamaquot;}
  15. JavaScript Object Literals Useful for storing related name value pairs: {country:quot;United Statesquot;, government:quot;Democracyquot;, president:quot;Barrak Obamaquot;} Also useful for composing instructions for functions: find({government:quot;Democracyquot;}) // find all records where government == Democracy
  16. This is TaffyDB
  17. This is TaffyDB • A wrapper for object literals (records)
  18. This is TaffyDB • A wrapper for object literals (records) • Provides a JavaScript centric API (using arrays/objects)
  19. This is TaffyDB • A wrapper for object literals (records) • Provides a JavaScript centric API (using arrays/objects) • Uses familiar database concepts
  20. This is TaffyDB • A wrapper for object literals (records) • Provides a JavaScript centric API (using arrays/objects) • Uses familiar database concepts • But it isn't a DB - no persistence
  21. This is TaffyDB • A wrapper for object literals (records) • Provides a JavaScript centric API (using arrays/objects) • Uses familiar database concepts • But it isn't a DB - no persistence • Thin (under 12K) • Opensource and Free • Maintained (v1.7.1) • One global object, no prototype modification
  22. Create a data collection // create a populated data collection var jsConfSpeakers = TAFFY([ {quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!quot;}, {quot;namequot;:quot;Francisco Tolmaskquot;,quot;topicquot;:quot;Objective-Jquot;}, {quot;namequot;:quot;Chris Andersonquot;,quot;topicquot;:quot;CouchDBquot;}, {quot;namequot;:quot;Jeff Hayniequot;,quot;topicquot;:quot;Web Apps on the Desktopquot;}, {quot;namequot;:quot;Stoyan Stefanovquot;,quot;topicquot;:quot;Kick Ass Web Appsquot;} ]);
  23. Insert jsConfSpeakers.insert( {quot;namequot;:quot;Richard D. Worthquot;,quot;topicquot;:quot;jQuery UIquot;} );
  24. Getting records jsConfSpeakers.first(); // returns {quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!quot;}
  25. Getting records jsConfSpeakers.first(); // returns {quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!quot;} // TaffyDB filtering is overloaded // 0 and [0] will both return the first record jsConfSpeakers.get(0); jsConfSpeakers.get([0]); // returns [{quot;namequot;:quot;John Resigquot;,quot;topicquot;:quot;Surprise!quot;}]
  26. Remove // delete is a reserved word // use remove function instead jsConfSpeakers.remove(0);
  27. Update jsConfSpeakers.update({quot;topicquot;:quot;TBDquot;},0); // updates the first record, sets topic = quot;TBDquot;
  28. Advanced filtering // Use Object Literals to construct quot;where clausesquot; jsConfSpeakers.find({name:quot;Chris Andersonquot;}); // returns [2]
  29. Advanced filtering // Use Object Literals to construct quot;where clausesquot; jsConfSpeakers.find({name:quot;Chris Andersonquot;}); // returns [2] jsConfSpeakers.find({topic:{like:quot;Web Appsquot;}}); // returns [3,4]
  30. Advanced filtering // Use Object Literals to construct quot;where clausesquot; jsConfSpeakers.find({name:quot;Chris Andersonquot;}); // returns [2] jsConfSpeakers.find({topic:{like:quot;Web Appsquot;}}); // returns [3,4] jsConfSpeakers.find({ topic:{like:quot;Web Appsquot;}, name:{like:quot;Jeffquot;}}); // returns [3] // quot;where topic like Web Apps and name like Jeffquot;
  31. Let's see it in action...
  32. .forEach() in details collection.forEach( function (r,index) { //whatever logic here },[optional filter]);
  33. .forEach() in details collection.forEach( function (r,index) { //whatever logic here },[optional filter]); // modify r and return it to update the record collection.forEach( function (r,index) { r.field = quot;new valuequot;; return r; });
  34. TaffyDB is Batteries Included
  35. TaffyDB is Batteries Included Events: • onUpdate, onInsert, onRemove
  36. TaffyDB is Batteries Included Events: • onUpdate, onInsert, onRemove JSON Support
  37. TaffyDB is Batteries Included Events: • onUpdate, onInsert, onRemove JSON Support typeOf() methods
  38. TaffyDB is Batteries Included Events: • onUpdate, onInsert, onRemove JSON Support typeOf() methods Object Methods • isSameObject, mergeObject, etc
  39. TaffyDB is Batteries Included Events: • onUpdate, onInsert, onRemove JSON Support typeOf() methods Object Methods • isSameObject, mergeObject, etc Utility Methods
  40. Does it scale?
  41. Sites Using TaffyDB
  42. Joe's Goals (joesgoals.com)
  43. QuoteWizard (quotewizard.com)
  44. VitaList (vitalist.com)
  45. MostRecent (mostrecent.net)
  46. http://taffydb.com Learn - Download - Find Help Contribute Code

×