Implement getTableStructure command.

Reviewed By: lblasa

Differential Revision: D48191484

fbshipit-source-id: 6838590f4e10b4613074e9e9d112a62d4688f739
This commit is contained in:
Fúlvio Abrahão de Paula
2023-08-14 11:07:07 -07:00
committed by Facebook GitHub Bot
parent ce85f44a33
commit 453b8f7b96
11 changed files with 121 additions and 38 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,49 @@
/*
* 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 "DatabaseGetTableStructure.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" ];
}
- (DatabaseGetTableStructureResponse*)
getTableStructureWithDatabaseDescriptor:
(id<DatabaseDescriptor>)databaseDescriptor
forTable:(NSString*)tableName {
NSMutableArray<NSString*>* structureColumns =
[NSMutableArray arrayWithObjects:@"id", @"name", @"age", nil];
NSMutableArray<NSArray<NSString*>*>* structureValues =
[NSMutableArray arrayWithObjects:@[ @"1", @"John", @"25" ],
@[ @"2", @"Jane", @"30" ],
nil];
NSMutableArray<NSString*>* indexesColumns = [NSMutableArray
arrayWithObjects:@"index_name", @"unique", @"indexed_column_name", nil];
NSMutableArray<NSArray<NSString*>*>* indexesValues = [NSMutableArray
arrayWithObjects:@[ @"index_name1", @"false", @"id,name" ],
@[ @"index_name2", @"true", @"age" ],
nil];
return [[DatabaseGetTableStructureResponse alloc]
initWithStructureColumns:[structureColumns copy]
structureValues:[structureValues copy]
indexesColumns:[indexesColumns copy]
indexesValues:[indexesValues copy]];
}
@end