I wrote about an Active Record implementation for the Adobe Integrated Runtime using it's SQLite database functionality. I put up all the code on Google Code under the name AIR Active Record. Please check it out, let me know of bugs or features, or better yet, submit fixes and add-ons. If you're interested in being an active developer on it let me know.
Update:
To use the ActiveRecord (sorry for the lack of documentation), you need to extend it with a class for each table you'll use. For example, if I wanted an employee table I would create an Employee class like this:
In the metadata, the name is the property name which will be auto-generated and auto-populated (when you access it) for the relation. The className is the full class path (e.g. com.foo.Bar). multiple is a flag that specifies whether it's a one-to-many relationship. You can have many-to-many relationships as well.
If you aren't creating the database yourself there is a handy-dandy feature which will do it for you off of code introspection. Many-to-many is not supported for creation this way unless you have a class for that join table and run it on that.
This will create the table if it doesn't exist, but it is also useful for updating the table if you've added new properties to the class. (right now it doesn't delete columns if you remove properties)
Then, you use it. You'll need to look at the code comments, or maybe generate the AS3 docs off of it to see all you can do, but this is some of what you can do (let's say you have an Employee class and a Task class):
// accessing tasks will autoload them from the database
for each (var task:Task in employee.tasks)
trace(task);
task = new Task("Call your mother");
employee.task.push(task);
employee.saveTasks();
employee.firstName = "Bobby";
employee.save();
var employee2:Employee = new Employee();
employee2.firstName = "Sue";
....
employee2.save();
trace(employee2.id); // new id
Pretty cool stuff. Maybe someone should document it! :D Anyone interested in figuring out and documenting super-cool code, please apply!
[...] Update: AIR Active Record is open sourced. [...]
Hi, can u post an example of the usage of this library. Because I tried to integrate it in my project, but I falied. There where a lot of problem with the proxy implementation.
I really want to use this, but I still don’t get how to use it :$
Feel free to contact me to my email address.
Thanks :)
[...] went back and wrote up some very minimal documentation on using AIRActiveRecord on my post about it and remembered how cool it is. True, more documentation would sure be nice, and [...]
Cool! :)
sweet implementation dude. I looked at proxies for this a while ago and its true that they are a bit problematic, but without pre-processors on the compiler there are few other choices.
Well done on this man a lot of people have been waiting for something like this.
Thanks Campbell!
I’m looking forward to ActionScript 4 which should allow proxy capabilities on any classes, not just subclasses of proxy.
Wow, you rock!
ActiveRecord is the best thing since sliced bread. Everybody loves AIR. What a great combination…
[...] ActiveRecord source and blog post explaining its usage (Jacob [...]
Great tool!!
Just what I was looking for!!
I wanted to contribute, can you add me on the google code projet?
I already have done some fix and enhancement (I can send you before comit).
First off, this ActiveRecord implementation for AIR has saved me a ton of time. So, thank you.
But my question is this… I’ve just now bound an ArrayCollection of objects that extend ActiveRecord to a datagrid. The data appears just as I’d expect but something decidedly odd is happening. The roll-over highlighting and selecting on the datagrid is not working.
When I switch to an ArrayCollection of objects that don’t extend ActiveRecord, it works fine.
Has any one run into this issue? I’ve never seen anything like it in my years of Flex development.
Thanks again!
Doug.
That is weird. I’ve not run into it, but I haven’t used the DataGrid with ActiveRecord either. You could step through the datagrid code on a roll over if you dare. :)
I’m playing with this in gumbo, when I try to get an array of the data in a table using findAll() I get an ‘Error #3137: An index specified for a parameter was out of range.’, details:’variable number must be between ?0 and ?-1′ error (I’m not using any params).
There are two records in the DB.
Any ideas or am I going the wrong way in getting an array (or ideally arraycollection) of the data in a table
Cheers
Just commented out the params section in ActiveRecord.loadItems and findAll now works.
Hmmmmn…