Hey,
First of all, thanks for the great library. I plan on contributing some, I've started to make a set of methods I've found useful in my project that I'll pull request at some point so you can take a look.
I have a question about SQL representation. You have this in the wiki:
@implementation NSString (sqlRepresentation)
+ (ActiveRecord *)fromSql:(NSString *)sqlData{
return sqlData;
}
- (NSString *)toSql {
return self;
}
+ (const char *)sqlType {
return "text";
}
@end
You have fromSql returning ActiveRecord
, would it not return NSString
? Am I misunderstanding how this works?
I'm setting up sql representation for NSArray. All array will just contain BOOLs, something like this:
NSArray *values = @[ @YES, @NO, @NO, @YES ];
My storage technique is just to serialize the data as JSON and back again. Here's the code:
@implementation NSArray (BBExtension)
+ (id)fromSql:(NSString *)sqlData{
return [NSJSONSerialization JSONObjectWithData:[sqlData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
}
- (NSString *)toSql {
return [NSString stringWithUTF8String:[[NSJSONSerialization dataWithJSONObject:self options:0 error:nil] bytes]];
}
+ (const char *)sqlType {
return "text";
}
@end
I've tested the serialization/deserialization to verify that when I manually do it, it works fine. But when creating the record like so:
BBGroove *groove = [[BBGroove alloc] init];
...
[groove save]; // This returns YES
NSLog(@"Groove: %@", [BBGroove allRecords]);
After the NSLog runs, I get this in the console:
2012-07-29 19:54:55.896 BeatBuilder[3479:c07] SELECT "BBGroove"."id","BBGroove"."updatedAt","BBGroove"."beatUnit","BBGroove"."beats","BBGroove"."tempo","BBGroove"."createdAt","BBGroove"."voices" FROM "BBGroove" LIMIT -1
2012-07-29 19:54:55.897 BeatBuilder[3479:c07] Couldn't retrieve data from database: no such table: BBGroove
2012-07-29 19:54:55.923 BeatBuilder[3479:c07] Groove: (null)
My other models work just fine, but this one model has the custom ARRepresentationProtocol for arrays and doesn't work, so I can't help but think I might be doing something wrong? Do you see something I'm overlooking?
I'll keep looking into it, but wondered if you had some insight. Thanks for the great work!