+ (id) create

Creates and initializes an Ohmoc instance using a memory only storage and registers the database globally.

+ (id) createWithPath:(NSString*)path

Creates and initializes an Ohmoc instance using a file located at path and registers the database globally.

+ (id) createWithDocumentFilename:(NSString*)filename

Creates and initializes an Ohmoc instance using a file name filename in the documents directory and registers the database globally.

- (id) init

Initializes an Ohmoc instance using a memory only storage and registers the database globally.

- (id) initAllowDuplicates:(BOOL)allowDuplicates

Initializes an Ohmoc instance using a memory only storage and optionally registers the database globally.

- (id) initWithPath:(NSString*)path

Initializes an Ohmoc instance using a file located at path and registers the database globally.

- (id) initWithPath:(NSString*)path allowDuplicates:(BOOL)allowDuplicates

Initializes an Ohmoc instance using a file located at path and optionally registers the database globally.

- (id) initWithDocumentFilename:(NSString*)filename

Initializes an Ohmoc instance using a file name filename in the documents directory and registers the database globally.

- (id) initWithDocumentFilename:(NSString*)filename allowDuplicates:(BOOL)allowDuplicates

Initializes an Ohmoc instance using a file name filename in the documents directory and optionally registers the database globally.

- (OOCSet) find:(NSDictionary)dict model:(Class)modelClass

Finds all objects of class Class that match the filters in dict.

Class must be a subclass of OOCModel.

In dict, the keys must have an index. If the value of the object is an enumerable, it will return objects that match all of the parameters. The filter values can be either the same type of value and would be matched directly, or an enumerable and it will return all objects that match any of the values.

Post* p = [Post create:@{@"tags": @"foo bar baz"}];
BOOL contains = [[Post find:@{@"tag": @[@"foo", @"bar"]}] contains:p];
// true
contains = [[Post find:@{@"tag": @[@"foo", @"bar"]}] contains:p];
// true
contains = [[Post find:@{@"tag": @[@"bar", @"baz"]}] contains:p];
// true
contains = [[Post find:@{@"tag": @[@"baz", @"oof"]}] contains:p];
// false
@interface Post : OOCModel

@property NSString* tags;
@property (readonly) NSSet<OOCIndex>* tag;

@end
@implementation OOCPost

- (NSSet<OOCIndex>*) tag {
    return (NSSet<OOCIndex>*)[NSSet setWithArray:[self.tags componentsSeparatedByString:@" "]];
}

@end

πŸ“˜

Syntax equivalency

Calling OOCModel.+find: is equivalent to Ohmoc.-find:model: using the OOCModel subclass as second parameter.

- (id) with:(NSString*)property is:(id)value model:(Class)modelClass

Gets the instance of modelClass where property is value. Property must have a unique index.

- (id) get:(NSString*)id model:(Class)modelClass

Gets the instance of modelClass where id is id.

- (id) createModel:(Class)modelClass

Create a new blank instance of modelClass.

- (id) create:(NSDictionary*)properties model:(Class)modelClass

Create a new instance of modelClass and applies all the properties.

User* john = [ohmoc create:@{@"fname": @"John", @"lname": @"Doe", @"age": @23} model:[User class]];

john.fname // @"John"
john.lname // @"Doe"
john.age // 23
@interface OOCUser : OOCModel

@property NSString* fname;
@property NSString* lname;
@property int age;

@end

- (OOCSet*) allModels:(Class)modelClass

Gets all instances of modelClass.

- (void) flush

Removes all objects from the database.

- (void) multi

Starts a transaction for multiple operations. This will change the instance global state to a write-only mode, allowing you to create and update objects. Notice that every object that's going to be updated needs to have been fetched before calling multi. Once all the changes are ready, call exec.

- (void) exec

Performs all the write operation since multi was called.