Access your local database using Action Script 3.
- Add AS3-Database-Utils.swc to Your project
- Let's implement the code below
public class Person extends Entity
{
public var name:String;
public var age:uint;
public var mail:String;
}
Db.loadDatabase("Person");
Db.registerEntity(Person); // one Entity
Db.registerEntitys([Person, Animal]); // many Entity
var person:Person = new Person();
person.name = "Ahmad Arif";
person.age = 23;
person.mail = "ahmad.arif019@gmail.com";
Db.save(person);
var person:Person = new Person();
person.id = 1;
person.name = "Arif Ahmad";
person.age = 100;
person.mail = "ahmad_arif@icloud.com";
Db.update(person);
var person:Person = new Person();
person.id = 1;
Db.remove(person);
var result:Array = Db.getAll(Person);
if(result != null)
{
for (var i:uint = 0; i < result.length; i++)
{
var tmp:Person = result[i];
trace(tmp.name);
}
}
var obj:Person = Db.getById(Person, 2);
if(obj != null)
{
trace("Name = " + obj.name);
}
var result:Array = Db.getByObject(Person);
if(result != null)
{
for (var i:uint = 0; i < result.length; i++)
{
var tmp:Person = result[i];
trace(tmp.name);
}
}