My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GettingStarted  
First steps with AirORM
Featured
Updated Jul 12, 2009 by noirbiza...@gmail.com

Introduction

AirORM 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

  1. Download and save AirORM.swc into your project's libs folder.
  2. Setup your value/model classes to extend info.noirbizarre.airorm.ActiveRecord
  3. During your application's initialize event (for example) register your classes using info.noirbizarre.airorm.ORM#registerClass()
  4. Once you have registered all your classes, call info.noirbizarre.airorm.ORM#updateDB()
  5. In your application, you can now perform changes to instances of your model objects and call the save() method to persist them.

Simple Example

In 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 classes

package 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>
Comment by project member realgt, Apr 1, 2009

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

Comment by sathisho...@gmail.com, Mar 28, 2010

its nice product. By default main.db is created. how to change database name?


Sign in to add a comment
Powered by Google Project Hosting