I’ve been working with AIR quite a bit since my side project is in AIR. I thought it would be pretty cool to create an active record implementation in AIR since I’ve got one on the server side.
I have to use synchronous database connections for it so that everytime I access an object’s related properties I don’t have to use a callback, though it could be refactored to do that. Not my idea of fun though, and after an excellent presentation by Jason Williams, “Working with Persistent Data in AIR,” where he showed how fast it was to retrieve data from an AIR database I figured it would be just fine.
Currently I don’t have metadata allowing you to define how every property maps to a field in the database, nor do I have many “special case” hooks for this and that. I figured that any AIR app you write will be using a fresh database and not a legacy system. How many desktop apps using a SQLite database will you be updating with AIR and using the same database file? Maybe I’m wrong, but I don’t think so.
I also added a piece that you can run which will create and update database tables based off the ActiveRecord object’s properties. So you have a nice update mechanism for the database when you update your app using the updater api.
I’ll be open-sourcing the code when I have time (isn’t that always the case), but you can get the code now, test it out, and let me know what enhancements you’d like to see. Sorry, no documentation currently. If I like the ideas or they’re requested enough I’ll be sure to add them in. :)
Oh, and when you unzip it you’ll see “flight” is the package Tyler (my twin) and I are using for our projects. It started when he and Rob Taylor started a component set in AS2 under the name but AS3 and Flex 2 came out and they never finished. Maybe an AS3 set will happen someday.
Update: AIR Active Record is open sourced.
February 29th, 2008 at 5:08 am
Personally, I’d be very interested in something like this. I’ve been too spoiled by ActiveRecord to want to deal with the DB directly.
April 20th, 2008 at 10:38 pm
Hi, I was wondering if you were still planning on releasing this code under an open source license? I’d love to use it but I’d hate to step on your toes, nor do i want to invest a lot of effort only to have to rip out the DB layer if your license requires the full app to be open source a lá GPL.
April 29th, 2008 at 3:33 pm
It will be under the MIT license if that is good for you. I will get that up on a Google Code project today if possible.
Thanks for following up with me on that!
April 29th, 2008 at 11:22 pm
[…] wrote about an Active Record implementation for the Adobe Integrated Runtime using it’s SQLite database functionality. I […]
September 24th, 2008 at 5:02 pm
This is a very cool project, Jacob! I’m having a little trouble getting it to work though. Does it assume that I’m using a database called “main”? It seems to always bomb out on the first call to DB.getSchema().
SQLError: ‘Error #3115: SQL Error.’, details:’No schema objects in database ‘main’ were found.’, operation:’schema’
September 24th, 2008 at 5:54 pm
No, that error happens when you have no tables defined. Make sure to either 1) write the sql to create the tables or 2) use the table creator doing something like…
TableCreator.updateTable(employee);
where employee is an instance of your ActiveRecord class. You can see how it is used here: http://jacwright.com/blog/79/air-activerecord-is-open-source/
September 24th, 2008 at 6:46 pm
Thanks for the quick reply, Jacob! If we can get this thing documented, I predict that there will be HUGE adoption. Sorry for posting my issue here, I posted it in more detail on Google Code.
http://code.google.com/p/air-activerecord/issues/list?updated=2&ts=1222296340
September 25th, 2008 at 12:07 pm
OK, the problem was the at the location of the database. ActiveRecord was creating a new database in the local store instead of using the existing database that I had placed in the Application Directory. As a result, calls to conn.loadSchema() were failing because, like you said, Jacob, the new db didn’t have any tables in it. DB.as, line 29, sets the path of the db to the applicationStorageDirectory, I changed it to applicationDirectory and it works.
Now, if only I could figure out many to many relationships ;)
September 25th, 2008 at 12:11 pm
@jacob, I’ll be happy to write up some how-to’s on Google Code regarding any of these features you help me get working! ;) These classes might save me hours of coding. I can give some of that time back to this project. You can reach me here mc[a la]lightmedium[]com.
September 1st, 2009 at 3:29 pm
i can’t seem to compile it without getting the same error. “SQLError: ‘Error #3115: SQL Error.’, details:’No schema objects in database ‘main’ were found.’, operation:’schema’”
i used the testproject included in the SVN repository.
Does anybody else get the same error?
September 1st, 2009 at 3:33 pm
vitaLee: This is an error when there are no existing tables in the database. If you add a try catch around it you should get it to work fine. It’s a bug I’ve never gotten to fixing. My apologies.
September 1st, 2009 at 3:43 pm
Wow thanks so much Jacob for your lightning fast reply. That worked.
I’m relatively new to this whole thing (Flex, AIR, sqlite) and wasn’t exactly sure what’s wrong.
Thanks again! :)
September 1st, 2009 at 3:59 pm
nope i lied to you.:) the error is caught but it just doesn’t work. i guess i’ll have to create the tables myself and skip the ‘TableCreator.updateTable’ part.
September 2nd, 2009 at 10:58 am
i’d really love to get my hands on a basic example how to use this library. i failed miserably trying to make it work both ways (using TableCreator and manually creating the tables). i keep getting the same error. :(
September 2nd, 2009 at 3:30 pm
I checked it out and updated the code. There is a newer behavior in E4X that was breaking it, and the testproject was old and needed to be updated. I also added the try/catch so that tables are created correctly. You shouldn’t have any problems now. I apologize it was broken. I haven’t looked at it in awhile.
September 2nd, 2009 at 3:34 pm
With the exception that the default SQL schema expected for foreign keys were changed from employerId to employer_id, the example on http://jacwright.com/blog/79/air-activerecord-is-open-source/ should be accurate as well.
September 2nd, 2009 at 4:19 pm
got it working :D
i can continue my quest now. :)
thank you so much for your efforts.