Example project for a Titanium port of TaffyDb
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




The original code can be found in the Release1 branch.

Please be aware that this version HAS BREAKING changes compared with the original. However the changes are not too big and they should be easy to be implemented.

This version aims to an easier update of the TaffyDb library in the future and a simplification of the APIs.

###TaffyDb for Titanium

Full credit goes to Ben Bahrenburg for the initial implementation of TaffyDB for Titanium, and to Ian Smith for the great TaffyDB library.

The version used in the Release1 branch of TiTaffyDb has a bug (I think the bug is in the older version of TaffyDB used by this module) that doesn't allow multiple dbs in the same file. There are query caching optimizations that make the data to be overwriten for the same query on two different dbs.

How the TiTaffyDb implementation goes deep integrated into TaffyDb, a simple update to the latest version was too much for me (I'm too lazy) so I stole some code from Ben and created a simpler wrapper for TaffyDb.

The syntax is cleaner (in my opinion) and the update to a future version of Taffy should be painless.


  • Right now the only storage method is to a file. I will add, maybe :), storing to properties.
  • I tested it only on iOs, but the Ben's version was working just fine on Android so I see no reason why this version wouldn't. Anyway, I'll run some test and update this howto.

####How to

#####Create a database - plain simple The constructor accepts as argument the name of the store where the data wil reside.

var taffy = require('/taffydb4ti').taffy;

var my_db = new taffy('my_db_store_name');



#####Create a database - passing taffydb settings More about Taffy settings (scroll to db.settings() )

var taffy = (require('/taffydb4ti').taffy;

var my_db = new taffy('my_db_store_name',{onInsert: function(){alert('We had an insert!')}});



#####Create a database - autocommit This setting will autosave each change you are doing to the database. While handy, if you have many operation on the the db I suggest not to use it and call db.save() yourself. Of course autocommit can be used together with taffy settings.

var taffy = (require('/taffydb4ti').taffy;

var my_db = new taffy('my_db_store_name',{autocommit:true});


// no need for my_db.save() anymore;

#####Instantiate taffydb4ti with initial data To load taffydb4ti with a pre-defined JSON string, you pass data as a third parameter.

var taffy = (require('/taffydb4ti').taffy;
var inJSON=[
	{manufacturer:'Apple',model:'iPod',version:'4th Gen'},

var my_db = new taffy('my_db_store_name',{autocommit:true},inJSON);

my_db().each(function (rec) {
	console.log(rec.manufacturer + '-' + rec.model + '-' + rec.version)

####License TaffyDB is licensed under the BSD licence type.

TiTaffyDb is under the OSI approved Apache Public License (version 2).

As long as you respect the above licenses I don't care what you do with the code.

Just have fun :)

####Changes by Daniel Tamas @dan_tamas

####Additional changes by Ricardo Alcocer @ricardoalcocer