-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
66 lines (54 loc) · 2.23 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
----------------------------------------------------------------
Simple JS Model for Appcelerator Titanium
----------------------------------------------------------------
http://github.com/swanify/Appcelerator-Titanium-DB-Model
This is a really simple template for a model to handle database
interaction when using Appcelerator Titanium to build iPhone /
Android applications, there are some really useful functions,
and you can easily add your own custom functions.
We like to place them in their own folder called models i.e.
/Resources/models/item.js
----------------------------------------------------------------
INSTRUCTIONS:
----------------------------------------------------------------
Replace all occurrences of Singular with your desired name, i.e.
Item, Person, Setting etc
Replace all occurrences of TABLE with the name of your table,
i.e. ITEMS, PEOPLE, SETTINGS
Replace all occurrences of DB with the name of your DB.
Enter all your columns in the this.columns array, created and
updated will be automatically updated so you just need to
include them in your table.
----------------------------------------------------------------
USAGE:
----------------------------------------------------------------
TO INCLUDE THE MODEL
Ti.include('models/item.js');
----------------------------------------------------------------
TO CREATE A NEW ENTRY
----------------------------------------------------------------
var item = new Item();
item.name = 'Example';
item.price = '2.99';
item.save();
----------------------------------------------------------------
TO UPDATE AN ENTRY
----------------------------------------------------------------
var item = new Item();
item.getById(1);
item.name = 'Example 2';
item.save();
----------------------------------------------------------------
TO GET NUMBER OF ROWS
----------------------------------------------------------------
var item = new Item();
var numRows = item.countAll();
----------------------------------------------------------------
TO LOOP THROUGH RESULTS
----------------------------------------------------------------
var item = new Item();
var rows = item.getAll();
for ( var i=0, len=rows.length; i<len; ++i ){
Ti.API.info('ID: ' + rows[i].id);
Ti.API.info('Name: ' + rows[i].name);
}