Implement databaseList command and Add MockDatabaseDriver.
Reviewed By: lblasa Differential Revision: D48172577 fbshipit-source-id: 10d6301041b3a4b3ab83b19e9afd3eac7ad7004c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fea326be79
commit
9db2c74632
@@ -9,6 +9,8 @@
|
||||
#import <FlipperKit/FlipperClient.h>
|
||||
#import <FlipperKit/FlipperConnection.h>
|
||||
#import <FlipperKit/FlipperResponder.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#import "DatabaseDescriptor.h"
|
||||
#import "DatabaseDriver.h"
|
||||
|
||||
@interface DatabasesManager ()
|
||||
@@ -46,11 +48,78 @@
|
||||
}
|
||||
|
||||
- (void)listenForCommands {
|
||||
// TODO(fulvioabrahao) implement commands.
|
||||
[self.connection
|
||||
receive:@"databaseList"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder) {
|
||||
NSInteger databaseId = 1;
|
||||
[self.databaseDescriptorHolders removeAllObjects];
|
||||
[self.databaseDescriptorHolderSet removeAllObjects];
|
||||
|
||||
for (id<DatabaseDriver> databaseDriver in self.databaseDrivers) {
|
||||
NSArray<id<DatabaseDescriptor>>* databaseDescriptorList =
|
||||
[databaseDriver getDatabases];
|
||||
for (id<DatabaseDescriptor> databaseDescriptor in
|
||||
databaseDescriptorList) {
|
||||
DatabaseDescriptorHolder* databaseDescriptorHolder =
|
||||
[[DatabaseDescriptorHolder alloc]
|
||||
initWithIdentifier:databaseId
|
||||
databaseDriver:databaseDriver
|
||||
databaseDescriptor:databaseDescriptor];
|
||||
self.databaseDescriptorHolders[@(databaseId)] =
|
||||
databaseDescriptorHolder;
|
||||
[self.databaseDescriptorHolderSet
|
||||
addObject:databaseDescriptorHolder];
|
||||
databaseId++;
|
||||
}
|
||||
}
|
||||
|
||||
NSDictionary* result = [DatabasesManager
|
||||
databaseListToDictionary:self.databaseDescriptorHolderSet];
|
||||
[responder success:result];
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
receive:@"getTableData"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder){
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
receive:@"getTableStructure"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder){
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
receive:@"getTableInfo"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder){
|
||||
}];
|
||||
|
||||
[self.connection
|
||||
receive:@"execute"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder){
|
||||
}];
|
||||
}
|
||||
|
||||
+ (NSDictionary*)databaseListToDictionary:
|
||||
(NSSet<DatabaseDescriptorHolder*>*)databaseDescriptorHolderSet {
|
||||
NSMutableDictionary* resultDict = [NSMutableDictionary new];
|
||||
|
||||
for (DatabaseDescriptorHolder* descriptorHolder in
|
||||
databaseDescriptorHolderSet) {
|
||||
NSArray<NSString*>* tableNameList = [descriptorHolder.databaseDriver
|
||||
getTableNames:descriptorHolder.databaseDescriptor];
|
||||
NSArray<NSString*>* sortedTableNames =
|
||||
[tableNameList sortedArrayUsingSelector:@selector(compare:)];
|
||||
NSString* idString =
|
||||
[NSString stringWithFormat:@"%ld", descriptorHolder.identifier];
|
||||
NSDictionary* databaseDict = @{
|
||||
@"id" : idString,
|
||||
@"name" : descriptorHolder.databaseDescriptor.name,
|
||||
@"tables" : sortedTableNames
|
||||
};
|
||||
[resultDict setObject:databaseDict forKey:idString];
|
||||
}
|
||||
|
||||
return resultDict;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#import <FlipperKit/FlipperResponder.h>
|
||||
#import "DatabaseDriver.h"
|
||||
#import "DatabasesManager.h"
|
||||
#import "MockDatabaseDriver.h"
|
||||
|
||||
@interface FlipperKitDatabasesPlugin ()
|
||||
@property(strong, nonatomic) id<FlipperConnection> connection;
|
||||
@@ -22,7 +23,8 @@
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
NSArray<id<DatabaseDriver>>* databaseDrivers = @[];
|
||||
NSArray<id<DatabaseDriver>>* databaseDrivers =
|
||||
@[ [MockDatabaseDriver new] ];
|
||||
_databasesManager =
|
||||
[[DatabasesManager alloc] initWithDatabaseDrivers:databaseDrivers];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DatabaseDescriptor.h"
|
||||
|
||||
@interface MockDatabaseDescriptor : NSObject<DatabaseDescriptor>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "MockDatabaseDescriptor.h"
|
||||
|
||||
@implementation MockDatabaseDescriptor
|
||||
|
||||
- (NSString*)name {
|
||||
return @"MockDatabase";
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DatabaseDriver.h"
|
||||
|
||||
@interface MockDatabaseDriver : NSObject<DatabaseDriver>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "MockDatabaseDriver.h"
|
||||
#import "MockDatabaseDescriptor.h"
|
||||
|
||||
@implementation MockDatabaseDriver
|
||||
|
||||
- (NSArray<id<DatabaseDescriptor>>*)getDatabases {
|
||||
MockDatabaseDescriptor* mockDescriptor =
|
||||
[[MockDatabaseDescriptor alloc] init];
|
||||
return @[ mockDescriptor ];
|
||||
}
|
||||
|
||||
- (NSArray<NSString*>*)getTableNames:
|
||||
(id<DatabaseDescriptor>)databaseDescriptor {
|
||||
return @[ @"MockTable1", @"MockTable2" ];
|
||||
}
|
||||
|
||||
@synthesize databaseDescriptor;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user