Implement getTableInfo command.
Reviewed By: lblasa Differential Revision: D48266744 fbshipit-source-id: 79f2fd3c4718d6bf7be4a0538ec0d1eb92503eb7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
453b8f7b96
commit
a0510ad1bf
@@ -21,5 +21,7 @@
|
||||
@property(nonatomic, copy, readonly) NSString* table;
|
||||
|
||||
- (instancetype)initWithDatabaseId:(NSInteger)databaseId table:(NSString*)table;
|
||||
+ (DatabaseGetTableInfoRequest*)getTableInfoRequestFromDictionary:
|
||||
(NSDictionary*)dictionary;
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,4 +31,16 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (DatabaseGetTableInfoRequest*)getTableInfoRequestFromDictionary:
|
||||
(NSDictionary*)dictionary {
|
||||
NSNumber* databaseId = @([dictionary[@"databaseId"] integerValue]);
|
||||
NSString* table = dictionary[@"table"];
|
||||
if (databaseId == nil || table == nil) {
|
||||
return nil;
|
||||
}
|
||||
return [[DatabaseGetTableInfoRequest alloc]
|
||||
initWithDatabaseId:databaseId.intValue
|
||||
table:table];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol DatabaseDescriptor;
|
||||
@class DatabaseGetTableStructureRequest;
|
||||
@class DatabaseGetTableInfoResponse;
|
||||
@class DatabaseGetTableStructureResponse;
|
||||
|
||||
@protocol DatabaseDriver<NSObject>
|
||||
@@ -18,4 +18,8 @@
|
||||
getTableStructureWithDatabaseDescriptor:
|
||||
(id<DatabaseDescriptor>)databaseDescriptor
|
||||
forTable:(NSString*)tableName;
|
||||
- (DatabaseGetTableInfoResponse*)
|
||||
getTableInfoWithDatabaseDescriptor:
|
||||
(id<DatabaseDescriptor>)databaseDescriptor
|
||||
forTable:(NSString*)tableName;
|
||||
@end
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#import "DatabaseDescriptorHolder.h"
|
||||
#import "DatabaseDriver.h"
|
||||
#import "DatabaseErrorCodes.h"
|
||||
#import "DatabaseGetTableInfo.h"
|
||||
#import "DatabaseGetTableStructure.h"
|
||||
#import "ObjectMapper.h"
|
||||
|
||||
@@ -132,8 +133,43 @@
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
receive:@"getTableStructure"
|
||||
receive:@"getTableInfo"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder) {
|
||||
DatabaseGetTableInfoRequest* request = [DatabaseGetTableInfoRequest
|
||||
getTableInfoRequestFromDictionary:params];
|
||||
if (!request) {
|
||||
NSDictionary* errorResponse = [ObjectMapper
|
||||
errorWithCode:DatabasesErrorCodesInvalidRequest
|
||||
message:kDatabasesErrorCodesInvalidRequestMessage];
|
||||
[responder error:errorResponse];
|
||||
return;
|
||||
}
|
||||
DatabaseDescriptorHolder* descriptorHolder =
|
||||
self.databaseDescriptorHolders[@(request.databaseId)];
|
||||
if (!descriptorHolder) {
|
||||
NSDictionary* errorResponse = [ObjectMapper
|
||||
errorWithCode:DatabasesErrorCodesDatabaseInvalid
|
||||
message:kDatabasesErrorCodesDatabaseInvalidMessage];
|
||||
[responder error:errorResponse];
|
||||
return;
|
||||
}
|
||||
|
||||
@try {
|
||||
DatabaseGetTableInfoResponse* tableInfo =
|
||||
[descriptorHolder.databaseDriver
|
||||
getTableInfoWithDatabaseDescriptor:descriptorHolder
|
||||
.databaseDescriptor
|
||||
forTable:request.table];
|
||||
NSDictionary* response =
|
||||
[ObjectMapper databaseGetTableInfoResponseToDictionary:tableInfo];
|
||||
[responder success:response];
|
||||
} @catch (NSException* exception) {
|
||||
NSDictionary* errorResponse = [ObjectMapper
|
||||
errorWithCode:DatabasesErrorCodesSqlExecutionException
|
||||
message:[kDatabasesErrorCodesSqlExecutionExceptionMessage
|
||||
stringByAppendingString:exception.reason]];
|
||||
[responder error:errorResponse];
|
||||
}
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#import "MockDatabaseDriver.h"
|
||||
#import "DatabaseGetTableInfo.h"
|
||||
#import "DatabaseGetTableStructure.h"
|
||||
#import "MockDatabaseDescriptor.h"
|
||||
|
||||
@@ -46,4 +47,12 @@
|
||||
indexesValues:[indexesValues copy]];
|
||||
}
|
||||
|
||||
- (DatabaseGetTableInfoResponse*)
|
||||
getTableInfoWithDatabaseDescriptor:
|
||||
(id<DatabaseDescriptor>)databaseDescriptor
|
||||
forTable:(NSString*)tableName {
|
||||
return [[DatabaseGetTableInfoResponse alloc]
|
||||
initWithDefinition:@"This is mocked table definition"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -58,7 +58,9 @@
|
||||
|
||||
+ (NSDictionary*)databaseGetTableInfoResponseToDictionary:
|
||||
(DatabaseGetTableInfoResponse*)response {
|
||||
return @{};
|
||||
return @{
|
||||
@"definition" : response.definition,
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSDictionary*)databaseExecuteSqlResponseToDictionary:
|
||||
|
||||
Reference in New Issue
Block a user