diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.h new file mode 100644 index 000000000..9d1e1eb02 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.h @@ -0,0 +1,27 @@ +/* + * 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 + +@interface DatabaseExecuteSqlResponse : NSObject + +@property(nonatomic, strong) NSString* type; +@property(nonatomic, strong) NSArray* columns; +@property(nonatomic, strong) NSArray* values; +@property(nonatomic, strong) NSNumber* insertedId; +@property(nonatomic, assign) NSInteger affectedCount; + +@end + +@interface DatabaseExecuteSqlRequest : NSObject + +@property(nonatomic, assign, readonly) NSInteger databaseId; +@property(nonatomic, copy, readonly) NSString* value; + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId value:(NSString*)value; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.m new file mode 100644 index 000000000..96494e8d5 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseExecuteSql.m @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#include "DatabaseExecuteSql.h" + +@implementation DatabaseExecuteSqlResponse + +- (instancetype)initWithType:(NSString*)type + columns:(NSArray*)columns + values:(NSArray*)values + insertedId:(NSNumber*)insertedId + affectedCount:(NSInteger)affectedCount { + self = [super init]; + if (self) { + _type = type; + _columns = [columns copy]; + _values = [values copy]; + _insertedId = insertedId; + _affectedCount = affectedCount; + } + return self; +} + +@end + +@implementation DatabaseExecuteSqlRequest + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId + value:(NSString*)value { + self = [super init]; + if (self) { + _databaseId = databaseId; + _value = [value copy]; + } + return self; +} + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.h new file mode 100644 index 000000000..2cc3f850b --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.h @@ -0,0 +1,42 @@ +/* + * 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 + +@interface DatabaseGetTableDataResponse : NSObject + +@property(nonatomic, strong, readonly) NSArray* columns; +@property(nonatomic, strong, readonly) NSArray* values; +@property(nonatomic, assign, readonly) NSInteger start; +@property(nonatomic, assign, readonly) NSInteger count; +@property(nonatomic, assign, readonly) NSInteger total; + +- (instancetype)initWithColumns:(NSArray*)columns + values:(NSArray*)values + start:(NSInteger)start + count:(NSInteger)count + total:(NSInteger)total; + +@end + +@interface DatabaseGetTableDataRequest : NSObject + +@property(nonatomic, assign, readonly) NSInteger databaseId; +@property(nonatomic, copy, readonly) NSString* table; +@property(nonatomic, copy, readonly) NSString* order; +@property(nonatomic, assign, readonly) BOOL reverse; +@property(nonatomic, assign, readonly) NSInteger start; +@property(nonatomic, assign, readonly) NSInteger count; + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId + table:(NSString*)table + order:(NSString*)order + reverse:(BOOL)reverse + start:(NSInteger)start + count:(NSInteger)count; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.m new file mode 100644 index 000000000..632142a01 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableData.m @@ -0,0 +1,50 @@ +/* + * 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 "DatabaseGetTableData.h" + +@implementation DatabaseGetTableDataResponse + +- (instancetype)initWithColumns:(NSArray*)columns + values:(NSArray*)values + start:(NSInteger)start + count:(NSInteger)count + total:(NSInteger)total { + self = [super init]; + if (self) { + _columns = [columns copy]; + _values = [values copy]; + _start = start; + _count = count; + _total = total; + } + return self; +} + +@end + +@implementation DatabaseGetTableDataRequest + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId + table:(NSString*)table + order:(NSString*)order + reverse:(BOOL)reverse + start:(NSInteger)start + count:(NSInteger)count { + self = [super init]; + if (self) { + _databaseId = databaseId; + _table = [table copy]; + _order = [order copy]; + _reverse = reverse; + _start = start; + _count = count; + } + return self; +} + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.h new file mode 100644 index 000000000..2163854a5 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.h @@ -0,0 +1,25 @@ +/* + * 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 + +@interface DatabaseGetTableInfoResponse : NSObject + +@property(nonatomic, strong) NSString* definition; + +- (instancetype)initWithDefinition:(NSString*)definition; + +@end + +@interface DatabaseGetTableInfoRequest : NSObject + +@property(nonatomic, assign, readonly) NSInteger databaseId; +@property(nonatomic, copy, readonly) NSString* table; + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId table:(NSString*)table; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.m new file mode 100644 index 000000000..b86fd8b7f --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableInfo.m @@ -0,0 +1,34 @@ +/* + * 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 "DatabaseGetTableInfo.h" + +@implementation DatabaseGetTableInfoResponse + +- (instancetype)initWithDefinition:(NSString*)definition { + self = [super init]; + if (self) { + _definition = definition; + } + return self; +} + +@end + +@implementation DatabaseGetTableInfoRequest + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId + table:(NSString*)table { + self = [super init]; + if (self) { + _databaseId = databaseId; + _table = [table copy]; + } + return self; +} + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.h new file mode 100644 index 000000000..6d2335d9f --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.h @@ -0,0 +1,34 @@ +/* + * 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 + +@interface DatabaseGetTableStructureResponse : NSObject + +@property(nonatomic, strong, readonly) NSArray* structureColumns; +@property(nonatomic, strong, readonly) + NSArray*>* structureValues; +@property(nonatomic, strong, readonly) NSArray* indexesColumns; +@property(nonatomic, strong, readonly) + NSArray*>* indexesValues; + +- (instancetype) + initWithStructureColumns:(NSArray*)structureColumns + structureValues:(NSArray*>*)structureValues + indexesColumns:(NSArray*)indexesColumns + indexesValues:(NSArray*>*)indexesValues; + +@end + +@interface DatabaseGetTableStructureRequest : NSObject + +@property(nonatomic, assign, readonly) NSInteger databaseId; +@property(nonatomic, copy, readonly) NSString* table; + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId table:(NSString*)table; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.m new file mode 100644 index 000000000..6e24cfaf2 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/Commands/DatabaseGetTableStructure.m @@ -0,0 +1,41 @@ +/* + * 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 "DatabaseGetTableStructure.h" + +@implementation DatabaseGetTableStructureResponse + +- (instancetype) + initWithStructureColumns:(NSArray*)structureColumns + structureValues:(NSArray*>*)structureValues + indexesColumns:(NSArray*)indexesColumns + indexesValues:(NSArray*>*)indexesValues { + self = [super init]; + if (self) { + _structureColumns = [structureColumns copy]; + _structureValues = [structureValues copy]; + _indexesColumns = [indexesColumns copy]; + _indexesValues = [indexesValues copy]; + } + return self; +} + +@end + +@implementation DatabaseGetTableStructureRequest + +- (instancetype)initWithDatabaseId:(NSInteger)databaseId + table:(NSString*)table { + self = [super init]; + if (self) { + _databaseId = databaseId; + _table = [table copy]; + } + return self; +} + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.h new file mode 100644 index 000000000..109d3c98a --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.h @@ -0,0 +1,23 @@ +/* + * 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 +#import "DatabaseDescriptor.h" +#import "DatabaseDriver.h" + +@interface DatabaseDescriptorHolder : NSObject + +@property(nonatomic, assign, readonly) NSInteger identifier; +@property(nonatomic, strong, readonly) id databaseDriver; +@property(nonatomic, strong, readonly) id + databaseDescriptor; + +- (instancetype)initWithIdentifier:(NSInteger)identifier + databaseDriver:(id)databaseDriver + databaseDescriptor:(id)databaseDescriptor; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.m new file mode 100644 index 000000000..467f340ae --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseDescriptorHolder.m @@ -0,0 +1,24 @@ +/* + * 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 "DatabaseDescriptorHolder.h" + +@implementation DatabaseDescriptorHolder + +- (instancetype)initWithIdentifier:(NSInteger)identifier + databaseDriver:(id)databaseDriver + databaseDescriptor:(id)databaseDescriptor { + self = [super init]; + if (self) { + _identifier = identifier; + _databaseDriver = databaseDriver; + _databaseDescriptor = databaseDescriptor; + } + return self; +} + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseErrorCodes.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseErrorCodes.h new file mode 100644 index 000000000..e97a7e431 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabaseErrorCodes.h @@ -0,0 +1,21 @@ +/* + * 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 + +typedef NS_ENUM(NSInteger, DatabasesErrorCodes) { + DatabasesErrorCodesInvalidRequest = 1, + DatabasesErrorCodesDatabaseInvalid = 2, + DatabasesErrorCodesSqlExecutionException = 3, +}; + +static NSString* const kDatabasesErrorCodesInvalidRequestMessage = + @"The request received was invalid"; +static NSString* const kDatabasesErrorCodesDatabaseInvalidMessage = + @"Could not access database"; +static NSString* const kDatabasesErrorCodesSqlExecutionExceptionMessage = + @"SQL execution exception: "; diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.h index ec850e11b..0907f01f3 100644 --- a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.h +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.h @@ -23,61 +23,3 @@ - (BOOL)isConnected; @end - -@interface DatabaseDescriptorHolder : NSObject - -@property(nonatomic, assign, readonly) NSInteger identifier; -@property(nonatomic, strong, readonly) id databaseDriver; -@property(nonatomic, strong, readonly) id - databaseDescriptor; - -- (instancetype)initWithIdentifier:(NSInteger)identifier - databaseDriver:(id)databaseDriver - databaseDescriptor:(id)databaseDescriptor; - -@end - -@interface ExecuteSqlRequest : NSObject - -@property(nonatomic, assign, readonly) NSInteger databaseId; -@property(nonatomic, copy, readonly) NSString* value; - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId value:(NSString*)value; - -@end - -@interface GetTableDataRequest : NSObject - -@property(nonatomic, assign, readonly) NSInteger databaseId; -@property(nonatomic, copy, readonly) NSString* table; -@property(nonatomic, copy, readonly) NSString* order; -@property(nonatomic, assign, readonly) BOOL reverse; -@property(nonatomic, assign, readonly) NSInteger start; -@property(nonatomic, assign, readonly) NSInteger count; - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId - table:(NSString*)table - order:(NSString*)order - reverse:(BOOL)reverse - start:(NSInteger)start - count:(NSInteger)count; - -@end - -@interface GetTableStructureRequest : NSObject - -@property(nonatomic, assign, readonly) NSInteger databaseId; -@property(nonatomic, copy, readonly) NSString* table; - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId table:(NSString*)table; - -@end - -@interface GetTableInfoRequest : NSObject - -@property(nonatomic, assign, readonly) NSInteger databaseId; -@property(nonatomic, copy, readonly) NSString* table; - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId table:(NSString*)table; - -@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.mm b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.m similarity index 52% rename from iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.mm rename to iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.m index 7447aa551..5bebe3bfc 100644 --- a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.mm +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/DatabasesManager.m @@ -11,7 +11,11 @@ #import #include #import "DatabaseDescriptor.h" +#import "DatabaseDescriptorHolder.h" #import "DatabaseDriver.h" +#import "DatabaseErrorCodes.h" +#import "DatabaseGetTableStructure.h" +#import "ObjectMapper.h" @interface DatabasesManager () @@ -73,7 +77,7 @@ } } - NSDictionary* result = [DatabasesManager + NSDictionary* result = [ObjectMapper databaseListToDictionary:self.databaseDescriptorHolderSet]; [responder success:result]; }]; @@ -89,7 +93,7 @@ }]; [self.connection - receive:@"getTableInfo" + receive:@"getTableStructure" withBlock:^(NSDictionary* params, id responder){ }]; @@ -99,107 +103,4 @@ }]; } -+ (NSDictionary*)databaseListToDictionary: - (NSSet*)databaseDescriptorHolderSet { - NSMutableDictionary* resultDict = [NSMutableDictionary new]; - - for (DatabaseDescriptorHolder* descriptorHolder in - databaseDescriptorHolderSet) { - NSArray* tableNameList = [descriptorHolder.databaseDriver - getTableNames:descriptorHolder.databaseDescriptor]; - NSArray* 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 - -@implementation DatabaseDescriptorHolder - -- (instancetype)initWithIdentifier:(NSInteger)identifier - databaseDriver:(id)databaseDriver - databaseDescriptor:(id)databaseDescriptor { - self = [super init]; - if (self) { - _identifier = identifier; - _databaseDriver = databaseDriver; - _databaseDescriptor = databaseDescriptor; - } - return self; -} - -@end - -@implementation ExecuteSqlRequest - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId - value:(NSString*)value { - self = [super init]; - if (self) { - _databaseId = databaseId; - _value = [value copy]; - } - return self; -} - -@end - -@implementation GetTableDataRequest - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId - table:(NSString*)table - order:(NSString*)order - reverse:(BOOL)reverse - start:(NSInteger)start - count:(NSInteger)count { - self = [super init]; - if (self) { - _databaseId = databaseId; - _table = [table copy]; - _order = [order copy]; - _reverse = reverse; - _start = start; - _count = count; - } - return self; -} - -@end - -@implementation GetTableStructureRequest - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId - table:(NSString*)table { - self = [super init]; - if (self) { - _databaseId = databaseId; - _table = [table copy]; - } - return self; -} - -@end - -@implementation GetTableInfoRequest - -- (instancetype)initWithDatabaseId:(NSInteger)databaseId - table:(NSString*)table { - self = [super init]; - if (self) { - _databaseId = databaseId; - _table = [table copy]; - } - return self; -} - @end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin.mm b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin.m similarity index 100% rename from iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin.mm rename to iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin.m diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.h b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.h new file mode 100644 index 000000000..a67d77611 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.h @@ -0,0 +1,30 @@ +/* + * 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 + +@class DatabaseDescriptorHolder; +@class DatabaseExecuteSqlResponse; +@class DatabaseGetTableDataResponse; +@class DatabaseGetTableInfoResponse; +@class DatabaseGetTableStructureResponse; + +@interface ObjectMapper : NSObject + ++ (NSDictionary*)databaseListToDictionary: + (NSMutableSet*)databaseDescriptorHolderSet; ++ (NSDictionary*)databaseGetTableDataResponseToDictionary: + (DatabaseGetTableDataResponse*)response; ++ (NSDictionary*)databaseGetTableStructureResponseToDictionary: + (DatabaseGetTableStructureResponse*)response; ++ (NSDictionary*)databaseGetTableInfoResponseToDictionary: + (DatabaseGetTableInfoResponse*)response; ++ (NSDictionary*)databaseExecuteSqlResponseToDictionary: + (DatabaseExecuteSqlResponse*)response; ++ (NSDictionary*)errorWithCode:(NSInteger)code message:(NSString*)message; + +@end diff --git a/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.m b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.m new file mode 100644 index 000000000..fd9d080a0 --- /dev/null +++ b/iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.m @@ -0,0 +1,63 @@ +/* + * 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 "ObjectMapper.h" +#include +#import "DatabaseDescriptorHolder.h" +#import "DatabaseExecuteSql.h" +#import "DatabaseGetTableData.h" +#import "DatabaseGetTableInfo.h" +#import "DatabaseGetTableStructure.h" + +@implementation ObjectMapper + ++ (NSDictionary*)databaseListToDictionary: + (NSMutableSet*)databaseDescriptorHolderSet { + NSMutableDictionary* result = [NSMutableDictionary new]; + + for (DatabaseDescriptorHolder* holder in databaseDescriptorHolderSet) { + NSArray* tables = + [holder.databaseDriver getTableNames:holder.databaseDescriptor]; + NSArray* sortedTableNames = + [tables sortedArrayUsingSelector:@selector(compare:)]; + NSString* idString = [NSString stringWithFormat:@"%ld", holder.identifier]; + NSDictionary* databaseInfo = @{ + @"id" : idString, + @"name" : holder.databaseDescriptor.name, + @"tables" : sortedTableNames + }; + [result setObject:databaseInfo forKey:idString]; + } + + return result; +} + ++ (NSDictionary*)databaseGetTableDataResponseToDictionary: + (DatabaseGetTableDataResponse*)response { + return @{}; +} + ++ (NSDictionary*)errorWithCode:(NSInteger)code message:(NSString*)message { + return @{@"code" : @(code), @"message" : message}; +} + ++ (NSDictionary*)databaseGetTableStructureResponseToDictionary: + (DatabaseGetTableStructureResponse*)response { + return @{}; +} + ++ (NSDictionary*)databaseGetTableInfoResponseToDictionary: + (DatabaseGetTableInfoResponse*)response { + return @{}; +} + ++ (NSDictionary*)databaseExecuteSqlResponseToDictionary: + (DatabaseExecuteSqlResponse*)response { + return @{}; +} + +@end