Jessica Fae (jessica_fae) wrote,
Jessica Fae

ActiveRecord and Cocoa.

So, for the last few days I've been trying to get ActiveRecord.framework working on Cocoa and after hacking apart the framework's code I've gotten it to work. Note, I did not rewrite the entire thing, and the code is UGLY. I've uploaded the build of the framework here. If you want to download and use it feel free.

Some notes:

* Does not support migration or anything fancy from Rails.
* Does support direct SQL queries passed into the connection object.
* Does not support translating a generic query into the correct format for your chosen backend on all queries.
* Does support conversion of data types for correct insertion into either MySQL or SQLite.
* Before any creation or fetching of any ARBase inherited objects can be done, you must issue [ARBase setDefaultConnection:(ARConnection *)anARConnection].
* ARMySQLConnection constructor ( + (ARMySQLConnection *)openConnectionWithInfo:(NSDictionary *)aDictionary error:(NSError **)err;) looks for the keys/objects: host:(NSString *)host, port:(NSNumber)port, user:(NSString *)user, password:(NSString *)password, database:(NSString *)database
*ARSQLiteConnection constructor (+ (ARSQLiteConnection *)openConnectionWithInfo:(NSDictionary *)aDictionary error:(NSError **)err;) looks for only one key/object: path:(NSString *)pathToSQLiteDatabaseFile
* Both connection types define - executeSQL:(NSString *)query substitutions:(NSDictionary *)someSubstitutions;, I have modified both of these functions to allow for a direct query input by passing a properly formatted and escaped query as the string and nil as the dictionary.
* Values set for string type storage elements in the ARBase class are ' and " safe (so you can do [ARBase setValue:@"Don't run!" forKey:@"instruction"] and it will escape the ' with \').
* Framework is built as 32-bit Universal 10.6 with Garbage Collection Required. (I wasn't about to go through the entire framework and ensure that all necessary retain/release calls were made to keep it free from memory leaks, and since I use GC in all of my code projects, you get my settings.)

This framework was originally written by and not me. I only made the necessary modifications to make it actually work with both MySQL and SQLite on my 10.6.1 install of OS X.  If you are a developer interested in the source with my mods in it for any reason, please leave a comment here and I will send it  your way.  One day I may go through it and recode the entire thing, but for now, no.

*edit: I forgot to include some install notes! Just extract the ActiveRecord.framework directory from the DMG into your /Library/Frameworks directory. Then you can include it by adding an existing framework to be linked to your target. If you add a copy files build phase to set to copy to Frameworks and add the framework to it, then it'll build with the framework embedded and you won't need to have the user install it.
Tags: cocoa, code, mac, objective-c, os x, os x 10.6, snow leopard

  • كلمة اليوم

    كلمة اليوم هي الفسوق! Today's word of the day comes to you in honor of being in Vegas! Though, apparently something (probably this app) deleted…

  • اختبار

    هذا هو اختبار

  • Trying to not be confused.

    So, I am sitting here watching some anime, and it has the usual problems that I run into with anime. Firstly, it is very childish in many ways. It…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.