-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a556ece
commit 15d7d07
Showing
9 changed files
with
232 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXSQLResult.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// FLEXSQLResult.h | ||
// FLEX | ||
// | ||
// Created by Tanner on 3/3/20. | ||
// Copyright © 2020 Flipboard. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FLEXSQLResult : NSObject | ||
|
||
/// Describes the result of a non-select query, or an error of any kind of query | ||
+ (instancetype)message:(NSString *)message; | ||
/// @param rowData A list of rows, where each element in the row | ||
/// corresponds to the column given in /c columnNames | ||
+ (instancetype)columns:(NSArray<NSString *> *)columnNames | ||
rows:(NSArray<NSArray<NSString *> *> *)rowData; | ||
|
||
@property (nonatomic, readonly, nullable) NSString *message; | ||
|
||
/// A list of column names | ||
@property (nonatomic, readonly, nullable) NSArray<NSString *> *columns; | ||
/// A list of rows, where each element in the row corresponds | ||
/// to the value of the column at the same index in \c columns. | ||
/// | ||
/// That is, given a row, looping over the contents of the row and | ||
/// the contents of \c columns will give you key-value pairs of | ||
/// column names to column values for that row. | ||
@property (nonatomic, readonly, nullable) NSArray<NSArray<NSString *> *> *rows; | ||
/// A list of rows where the fields are paired to column names. | ||
/// | ||
/// This property is lazily constructed by looping over | ||
/// the rows and columns present in the other two properties. | ||
@property (nonatomic, readonly, nullable) NSArray<NSDictionary<NSString *, id> *> *keyedRows; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
47 changes: 47 additions & 0 deletions
47
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXSQLResult.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// FLEXSQLResult.m | ||
// FLEX | ||
// | ||
// Created by Tanner on 3/3/20. | ||
// Copyright © 2020 Flipboard. All rights reserved. | ||
// | ||
|
||
#import "FLEXSQLResult.h" | ||
#import "NSArray+Functional.h" | ||
|
||
@implementation FLEXSQLResult | ||
@synthesize keyedRows = _keyedRows; | ||
|
||
+ (instancetype)message:(NSString *)message { | ||
return [[self alloc] initWithmessage:message columns:nil rows:nil]; | ||
} | ||
|
||
+ (instancetype)columns:(NSArray<NSString *> *)columnNames rows:(NSArray<NSArray<NSString *> *> *)rowData { | ||
return [[self alloc] initWithmessage:nil columns:columnNames rows:rowData]; | ||
} | ||
|
||
- (id)initWithmessage:(NSString *)message columns:(NSArray *)columns rows:(NSArray<NSArray *> *)rows { | ||
NSParameterAssert(message || (columns && rows)); | ||
NSParameterAssert(columns.count == rows.firstObject.count); | ||
|
||
self = [super init]; | ||
if (self) { | ||
_message = message; | ||
_columns = columns; | ||
_rows = rows; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (NSArray<NSDictionary<NSString *,id> *> *)keyedRows { | ||
if (!_keyedRows) { | ||
_keyedRows = [self.rows flex_mapped:^id(NSArray<NSString *> *row, NSUInteger idx) { | ||
return [NSDictionary dictionaryWithObjects:row forKeys:self.columns]; | ||
}]; | ||
} | ||
|
||
return _keyedRows; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.