forked from dkeskar/airdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.mxml
More file actions
70 lines (59 loc) · 2.43 KB
/
example.mxml
File metadata and controls
70 lines (59 loc) · 2.43 KB
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
67
68
69
70
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="exInit();">
<mx:Script>
<![CDATA[
import example.Relationship;
import example.Person;
import mx.core.Application;
import com.memamsa.airdb.DB;
import example.Comment;
import example.Post;
public function exInit():void {
DB.initDB('example.db');
var post:Post = new Post();
var cmt:Comment = new Comment();
post.create({title: 'My first post', author: 'cooldude'});
cmt.data({author: 'cooldude', title: '1st'});
post.comments.push(cmt);
trace('Post: ' + post['id'] + ' titled ' + post['title']);
trace('# Comments: ' + post.comments.list().length);
var results:Array;
results = post.comments.findAll({conditions: "author like '%cool%'", order: 'created_at ASC'});
trace('Found: ' + results.length);
// comment on a comment
// we can do self-referential has-many relationships
var sub:Comment = new Comment();
sub.create({title: 'OP is right!', author: 'fanboi'});
cmt.comments.push(sub);
trace('Thread parent: ' + sub.parent.title);
// EXPERIMENTAL
// self-referential has_many using new associative declarations
var mario:Person = new Person();
if (!mario.load({name: 'Mario Spaghetti'})) {
mario.create({name: 'Mario Spaghetti', age: 43, city: 'Rome'});
}
var luigi:Person = new Person();
if (!luigi.load({name: 'Luigi Salvatore'})) {
luigi.create({name: 'Luigi Salvatore', age: 39, city: 'Venice'});
}
var joe:Person = new Person();
if (!joe.load({name: 'Joe Montana'})) {
joe.create({name: 'Joe Montana', age: 55, city: 'New York'});
}
Relationship.make(mario, luigi, 'omerta officers');
Relationship.make(mario, joe, 'baseball buddies');
trace('Friends of Mario: ' + mario.friends.count);
// describe friendships
var frnds:Array = mario.friendships.list();
trace('Iterating Mario friendships');
var rel:Relationship = new Relationship();
for each (var friend:* in frnds) {
rel.load({id: friend.id});
trace(friend.descr + ': ' + friend.to_id + ': ' + rel.receptor.name);
}
}
]]>
</mx:Script>
<mx:Label text="AirDB Example" color="#0728D1" fontSize="22" fontWeight="bold" fontFamily="Helvetica" />
<!-- Add some controls here to showcase and see data -->
</mx:WindowedApplication>