Overview
Ohmoc is a library that allows you to persist and query objects. It uses rlite, a persistence layer with a Redis-compatible API. It is inspired in Ohm.
Example
#import "Event.h"
#import "Person.h"
- (void) myCode {
// initialize the database
[Ohmoc createWithDocumentFilename:@"data.rld"];
// Create some persons
Person* mariano = [Person create:@{@"name": @"Mariano"}]
Person* julio = [Person create:@{@"name": @"Julio"}]
Person* michel = [Person create:@{@"name": @"Michel"}]
// Create some events
Event* nscoderba = [Event create:@{@"name": @"NSCoderBA", @"location": @"Buenos Aires"}];
Event* rubymeetup = [Event create:@{@"name": @"Ruby Meetup", @"location": @"Paris"}];
// Some people want go to some events
[nscoderba.attendees add:mariano];
[nscoderba.attendees add:julio];
[rubymeetup.attendees add:michel];
// ...
// Let's run some queries to fetch these values
[[Event all] arrayValue]; // @[nscoderba, rubymeetup]
for (Event* ev in [Event find:@{@"location": @"Buenos Aires"}]) {
NSLog(@"%@", ev.name); // NSCoderBA
}
Event* nsCoderBa = [Event with:@"name" is:@"NSCoderBA"];
NSLog(@"%@", nsCoderBa.location); // Buenos Aires
}
#include <Ohmoc.h>
@interface Event : OOCModel
@property NSString* name;
@property id<OOCUnique> nameMeta;
@property NSString* location;
@property id<OOCIndex> locationMeta;
@property OOCMutableSet<Person>* attendees;
@end
#include <Ohmoc.h>
@protocol Person <NSObject>
@end
@interface Person : OOCModel
@property NSString* name;
@end
Installing
Ohmoc is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ohmoc"
Updated less than a minute ago