Skip to content

Basic Conditions

cmancushman edited this page Oct 27, 2017 · 8 revisions

The Purpose of Conditions

Conditions, or instances of the StackBaseCondition class, are filters that refine results when searching for rows with certain traits. Using conditions allows for a large table with many rows to return a small target segment that contains records useful to the client. Conditions are necessary in order to design a scalable backend.


Condition That Checks if Column is Equal to Value (NSNumber or NSString)

Declaration

+(instancetype) columnWithName:(NSString *)columnName isEqualTo:(id)value;

Example

//get the first 3 rows where column 'id' is equal to 10
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnWithName:@"id" isEqualTo:@10]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if Column is not Equal to Value (NSNumber or NSString)

Declaration

+(instancetype) columnWithName:(NSString *)columnName isNotEqualTo:(id)value;

Example

//get the first 3 rows where column 'Name' is not equal to 'Jake'
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnWithName:@"Name" isNotEqualTo:@"Jake"]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if Column is Greater Than Value (NSNumber only)

Declaration

+(instancetype) columnWithName:(NSString *)columnName isGreaterThan:(NSNumber *)value;

Example

//get the first 4 rows where column 'id' is greater than 10
[weakSelf.table getFirst:4 
rowsWhere:[StackBaseCondition columnWithName:@"id" isGreaterThan:@10]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if Column is Less Than Value (NSNumber only)

Declaration

+(instancetype) columnWithName:(NSString *)columnName isLessThan:(NSNumber *)value;

Example

//get the first 4 rows where column 'id' is less than 10
[weakSelf.table getFirst:4 
rowsWhere:[StackBaseCondition columnWithName:@"id" isLessThan:@10]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if Column Starts With Value (NSString only)

Declaration

+(instancetype) columnWithName:(NSString *)columnName startsWith:(NSString *)value;

Example

//get the first 3 rows where the column 'Name' starts with the phrase 'Chri'
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnWithName:@"Name" startsWith:@"Chri"]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if an Array Contains Column (NSNumbers and NSStrings)

Declaration

+(instancetype) columnWithName:(NSString *)columnName matchesOneOfTheseValues:(NSArray *)values;

Example

//get the first 3 rows where the column 'id' is equal to 1, 3, or 5
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnWithName:@"id" matchesOneOfTheseValues:@[@1, @3, @5]]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if an Array Doesn't Contain Column (NSNumbers and NSStrings)

Declaration

+(instancetype) columnWithName:(NSString *)columnName doesNotMatchAnyOfTheseValues:(NSArray *)values;

Example

//get the first 3 rows where the column 'Name' isn't equal to 'Dave' or 'John'
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnWithName:@"Name" doesNotMatchAnyOfTheseValues:@[@"Dave", @"John"]]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Note on Conditions

When passing numeric values into rows (@"example_numeric_field" : @4) or conditions ([StackBaseCondition columnWithName:@"id" isEqualTo:@1]), the numbers must be formatted as NSNumbers or be prefixed with '@' in order to be processed by the backend.

Clone this wiki locally