|
GettingStarted
First steps with AirORM
Featured IntroductionAirORM is an Object Relational Mapping similar to ActiveRecord. It is annotation based and does not rely on XML configuration. It saves all data to an embedded SQLite database. Steps to Get Started
Simple ExampleIn the following example, we will create a simple Person object with a first name, last name, and age. We will have it extend AirORM's ActiveRecord, initialize the database, and create a simple form for saving new records to the database. Setting up your classespackage com.mydomain.myproject.model
{
import info.noirbizarre.airorm.ActiveRecord;
[Bindable]
public dynamic class Person extends ActiveRecord
{
public var firstName:String;
public var lastName:String;
public var age:Number;
}
}Initializing the ORM<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication initialize="init()">
<mx:Script>
<![CDATA[
import info.noirbizarre.airorm.ORM;
import com.mydomain.myproject.model.Person;
private function init():void
{
ORM.registerClass(Person);
ORM.updateDB();//creates or updates database table
}
]]>
</mx:Script>
...
</mx:WindowedApplication>Persisting to the Database<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import com.mydomain.myproject.model.Person;
private function save():void
{
var person:Person = new Person();
person.firstName = firstName.text;
person.lastName = lastName.text;
person.age = age.text;
person.save();//this automatically constructs your sql and persists it to the database.
}
]]>
</mx:Script>
<mx:Form width="100%" height="100%">
<mx:FormItem label="First Name">
<mx:TextInput id="firstName"/>
</mx:FormItem>
<mx:FormItem label="Last Name">
<mx:TextInput id="lastName"/>
</mx:FormItem>
<mx:FormItem label="Age">
<mx:TextInput id="age"/>
</mx:FormItem>
</mx:Form>
<mx:Button label="Save" click="save()"/>
</mx:Canvas>
|
► Sign in to add a comment
i figured out how to use this on my own and posted a screencast tutorial http://www.realgt.com/2009/4/How-to-use-AirORM-A-Flex-ORM-based-on-ActiveRecord
hth
its nice product. By default main.db is created. how to change database name?