Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Installing and setting up in-app DB?

Hello. I was wondering if anyone could link me (Or write up) a quick guide to setting up an in-app Database using Titanium? I would like to setup a "Favorites" features for my app and the only way I can really think of doing that is through the SQLite DB, but I'm not sure how to go about setting that up.

Any help would be much appreciated!!

— asked October 20th 2010 by Colton Arabsky
  • database
0 Comments

4 Answers

  • You could use the properties feature and instead of using a database do it in an array which you convert to json and save to properties, then you recall it and parse into into a js array.

    http://developer.appcelerator.com/apidoc/desktop/latest/Titanium.API.set-method.html

    http://developer.appcelerator.com/apidoc/desktop/latest/Titanium.JSON-module

    — answered October 20th 2010 by Bryce Wilkinson
    permalink
    0 Comments
  • So I would put all the content I want (Which would be nothing more than 3 or so text fields) into an array, convert that array into a JSON, using:

    var array = [
    {title:'Row1', desc:'Row1', img:'Row1'},
    {title:'Row2', desc:'Row2', img:'Row2'}
    ];
    var json_array = Titanium.JSON.stringify(array)
    

    And then save that into a Property:

    Titanium.App.Properties.setString('favorites', json_array);
    

    And then when I want to get that I just…

    var favorites_string = Titanium.App.Properties.getString('favorites');
    var favorites = Titanium.JSON.parse(favorites_string);
    

    Yes?

    PS - You do know I'm coding for iPhone Applications not a Desktop Application, right?

    — answered October 20th 2010 by Colton Arabsky
    permalink
    0 Comments
  • Here is some nice sample code:

    http://github.com/kwhinnery/Persistence

    — answered October 20th 2010 by Dan Trevino
    permalink
    0 Comments
  • Hmm… Alright, I have having some troubles doing what I would I would like to do. Let me tell you guys what I want and see if you guys can help in any way?

    So I have two tabs: One is "Episodes" and another is "Favorites". From the Episodes tab you click a little icon on the topRightNav and it says "Add to Favorites?" or "Cancel". If you click "Add to Favorites" it adds the episode (There are multiple fields that are filled, such as the date, name, description, an image, and some other things). From there you should click to the "Favorites" tab and see a TableView of all the episodes you have added to your favorites, and be able to remove/move them.

    Any ideas? :) I'm getting mixed up with my coding on the conversion between the two tabs. Not sure how to get the information from the one page onto the other.

    PS - These are in different files each (Two different .js files, linked from the app.js).

    — answered October 21st 2010 by Colton Arabsky
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.