Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Code/RocksDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ NS_ASSUME_NONNULL_BEGIN
that currently exist in the DB.
*/
+ (nullable instancetype)databaseAtPath:(NSString *)path
andDBOptions:(nullable void (^)(RocksDBOptions *options))options;
andDBOptions:(nullable void (^)(RocksDBOptions *options))options
error:(NSError**)error;

/**
Intializes a DB instance and opens the defined Column Families.
Expand All @@ -81,8 +82,9 @@ NS_ASSUME_NONNULL_BEGIN
that currently exist in the DB.
*/
+ (nullable instancetype)databaseAtPath:(NSString *)path
columnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor
andDatabaseOptions:(nullable void (^)(RocksDBDatabaseOptions *options))options;
columnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor
andDatabaseOptions:(nullable void (^)(RocksDBDatabaseOptions *options))options
error:(NSError**)error;

#if !(defined(ROCKSDB_LITE) && defined(TARGET_OS_IPHONE))

Expand Down
21 changes: 13 additions & 8 deletions Code/RocksDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ @implementation RocksDB

#pragma mark - Lifecycle

+ (instancetype)databaseAtPath:(NSString *)path andDBOptions:(void (^)(RocksDBOptions *))optionsBlock
+ (instancetype)databaseAtPath:(NSString *)path andDBOptions:(void (^)(RocksDBOptions *))optionsBlock error:(NSError**)error
{
RocksDB *rocks = [[RocksDB alloc] initWithPath:path];

if (optionsBlock) {
optionsBlock(rocks.options);
}

if ([rocks openDatabaseReadOnly:NO] == NO) {
if ([rocks openDatabaseReadOnly:NO error:error] == NO) {
return nil;
}
return rocks;
}

+ (instancetype)databaseAtPath:(NSString *)path
columnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor
andDatabaseOptions:(void (^)(RocksDBDatabaseOptions *options))optionsBlock
andDatabaseOptions:(void (^)(RocksDBDatabaseOptions *options))optionsBlock
error:(NSError**)error
{
RocksDB *rocks = [[RocksDB alloc] initWithPath:path];

Expand All @@ -101,7 +102,7 @@ + (instancetype)databaseAtPath:(NSString *)path
}
rocks.options.databaseOptions = dbOptions;

if ([rocks openColumnFamilies:descriptor readOnly:NO] == NO) {
if ([rocks openColumnFamilies:descriptor readOnly:NO error:error] == NO) {
return nil;
}
return rocks;
Expand Down Expand Up @@ -186,7 +187,7 @@ - (BOOL)isClosed {

#pragma mark - Open

- (BOOL)openDatabaseReadOnly:(BOOL)readOnly
- (BOOL)openDatabaseReadOnly:(BOOL)readOnly error:(NSError**)error
{
rocksdb::Status status;
if (readOnly) {
Expand All @@ -196,7 +197,9 @@ - (BOOL)openDatabaseReadOnly:(BOOL)readOnly
}

if (!status.ok()) {
NSLog(@"Error opening database: %@", [RocksDBError errorWithRocksStatus:status]);
NSError *statusError = [RocksDBError errorWithRocksStatus:status];
*error = statusError;
NSLog(@"Error opening database: %@", statusError);
[self close];
return NO;
}
Expand All @@ -205,7 +208,7 @@ - (BOOL)openDatabaseReadOnly:(BOOL)readOnly
return YES;
}

- (BOOL)openColumnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor readOnly:(BOOL)readOnly
- (BOOL)openColumnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor readOnly:(BOOL)readOnly error:(NSError**)error
{
rocksdb::Status status;
std::vector<rocksdb::ColumnFamilyDescriptor> *columnFamilies = descriptor.columnFamilies;
Expand All @@ -227,7 +230,9 @@ - (BOOL)openColumnFamilies:(RocksDBColumnFamilyDescriptor *)descriptor readOnly:


if (!status.ok()) {
NSLog(@"Error opening database: %@", [RocksDBError errorWithRocksStatus:status]);
NSError *statusError = [RocksDBError errorWithRocksStatus:status];
*error = statusError;
NSLog(@"Error opening database: %@", statusError);
[self close];
return NO;
}
Expand Down