WIP: utilities for clauses

This commit is contained in:
John Rommel Estropia
2016-06-20 08:09:11 +09:00
parent e5a199489c
commit 3ccbce5c29
12 changed files with 722 additions and 190 deletions

View File

@@ -28,49 +28,171 @@
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass) {
CSFrom *_Nonnull CSFromCreate(Class _Nonnull entityClass) CS_OBJC_RETURNS_RETAINED {
return [CSFrom entityClass:entityClass];
return [[CSFrom alloc] initWithEntityClass:entityClass];
}
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull From(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations) {
CSFrom *_Nonnull CSFromCreate(Class _Nonnull entityClass, NSNull *_Nonnull configuration) CS_OBJC_RETURNS_RETAINED {
return [CSFrom entityClass:entityClass configurations:configurations];
return [[CSFrom alloc] initWithEntityClass:entityClass configuration:configuration];
}
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull CSFromCreate(Class _Nonnull entityClass, NSString *_Nonnull configuration) CS_OBJC_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass configuration:configuration];
}
CS_OBJC_OVERLOADABLE
CSFrom *_Nonnull CSFromCreate(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations) CS_OBJC_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass configurations:configurations];
}
// MARK: - Select
//CSSelectTerm *_Nonnull CSAttribute(NSString *_Nonnull keyPath) CS_OBJC_RETURNS_RETAINED {
//
// return [[CSSelectTerm alloc] initWithKeyPath:keyPath];
//}
CSSelect *_Nonnull CSSelectNumber(CSSelectTerm *_Nonnull selectTerm) CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithNumberTerm:selectTerm];
}
CSSelect *_Nonnull CSSelectDecimal(CSSelectTerm *_Nonnull selectTerm) CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDecimalTerm:selectTerm];
}
CSSelect *_Nonnull CSSelectString(CSSelectTerm *_Nonnull selectTerm) CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithStringTerm:selectTerm];
}
CSSelect *_Nonnull CSSelectDate(CSSelectTerm *_Nonnull selectTerm) CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDateTerm:selectTerm];
}
CSSelect *_Nonnull CSSelectData(CSSelectTerm *_Nonnull selectTerm) CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDataTerm:selectTerm];
}
CSSelect *_Nonnull CSSelectObjectID() CS_OBJC_RETURNS_RETAINED {
return [[CSSelect alloc] initWithObjectIDTerm];
}
// MARK: - Where
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(BOOL value) {
CSWhere *_Nonnull CSWhereValue(BOOL value) CS_OBJC_RETURNS_RETAINED {
return [CSWhere value:value];
return [[CSWhere alloc] initWithValue:value];
}
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSString *_Nonnull format, ...) {
CSWhere *_Nonnull CSWhereFormat(NSString *_Nonnull format, ...) CS_OBJC_RETURNS_RETAINED {
CSWhere *where;
va_list args;
va_start(args, format);
where = [CSWhere predicate:[NSPredicate predicateWithFormat:format arguments:args]];
where = [[CSWhere alloc] initWithPredicate:[NSPredicate predicateWithFormat:format arguments:args]];
va_end(args);
return where;
}
CS_OBJC_OVERLOADABLE
CSWhere *_Nonnull Where(NSPredicate *_Nonnull predicate) {
CSWhere *_Nonnull CSWherePredicate(NSPredicate *_Nonnull predicate) CS_OBJC_RETURNS_RETAINED {
return [CSWhere predicate:predicate];
return [[CSWhere alloc] initWithPredicate:predicate];
}
// MARK: - OrderBy
@class CSOrderBy;
NSSortDescriptor *_Nonnull CSSortAscending(NSString *_Nonnull key) {
return [[NSSortDescriptor alloc] initWithKey:key ascending:YES];
}
NSSortDescriptor *_Nonnull CSSortDescending(NSString *_Nonnull key) {
return [[NSSortDescriptor alloc] initWithKey:key ascending:NO];
}
CSOrderBy *_Nonnull CSOrderBySortKey(NSSortDescriptor *_Nonnull sortDescriptor) CS_OBJC_RETURNS_RETAINED {
return [[CSOrderBy alloc] initWithSortDescriptor:sortDescriptor];
}
CS_OBJC_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderBySortKeys(NSSortDescriptor *_Nonnull sortDescriptor, ...) CS_OBJC_RETURNS_RETAINED {
va_list args;
va_start(args, sortDescriptor);
NSMutableArray *sortDescriptors = [NSMutableArray new];
[sortDescriptors addObject:sortDescriptor];
NSSortDescriptor *next;
while ((next = va_arg(args, NSSortDescriptor *)) != nil) {
[sortDescriptors addObject:next];
}
va_end(args);
return [[CSOrderBy alloc] initWithSortDescriptors:sortDescriptors];
}
CS_OBJC_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderBySortKeys(NSArray<NSSortDescriptor *> *_Nonnull sortDescriptors) CS_OBJC_RETURNS_RETAINED {
return [[CSOrderBy alloc] initWithSortDescriptors:sortDescriptors];
}
// MARK: - GroupBy
CS_OBJC_OVERLOADABLE
CSGroupBy *_Nonnull GroupBy(NSArray<NSString *> *_Nonnull keyPaths) {
return [CSGroupBy keyPaths:keyPaths];
CSGroupBy *_Nonnull CSGroupByKeyPath(NSString *_Nonnull keyPath) CS_OBJC_RETURNS_RETAINED {
return [[CSGroupBy alloc] initWithKeyPath:keyPath];
}
CS_OBJC_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSString *_Nonnull keyPath, ...) CS_OBJC_RETURNS_RETAINED {
va_list args;
va_start(args, keyPath);
NSMutableArray *keyPaths = [NSMutableArray new];
[keyPaths addObject:keyPath];
NSString *next;
while ((next = va_arg(args, NSString *)) != nil) {
[keyPaths addObject:next];
}
va_end(args);
return [[CSGroupBy alloc] initWithKeyPaths:keyPaths];
}
CS_OBJC_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray<NSString *> *_Nonnull keyPaths) CS_OBJC_RETURNS_RETAINED {
return [[CSGroupBy alloc] initWithKeyPaths:keyPaths];
}
// MARK: - Tweak
CS_OBJC_OVERLOADABLE
CSTweak *_Nonnull CSTweakCreate(void (^_Nonnull block)(NSFetchRequest *_Nonnull fetchRequest)) CS_OBJC_RETURNS_RETAINED {
return [[CSTweak alloc] initWithBlock:block];
}