Skip to content
This repository has been archived by the owner on Nov 24, 2019. It is now read-only.
/ TiTaffyDb Public archive

Example project for a Titanium port of TaffyDb

Notifications You must be signed in to change notification settings

benbahrenburg/TiTaffyDb

This branch is 9 commits behind master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b6f22d3 · Jan 26, 2013

History

11 Commits
Jan 26, 2013
Dec 11, 2011
Jan 26, 2013
Jan 26, 2013

Repository files navigation

TiTaffyDb

==========

TaffyDb for Titanium

TiTaffyDb is a Titanium wrapper around TaffyDb created by Ian Smith.

For examples, and full documentation please visit (taffydb.com)[http://www.taffydb.com] for details.

Example

Below is a sample app.js demonstrating how to use TiTaffyDb in your Titanium Mobile Project. For a fully working demo project please see the example folder.


//Bring the commonJs module into our project
Ti.taffy = require('ti.taffydb').taffyDb;

//Create a new database with some records
var newsfeed = Ti.taffy ([
    {"id":1,"user":"kmart77","stars":3,"text":"JavaScript is a meal best served cold"},
    {"id":2,"user":"lukeisyourfather","stars":5,"text":"Anyone want to meet tonight at Fado?"},
    {"id":3,"user":"bemine","stars":3,"text":"I reallylike the new prirotity inbox #gmail"},
    {"id":4,"user":"keepit","stars":3,"text":"Laughing at this weeks fails video."},
    {"id":5,"user":"piegirl22","stars":3,"text":"It is impossible to change your clothes in a public bathroom. Ick."},
    {"id":6,"user":"kmart77","stars":3,"text":"@kmart77: Have fun in New York!"},
    {"id":7,"user":"justinb","stars":5,"text":"Please set the noise level to earthquake"}
]);

var newFeedCount = newsfeed().count(); // returns 7
Ti.API.info('Records in newfeed =' + newFeedCount);

Ti.API.info('sort records by username');
newsfeed.sort("user") 

Ti.API.info('filter for posts where user is equal to kmart77');
newsfeed({user:"kmart77"}).count() // returns 1

Ti.API.info('updates the star rating, returns a query object');
newsfeed({id:"1"}).update({stars:5});

Ti.API.info('inserts a new record');
newsfeed.insert({"id":8,"user":"justinb","stars":3,"text":"Have a great weekend everyone!"});

Ti.API.info('removes all records for user kmart77');
newsfeed({user:"kmart77"}).remove();

Ti.API.info('Save contents');
newsfeed.save('test1');

Ti.API.info('After reset this many rows are left ' + newsfeed().count());

Ti.API.info('Can this to see if a db is stored ')
Ti.API.info('Does db test1 exist ' + newsfeed.exists('test1'));
Ti.API.info('How about does db test2 exist ' + newsfeed.exists('test2'));

Ti.API.info('Reload our db contents');
newsfeed.open('test1');
Ti.API.info('After reloading the db how many rows do we have? ' + newsfeed().count());

Ti.API.info('Distroy the db');
newsfeed.destroy();

Ti.API.info('After destroying the db rows do we have? ' + newsfeed().count());
Ti.API.info('Does db test1 exist ' + newsfeed.exists('test1'));

Licensing & Support

This project is licensed under the OSI approved Apache Public License (version 2). For details please see the license associated with each project.

Developed by Ben Bahrenburg available on twitter @benCoding

Learn More

Twitter

Please consider following the @benCoding Twitter for updates and more about Titanium.

Blog

For module updates, Titanium tutorials and more please check out my blog at benCoding.Com.