diff --git a/.travis.yml b/.travis.yml index f9a96c1..1bdaf2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,35 @@ language: objective-c -osx_image: xcode7.3 +osx_image: xcode8.2 + +branches: + except: + - gh-pages + +install: + - gem install xcpretty + +env: + global: + - LC_CTYPE=en_US.UTF-8 + - LANG=en_US.UTF-8 + - WORKSPACE=ObjectiveRocks.xcworkspace + - IOS_FRAMEWORK_SCHEME=ObjectiveRocks-iOS + - MACOS_FRAMEWORK_SCHEME=ObjectiveRocks + - IOS_SDK=iphonesimulator10.2 + - MACOS_SDK=macosx10.12 + matrix: + - DESTINATION="arch=x86_64" SIMULATOR="" SCHEME="$MACOS_FRAMEWORK_SCHEME" SDK="$MACOS_SDK" + - DESTINATION="OS=9.0,name=iPhone 6" SIMULATOR="iPhone 6 (9.0)" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" + - DESTINATION="OS=9.1,name=iPhone 6 Plus" SIMULATOR="iPhone 6 Plus (9.1)" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" + - DESTINATION="OS=9.2,name=iPhone 6S" SIMULATOR="iPhone 6S (9.2)" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" + - DESTINATION="OS=9.3,name=iPhone 6S Plus" SIMULATOR="iPhone 6S Plus (9.3)" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" + - DESTINATION="OS=10.1,name=iPhone 7 Plus" SIMULATOR="iPhone 7 Plus (10.1)" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" + script: -- xcodebuild -project ObjectiveRocks.xcodeproj -scheme ObjectiveRocks -sdk macosx ONLY_ACTIVE_ARCH=NO -- xcodebuild test -project ObjectiveRocks.xcodeproj -scheme ObjectiveRocksTests -sdk macosx ONLY_ACTIVE_ARCH=NO -- xcodebuild -project ObjectiveRocks.xcodeproj -scheme ObjectiveRocks-iOS -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -- xcodebuild test -project ObjectiveRocks.xcodeproj -scheme ObjectiveRocksTests-iOS -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO + - set -o pipefail + - xcodebuild -version + - xcodebuild -showsdks + - SIMULATOR_ID=$(xcrun instruments -s devices | grep -io "$SIMULATOR \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/") + - open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $SIMULATOR_ID + - travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO clean build | xcpretty -c + - travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c; diff --git a/CHANGELOG.md b/CHANGELOG.md index 332d282..dace04a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,59 @@ # Change Log +## [0.7.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.7.0) + +Released on 2017.02.19 + +- RocksDB Version: `4.6.1`: [facebook/rocksdb@8d7926a](https://github.com/facebook/rocksdb/commit/8d7926a766f2ab9bd6e7aa8cba80b5d3ff26c52b) + +### Added + +- Missing nullability annotations and light-weight generics throughout code base +- New playground content + +### Updated + +- Project for Xcode 8 +- Swift tests for Swift 3 +- Playground contents and syntax for Swift 3 +- Travis config for iOS 10.2, macOS 10.12 +- Deployment targets to macOS 10.10, iOS 9.0 + +### Removed + +- Removed the deprecated `timeoutHint` option +- Removed the deprecated `maxMemCompactionLevel` option + +### Breaking Changes + +The built-in encoding/decoding of keys and values via the encoding options is completelty removed from this release. The API is completely `NSData`-based now. + +- Removed built-it Key/Value `Encoders` and `Decoders` + - The conversions of custom types to/from `NSData` is the responsibility of the caller +- Removed `EncodingOptions` +- Removed all methods depending on `EncodingOptions` and the built-in key/value `encoding` and all of the their variants: + - `setObject:forKey:` + - `deleteObjectForKey:` + - `objectForKey:` + - `mergeObject:forKey:` + - `mergeOperation:forKey:` +- Refactored all `Iterator`, `Key Comparator` and `Merge Operator` methods accordingly +- Removed `NSNumber` Key-Comparators +- Rename method for setting up default read & write options from `setDefaultReadOptions:andWriteOptions:` to `setDefaultReadOptions:writeOptions:` + - The custom Swift equivalent is `setDefault(readOptions:writeOptions:)` + + +## [0.6.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.6.0) + +Released on 2016.06.12 + +- RocksDB Version: `4.6.1`: [facebook/rocksdb@8d7926a](https://github.com/facebook/rocksdb/commit/8d7926a766f2ab9bd6e7aa8cba80b5d3ff26c52b) + +### Hotfix + +- Removed Cocoapods badges from README + + ## [0.6.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.6.0) Released on 2016.06.12 @@ -12,7 +66,7 @@ Released on 2016.06.12 - Support for `Write Batch with Index` and `Write Batch Iterator` - Support for `Range Compaction` operations - Nullability annotations - - Better compatibility with Swift + - Better compatibility with Swift - New statistics and counters - Cocoapods Podspec - Travis integration @@ -21,13 +75,13 @@ Released on 2016.06.12 - RocksDB initializers were changed to class instead of instance methods - Removed RocksDB methods without error parameter - - Better compatibility with Swift's error-handling model + - Better compatibility with Swift's error-handling model - Refactored all RocksDB methods so that the error parameter is the last - - Better compatibility with Swift's error-handling model + - Better compatibility with Swift's error-handling model - Removed `Column Family Metadata` from iOS target - `RocksDBIteratorKeyRange` is refactored to `RocksDBKeyRange` - - Key ranges are used not only for iterations but also for compaction jobs - - Empty-range constant is refactored to open-range, since it represents a range containing all the keys + - Key ranges are used not only for iterations but also for compaction jobs + - Empty-range constant is refactored to open-range, since it represents a range containing all the keys - ObjectiveRocks builds frameworks now instead of static libraries ## [0.5.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.5.0) @@ -43,7 +97,7 @@ Released on 2016.07.30 ### Removed - Removed `+ (instancetype)LRUCacheWithCapacity:numShardsBits:removeScanCountLimit:` RocksDB Cache initializer - - No longer available since: [facebook/rocksdb@c88ff4c](https://github.com/facebook/rocksdb/commit/c88ff4ca76a6a24632cbdd834f621952a251d7a1) + - No longer available since: [facebook/rocksdb@c88ff4c](https://github.com/facebook/rocksdb/commit/c88ff4ca76a6a24632cbdd834f621952a251d7a1) ## [0.4.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.4.0) @@ -70,7 +124,7 @@ All headers are refactored in this release to provide a pure Objective-C interfa ### Changed - Updated `Thread Status` API - - Adapted according to the changes introduces in: [facebook/rocksdb@bf287b7](https://github.com/facebook/rocksdb/commit/bf287b76e0e7b5998de49e3ceaa2b34d1f3c13ae) + - Adapted according to the changes introduces in: [facebook/rocksdb@bf287b7](https://github.com/facebook/rocksdb/commit/bf287b76e0e7b5998de49e3ceaa2b34d1f3c13ae) ## [0.3.0](https://github.com/iabudiab/ObjectiveRocks/releases/tag/0.3.0) diff --git a/Code/ObjectiveRocks.h b/Code/ObjectiveRocks.h index cfb2cb2..1a8df68 100644 --- a/Code/ObjectiveRocks.h +++ b/Code/ObjectiveRocks.h @@ -27,7 +27,6 @@ extern const unsigned char ObjectiveRocksVersionString[]; #import "RocksDBComparator.h" #import "RocksDBOptions.h" -#import "RocksDBEncodingOptions.h" #import "RocksDBDatabaseOptions.h" #import "RocksDBColumnFamilyOptions.h" #import "RocksDBWriteOptions.h" @@ -43,8 +42,6 @@ extern const unsigned char ObjectiveRocksVersionString[]; #import "RocksDBMergeOperator.h" -#import "RocksDBTypes.h" - #if !(defined(ROCKSDB_LITE) && defined(TARGET_OS_IPHONE)) #import "RocksDBColumnFamilyMetadata.h" diff --git a/Code/RocksDB.h b/Code/RocksDB.h index af6f018..b16f919 100644 --- a/Code/RocksDB.h +++ b/Code/RocksDB.h @@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN @discussion This method initializes the DB with the default Column Family and allows for configuring the DB via the RocksDBOptions block. The block gets a single argument, an - instance of `RocksDBOptions`, which is initialized with the default values and passed for + instance of `RocksDBOptions`, which is initialized with the default values and passed for further tuning. If the options block is `nil`, then default settings will be used. @param path The file path of the DB. @@ -58,11 +58,11 @@ NS_ASSUME_NONNULL_BEGIN + (nullable instancetype)databaseAtPath:(NSString *)path andDBOptions:(nullable void (^)(RocksDBOptions *options))options; -/** +/** Intializes a DB instance and opens the defined Column Families. @param path The file path of the database. - @param descriptor The descriptor holds the names and the options of the existing Column Families + @param descriptor The descriptor holds the names and the options of the existing Column Families in the DB. @param options A block with a single argument, an instance of `RocksDBDatabaseOptions`, which can be used to tune the DB configuration. @@ -102,7 +102,7 @@ NS_ASSUME_NONNULL_BEGIN @return The newly-intialized DB instance with the given path and options. @see RocksDBOptions - + @remark Opening a non-existing database in read-only mode wont have any effect, even if `createIfMissing` option is set. */ @@ -134,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN @remark Opening a non-existing database in read-only mode wont have any effect, even if `createIfMissing` option is set. - @remark When opening DB with read only, it is possible to specify only a subset of column families + @remark When opening DB with read only, it is possible to specify only a subset of column families in the database that should be opened. However, default column family must specified. */ + (nullable instancetype)databaseForReadOnlyAtPath:(NSString *)path @@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN /** @brief Closes the database instance */ - (void)close; -/** +/** Sets the default read & write options for all database operations. @param readOptions A block with an instance of `RocksDBReadOptions` which configures the behaviour of read @@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBWriteOptions */ - (void)setDefaultReadOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions - andWriteOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions; + writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions NS_SWIFT_NAME(setDefault(readOptions:writeOptions:)); @end @@ -178,11 +178,11 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBColumnFamily */ -+ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path; ++ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path; /** Creates a new Column Family with the given name and options. - + @param name The name of the new Column Family. @param options A block with a `RocksDBColumnFamilyOptions` instance for configuring the new Column Family. @@ -195,7 +195,7 @@ NS_ASSUME_NONNULL_BEGIN andOptions:(nullable void (^)(RocksDBColumnFamilyOptions *options))options; /** @brief Returns an array */ -- (NSArray *)columnFamilies; +- (NSArray *)columnFamilies; #if !(defined(ROCKSDB_LITE) && defined(TARGET_OS_IPHONE)) @@ -266,7 +266,9 @@ NS_ASSUME_NONNULL_BEGIN @param error If an error occurs, upon return contains an `NSError` object that describes the problem. @return `YES` if the operation succeeded, `NO` otherwise */ -- (BOOL)setObject:(id)anObject forKey:(id)aKey error:(NSError * _Nullable *)error; +- (BOOL)setData:(NSData *)anObject + forKey:(NSData *)aKey + error:(NSError * _Nullable *)error; /** Stores the given key-object pair into the DB. @@ -281,40 +283,10 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBWriteOptions */ -- (BOOL)setObject:(id)anObject forKey:(id)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; - -/** - Stores the given data object under the given data key in the DB. - - @param data The data for key. - @param aKey The key for object. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDB setObject:forKey: - @see RocksDB setObject:forKey:error: - @see RocksDB setObject:forKey:writeOptions: - @see RocksDB setObject:forKey:error:writeOptions: - */ -- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey error:(NSError * _Nullable *)error; - -/** - Stores the given data object under the given data key in the DB. - - @discussion This method can be used to configure single write operations bypassing the defaults. - - @param data The data for key. - @param aKey The key for object. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @param writeOptions A block with a `RocksDBWriteOptions` instance for configuring this write operation. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDB setObject:forKey: - @see RocksDB setObject:forKey:error: - @see RocksDB setObject:forKey:writeOptions: - @see RocksDB setObject:forKey:error:writeOptions: - */ -- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; +- (BOOL)setData:(NSData *)anObject + forKey:(NSData *)aKey + writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions + error:(NSError * _Nullable *)error; @end @@ -326,10 +298,6 @@ NS_ASSUME_NONNULL_BEGIN /// @name Merge operations ///-------------------------------- - -- (BOOL)mergeOperation:(NSString *)aMerge forKey:(id)aKey error:(NSError * _Nullable *)error; -- (BOOL)mergeOperation:(NSString *)aMerge forKey:(id)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; - /** Merges the given object with the existing data for the given key. @@ -343,7 +311,9 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBMergeOperator */ -- (BOOL)mergeObject:(id)anObject forKey:(id)aKey error:(NSError * _Nullable *)error; +- (BOOL)mergeData:(NSData *)anObject + forKey:(NSData *)aKey + error:(NSError * _Nullable *)error; /** Merges the given object with the existing data for the given key. @@ -360,41 +330,10 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBMergeOperator */ -- (BOOL)mergeObject:(id)anObject forKey:(id)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error ; - - -/** - Merges the given data object with the existing data for the given key. - - @discussion A merge is an atomic read-modify-write operation, whose semantics are defined - by the user-provided merge operator. - - @param data The data being merged. - @param aKey The key for the data. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDBMergeOperator - */ -- (BOOL)mergeData:(NSData *)data forKey:(NSData *)aKey error:(NSError * _Nullable *)error; - -/** - Merges the given data object with the existing data for the given key. - - @discussion A merge is an atomic read-modify-write operation, whose semantics are defined - by the user-provided merge operator. - This method can be used to configure single write operations bypassing the defaults. - - @param data The data being merged. - @param aKey The key for the data. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @param writeOptions A block with a `RocksDBWriteOptions` instance for configuring this merge operation. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDBMergeOperator - @see RocksDBWriteOptions - */ -- (BOOL)mergeData:(NSData *)data forKey:(NSData *)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; +- (BOOL)mergeData:(NSData *)anObject + forKey:(NSData *)aKey + writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions + error:(NSError * _Nullable *)error; @end @@ -413,7 +352,7 @@ NS_ASSUME_NONNULL_BEGIN @param error If an error occurs, upon return contains an `NSError` object that describes the problem. @return The object for the given key. */ -- (nullable id)objectForKey:(id)aKey error:(NSError * _Nullable *)error; +- (nullable NSData *)dataForKey:(NSData *)aKey error:(NSError * _Nullable *)error; /** Returns the object for the given key. @@ -425,37 +364,9 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBReadOptions */ -- (nullable id)objectForKey:(id)aKey readOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions error:(NSError * _Nullable *)error; - -/** - Returns the data for the given key. - - @peram aKey The key for data. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @return The data object for the given key. - - @see RocksDB objectForKey: - @see RocksDB objectForKey:error: - @see RocksDB objectForKey:readOptions: - @see RocksDB objectForKey:error:readOptions: - */ -- (nullable NSData *)dataForKey:(NSData *)aKey error:(NSError * _Nullable *)error; - -/** - Returns the data for the given key. - - @peram aKey The key for data. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @param readOptions A block with a `RocksDBReadOptions` instance for configuring this read operation. - @return The data object for the given key. - - @see RocksDBReadOptions - @see RocksDB objectForKey: - @see RocksDB objectForKey:error: - @see RocksDB objectForKey:readOptions: - @see RocksDB objectForKey:error:readOptions: - */ -- (nullable NSData *)dataForKey:(NSData *)aKey readOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions error:(NSError * _Nullable *)error; +- (nullable NSData *)dataForKey:(NSData *)aKey + readOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions + error:(NSError * _Nullable *)error; @end @@ -474,36 +385,10 @@ NS_ASSUME_NONNULL_BEGIN @param error If an error occurs, upon return contains an `NSError` object that describes the problem. @return `YES` if the operation succeeded, `NO` otherwise */ -- (BOOL)deleteObjectForKey:(id)aKey error:(NSError * _Nullable *)error; - -/** - Deletes the object for the given key. - - @peram aKey The key to delete. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @param writeOptions A block with a `RocksDBWriteOptions` instance for configuring this delete operation. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDBWriteOptions - */ -- (BOOL)deleteObjectForKey:(id)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error ; - -/** - Deletes the data for the given key. - - @peram aKey The key to delete. - @param error If an error occurs, upon return contains an `NSError` object that describes the problem. - @return `YES` if the operation succeeded, `NO` otherwise - - @see RocksDB deleteObjectForKey: - @see RocksDB deleteObjectForKey:error: - @see RocksDB deleteObjectForKey:readOptions: - @see RocksDB deleteObjectForKey:error:readOptions: - */ - (BOOL)deleteDataForKey:(NSData *)aKey error:(NSError * _Nullable *)error; /** - Deletes the data for the given key. + Deletes the object for the given key. @peram aKey The key to delete. @param error If an error occurs, upon return contains an `NSError` object that describes the problem. @@ -511,12 +396,10 @@ NS_ASSUME_NONNULL_BEGIN @return `YES` if the operation succeeded, `NO` otherwise @see RocksDBWriteOptions - @see RocksDB deleteObjectForKey: - @see RocksDB deleteObjectForKey:error: - @see RocksDB deleteObjectForKey:readOptions: - @see RocksDB deleteObjectForKey:error:readOptions: */ -- (BOOL)deleteDataForKey:(NSData *)aKey writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; +- (BOOL)deleteDataForKey:(NSData *)aKey + writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions + error:(NSError * _Nullable *)error; @end @@ -531,7 +414,7 @@ NS_ASSUME_NONNULL_BEGIN /** Returns a write batch instance, which can be used to perform a set of updates to the database atomically. - @discussion This batch instance can be applied at a later point to the DB, making it more flexible + @discussion This batch instance can be applied at a later point to the DB, making it more flexible for “scattered” logic. @see RocksDBWriteBatch @@ -550,7 +433,8 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBWriteBatch */ -- (BOOL)performWriteBatch:(void (^)(RocksDBWriteBatch *batch, RocksDBWriteOptions *options))batch error:(NSError * _Nullable *)error; +- (BOOL)performWriteBatch:(void (^)(RocksDBWriteBatch *batch, RocksDBWriteOptions *options))batch + error:(NSError * _Nullable *)error; /** Applies a write batch instance on this DB. @@ -566,7 +450,9 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBWriteBatch @see RocksDBWriteOptions */ -- (BOOL)applyWriteBatch:(RocksDBWriteBatch *)writeBatch writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error; +- (BOOL)applyWriteBatch:(RocksDBWriteBatch *)writeBatch + writeOptions:(nullable void (^)(RocksDBWriteOptions *writeOptions))writeOptions + error:(NSError * _Nullable *)error; #if !(defined(ROCKSDB_LITE) && defined(TARGET_OS_IPHONE)) @@ -592,7 +478,8 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBIndexedWriteBatch */ -- (BOOL)performIndexedWriteBatch:(void (^)(RocksDBIndexedWriteBatch *batch, RocksDBWriteOptions *options))batch error:(NSError * _Nullable *)error; +- (BOOL)performIndexedWriteBatch:(void (^)(RocksDBIndexedWriteBatch *batch, RocksDBWriteOptions *options))batch + error:(NSError * _Nullable *)error; #endif @@ -677,7 +564,9 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBKeyRange @see RocksDBCompactRangeOptions */ -- (BOOL)compactRange:(RocksDBKeyRange *)range withOptions:(nullable void (^)(RocksDBCompactRangeOptions *options))options error:(NSError * _Nullable *)error; +- (BOOL)compactRange:(RocksDBKeyRange *)range + withOptions:(nullable void (^)(RocksDBCompactRangeOptions *options))options + error:(NSError * _Nullable *)error; @end diff --git a/Code/RocksDB.mm b/Code/RocksDB.mm index 9136739..329a755 100644 --- a/Code/RocksDB.mm +++ b/Code/RocksDB.mm @@ -1,10 +1,10 @@ - // - // ObjectiveRocks.m - // ObjectiveRocks - // - // Created by Iska on 15/11/14. - // Copyright (c) 2014 BrainCookie. All rights reserved. - // +// +// ObjectiveRocks.m +// ObjectiveRocks +// +// Created by Iska on 15/11/14. +// Copyright (c) 2014 BrainCookie. All rights reserved. +// #import "RocksDB.h" @@ -305,7 +305,7 @@ - (RocksDBColumnFamilyMetaData *)columnFamilyMetaData #pragma mark - Read/Write Options -- (void)setDefaultReadOptions:(void (^)(RocksDBReadOptions *))readOptionsBlock andWriteOptions:(void (^)(RocksDBWriteOptions *))writeOptionsBlock +- (void)setDefaultReadOptions:(void (^)(RocksDBReadOptions *))readOptionsBlock writeOptions:(void (^)(RocksDBWriteOptions *))writeOptionsBlock { _readOptions = [RocksDBReadOptions new]; _writeOptions = [RocksDBWriteOptions new]; @@ -353,40 +353,15 @@ - (uint64_t)valueForIntProperty:(RocksDBIntProperty)property #pragma mark - Write Operations -- (BOOL)setObject:(id)anObject forKey:(id)aKey error:(NSError * __autoreleasing *)error +- (BOOL)setData:(NSData *)anObject forKey:(NSData *)aKey error:(NSError * __autoreleasing *)error { - return [self setObject:anObject forKey:aKey writeOptions:nil error:error]; + return [self setData:anObject forKey:aKey writeOptions:nil error:error]; } -- (BOOL)setObject:(id)anObject - forKey:(id)aKey +- (BOOL)setData:(NSData *)anObject + forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock error:(NSError * __autoreleasing *)error -{ - NSError *locError = nil; - NSData *keyData = EncodeKey(aKey, (RocksDBEncodingOptions *)_options, &locError); - NSData *valueData = EncodeValue(aKey, anObject, (RocksDBEncodingOptions *)_options, &locError); - if (locError) { - if (error && *error == nil) { - *error = locError; - } - return NO; - } - - return [self setData:valueData - forKey:keyData - writeOptions:writeOptionsBlock - error:error]; -} - -- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey error:(NSError * __autoreleasing *)error -{ - return [self setData:data forKey:aKey writeOptions:nil error:error]; -} - -- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey - writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock - error:(NSError * __autoreleasing *)error { RocksDBWriteOptions *writeOptions = [_writeOptions copy]; if (writeOptionsBlock) { @@ -396,7 +371,7 @@ - (BOOL)setData:(NSData *)data forKey:(NSData *)aKey rocksdb::Status status = _db->Put(writeOptions.options, _columnFamily, SliceFromData(aKey), - SliceFromData(data)); + SliceFromData(anObject)); if (!status.ok()) { NSError *temp = [RocksDBError errorWithRocksStatus:status]; @@ -411,63 +386,12 @@ - (BOOL)setData:(NSData *)data forKey:(NSData *)aKey #pragma mark - Merge Operations -- (BOOL)mergeOperation:(NSString *)aMerge forKey:(id)aKey error:(NSError * __autoreleasing *)error -{ - return [self mergeOperation:aMerge forKey:aKey writeOptions:nil error:error]; -} - -- (BOOL)mergeOperation:(NSString *)aMerge - forKey:(id)aKey - writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock - error:(NSError * __autoreleasing *)error -{ - NSError *locError = nil; - NSData *keyData = EncodeKey(aKey, (RocksDBEncodingOptions *)_options, &locError); - if (locError) { - if (error && *error == nil) { - *error = locError; - } - return NO; - } - - return [self mergeData:[aMerge dataUsingEncoding:NSUTF8StringEncoding] - forKey:keyData - writeOptions:writeOptionsBlock - error:error]; -} - -- (BOOL)mergeObject:(id)anObject forKey:(id)aKey error:(NSError * __autoreleasing *)error -{ - return [self mergeObject:anObject forKey:aKey writeOptions:nil error:error]; -} - -- (BOOL)mergeObject:(id)anObject - forKey:(id)aKey - writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock - error:(NSError * __autoreleasing *)error -{ - NSError *locError = nil; - NSData *keyData = EncodeKey(aKey, (RocksDBEncodingOptions *)_options, &locError); - NSData *valueData = EncodeValue(aKey, anObject, (RocksDBEncodingOptions *)_options, &locError); - if (locError) { - if (error && *error == nil) { - *error = locError; - } - return NO; - } - - return [self mergeData:valueData - forKey:keyData - writeOptions:writeOptionsBlock - error:error]; -} - -- (BOOL)mergeData:(NSData *)data forKey:(NSData *)aKey error:(NSError * __autoreleasing *)error +- (BOOL)mergeData:(NSData *)anObject forKey:(NSData *)aKey error:(NSError * __autoreleasing *)error { - return [self mergeData:data forKey:aKey writeOptions:nil error:error]; + return [self mergeData:anObject forKey:aKey writeOptions:nil error:error]; } -- (BOOL)mergeData:(NSData *)data +- (BOOL)mergeData:(NSData *)anObject forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock error:(NSError * __autoreleasing *)error @@ -480,7 +404,7 @@ - (BOOL)mergeData:(NSData *)data rocksdb::Status status = _db->Merge(_writeOptions.options, _columnFamily, SliceFromData(aKey), - SliceFromData(data)); + SliceFromData(anObject)); if (!status.ok()) { NSError *temp = [RocksDBError errorWithRocksStatus:status]; @@ -495,31 +419,6 @@ - (BOOL)mergeData:(NSData *)data #pragma mark - Read Operations -- (id)objectForKey:(id)aKey error:(NSError * __autoreleasing *)error -{ - return [self objectForKey:aKey readOptions:nil error:error]; -} - -- (id)objectForKey:(id)aKey - readOptions:(void (^)(RocksDBReadOptions *readOptions))readOptionsBlock - error:(NSError * __autoreleasing *)error -{ - NSError *locError = nil; - NSData *keyData = EncodeKey(aKey, (RocksDBEncodingOptions *)_options, &locError); - if (locError) { - if (error && *error == nil) { - *error = locError; - } - return nil; - } - - NSData *data = [self dataForKey:keyData - readOptions:readOptionsBlock - error:error]; - - return DecodeValueData(aKey, data, (RocksDBEncodingOptions *)_options, error); -} - - (NSData *)dataForKey:(NSData *)aKey error:(NSError * __autoreleasing *)error { return [self dataForKey:aKey readOptions:nil error:error]; @@ -552,29 +451,6 @@ - (NSData *)dataForKey:(NSData *)aKey #pragma mark - Delete Operations -- (BOOL)deleteObjectForKey:(id)aKey error:(NSError * __autoreleasing *)error -{ - return [self deleteObjectForKey:aKey writeOptions:nil error:error]; -} - -- (BOOL)deleteObjectForKey:(id)aKey - writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptionsBlock - error:(NSError * __autoreleasing *)error -{ - NSError *locError = nil; - NSData *keyData = EncodeKey(aKey, (RocksDBEncodingOptions *)_options, &locError); - if (locError) { - if (error && *error == nil) { - *error = locError; - } - return NO; - } - - return [self deleteDataForKey:keyData - writeOptions:writeOptionsBlock - error:error]; -} - - (BOOL)deleteDataForKey:(NSData *)aKey error:(NSError * __autoreleasing *)error { return [self deleteDataForKey:aKey writeOptions:nil error:error]; @@ -608,8 +484,7 @@ - (BOOL)deleteDataForKey:(NSData *)aKey - (RocksDBWriteBatch *)writeBatch { - return [[RocksDBWriteBatch alloc] initWithColumnFamily:_columnFamily - andEncodingOptions:(RocksDBEncodingOptions *)_options]; + return [[RocksDBWriteBatch alloc] initWithColumnFamily:_columnFamily]; } - (BOOL)performWriteBatch:(void (^)(RocksDBWriteBatch *batch, RocksDBWriteOptions *options))batchBlock @@ -662,8 +537,7 @@ - (RocksDBIndexedWriteBatch *)indexedWriteBatch { return [[RocksDBIndexedWriteBatch alloc] initWithDBInstance:_db columnFamily:_columnFamily - readOptions:_readOptions - andEncodingOptions:(RocksDBEncodingOptions *)_options]; + readOptions:_readOptions]; } - (BOOL)performIndexedWriteBatch:(void (^)(RocksDBIndexedWriteBatch *batch, RocksDBWriteOptions *options))batchBlock @@ -706,7 +580,7 @@ - (RocksDBIterator *)iteratorWithReadOptions:(void (^)(RocksDBReadOptions *readO rocksdb::Iterator *iterator = _db->NewIterator(readOptions.options, _columnFamily); - return [[RocksDBIterator alloc] initWithDBIterator:iterator andEncodingOptions:(RocksDBEncodingOptions *)_options]; + return [[RocksDBIterator alloc] initWithDBIterator:iterator]; } #pragma mark - Snapshot @@ -742,8 +616,8 @@ - (BOOL)compactRange:(RocksDBKeyRange *)range optionsBlock(rangeOptions); } - rocksdb::Slice startSlice = SliceFromKey(range.start, (RocksDBEncodingOptions *)_options, nil); - rocksdb::Slice endSlice = SliceFromKey(range.end, (RocksDBEncodingOptions *)_options, nil); + rocksdb::Slice startSlice = SliceFromData(range.start); + rocksdb::Slice endSlice = SliceFromData(range.end); rocksdb::Status status = _db->CompactRange(rangeOptions.options, _columnFamily, &startSlice, &endSlice); diff --git a/Code/RocksDBBackupEngine.h b/Code/RocksDBBackupEngine.h index 5891d23..55f057d 100644 --- a/Code/RocksDBBackupEngine.h +++ b/Code/RocksDBBackupEngine.h @@ -10,6 +10,8 @@ #import "RocksDB.h" +@class RocksDBBackupInfo; + NS_ASSUME_NONNULL_BEGIN /** @@ -81,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBBackupInfo */ -- (NSArray *)backupInfo; +- (NSArray *)backupInfo; /** @brief Closes this Backup Engine instance. diff --git a/Code/RocksDBBlockBasedTableOptions.h b/Code/RocksDBBlockBasedTableOptions.h index ee2d645..cc85b72 100644 --- a/Code/RocksDBBlockBasedTableOptions.h +++ b/Code/RocksDBBlockBasedTableOptions.h @@ -10,6 +10,8 @@ #import "RocksDBCache.h" #import "RocksDBFilterPolicy.h" +NS_ASSUME_NONNULL_BEGIN + typedef NS_ENUM(char, BlockBasedTableIndexType) { @@ -81,7 +83,7 @@ typedef NS_ENUM(char, BlockBasedTableChecksumType) { @see RocksDBCache */ -@property (nonatomic, strong) RocksDBCache *blockCache; +@property (nonatomic, strong, nullable) RocksDBCache *blockCache; /** @brief @@ -89,7 +91,7 @@ typedef NS_ENUM(char, BlockBasedTableChecksumType) { @see RocksDBCache */ -@property (nonatomic, strong) RocksDBCache *blockCacheCompressed; +@property (nonatomic, strong, nullable) RocksDBCache *blockCacheCompressed; /** @brief @@ -123,7 +125,7 @@ typedef NS_ENUM(char, BlockBasedTableChecksumType) { @see RocksDBFilterPolicy */ -@property (nonatomic, strong) RocksDBFilterPolicy *filterPolicy; +@property (nonatomic, strong, nullable) RocksDBFilterPolicy *filterPolicy; /** @brief @@ -133,3 +135,5 @@ typedef NS_ENUM(char, BlockBasedTableChecksumType) { @property (nonatomic, assign) BOOL wholeKeyFiltering; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBCache.h b/Code/RocksDBCache.h index a6804d4..4bc7b17 100644 --- a/Code/RocksDBCache.h +++ b/Code/RocksDBCache.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** RocksDB cache. */ @@ -34,3 +36,5 @@ + (instancetype)LRUCacheWithCapacity:(size_t)capacity numShardsBits:(int)numShardBits; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBColumnFamily.h b/Code/RocksDBColumnFamily.h index f7a8fdd..56a5c82 100644 --- a/Code/RocksDBColumnFamily.h +++ b/Code/RocksDBColumnFamily.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN andDatabaseOptions:(nullable void (^)(RocksDBDatabaseOptions *options))options __attribute__((unavailable("Create column family via a RocksDB instance"))); #endif -+ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path __attribute__((unavailable("Use the superclass RocksDB instead"))); ++ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path __attribute__((unavailable("Use the superclass RocksDB instead"))); - (RocksDBColumnFamily *)createColumnFamilyWithName:(NSString *)name andOptions:(nullable void (^)(RocksDBColumnFamilyOptions *options))optionsBlock __attribute__((unavailable("Use the superclass RocksDB instead"))); diff --git a/Code/RocksDBColumnFamily.mm b/Code/RocksDBColumnFamily.mm index c5a3560..fb32606 100644 --- a/Code/RocksDBColumnFamily.mm +++ b/Code/RocksDBColumnFamily.mm @@ -22,7 +22,7 @@ - (instancetype)initWithDBInstance:(rocksdb::DB *)db self.db = db; self.columnFamily = columnFamily; self.options = options; - [self setDefaultReadOptions:nil andWriteOptions:nil]; + [self setDefaultReadOptions:nil writeOptions:nil]; } return self; } diff --git a/Code/RocksDBColumnFamilyMetadata.h b/Code/RocksDBColumnFamilyMetadata.h index cc51ab3..9d7b161 100644 --- a/Code/RocksDBColumnFamilyMetadata.h +++ b/Code/RocksDBColumnFamilyMetadata.h @@ -10,6 +10,10 @@ NS_ASSUME_NONNULL_BEGIN +@class RocksDBColumnFamilyMetaData; +@class RocksDBLevelFileMetaData; +@class RocksDBSstFileMetaData; + /** The metadata that describes a Column Family. */ @@ -33,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN /** @brief The metadata of all levels in this Column Family. */ -@property (nonatomic, strong, readonly) NSArray *levels; +@property (nonatomic, strong, readonly) NSArray *levels; @end @@ -55,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN /** @brief The metadata of all sst files in this level. */ -@property (nonatomic, strong, readonly) NSArray *files; +@property (nonatomic, strong, readonly) NSArray *files; @end diff --git a/Code/RocksDBColumnFamilyOptions.h b/Code/RocksDBColumnFamilyOptions.h index 6fadca2..9599bd1 100644 --- a/Code/RocksDBColumnFamilyOptions.h +++ b/Code/RocksDBColumnFamilyOptions.h @@ -7,12 +7,14 @@ // #import -#import "RocksDBMemTableRepFactory.h" -#import "RocksDBTableFactory.h" -#import "RocksDBComparator.h" -#import "RocksDBMergeOperator.h" -#import "RocksDBPrefixExtractor.h" -#import "RocksDBTypes.h" + +@class RocksDBMemTableRepFactory; +@class RocksDBTableFactory; +@class RocksDBComparator; +@class RocksDBMergeOperator; +@class RocksDBPrefixExtractor; + +NS_ASSUME_NONNULL_BEGIN /** The DB compression type. */ typedef NS_ENUM(char, RocksDBCompressionType) @@ -32,7 +34,7 @@ typedef NS_ENUM(char, RocksDBCompressionType) @see RocksDBComparator */ -@property (nonatomic, strong) RocksDBComparator *comparator; +@property (nonatomic, strong, nullable) RocksDBComparator *comparator; /** @brief The client must provide a merge operator if Merge operation needs to be accessed. @@ -44,7 +46,7 @@ typedef NS_ENUM(char, RocksDBCompressionType) @see RocksDBMergeOperator */ -@property (nonatomic, strong) RocksDBMergeOperator *mergeOperator; +@property (nonatomic, strong, nullable) RocksDBMergeOperator *mergeOperator; /** @brief Amount of data to build up in memory (backed by an unsorted log on disk) before converting to a sorted on-disk file. @@ -73,7 +75,7 @@ typedef NS_ENUM(char, RocksDBCompressionType) @see RocksDBPrefixExtractor */ -@property (nonatomic, strong) RocksDBPrefixExtractor *prefixExtractor; +@property (nonatomic, strong, nullable) RocksDBPrefixExtractor *prefixExtractor; /** @brief Number of levels for this DB. */ @property (nonatomic, assign) int numLevels; @@ -89,10 +91,6 @@ typedef NS_ENUM(char, RocksDBCompressionType) /** @brief Maximum number of level-0 files. */ @property (nonatomic, assign) int level0StopWritesTrigger; -/** @brief Maximum level to which a new compacted memtable is pushed if it - does not create overlap. */ -@property (nonatomic, assign) int maxMemCompactionLevel; - /** @brief Target file size for compaction. Default: 2MB */ @@ -166,7 +164,7 @@ typedef NS_ENUM(char, RocksDBCompressionType) @see RocksDBMemTableRepFactory */ -@property (nonatomic, strong) RocksDBMemTableRepFactory *memTableRepFactory; +@property (nonatomic, strong, nullable) RocksDBMemTableRepFactory *memTableRepFactory; /** @brief This is a factory that provides TableFactory objects. Default: A block-based table factory that provides a default @@ -175,10 +173,10 @@ typedef NS_ENUM(char, RocksDBCompressionType) @see RocksDBTableFactory */ -@property (nonatomic, strong) RocksDBTableFactory *tableFacotry; +@property (nonatomic, strong, nullable) RocksDBTableFactory *tableFacotry; /** @brief If prefixExtractor is set and bloom_bits is not 0, create prefix bloom - for memtable + for memtable. @see RocksDBPrefixExtractor */ @@ -208,39 +206,4 @@ typedef NS_ENUM(char, RocksDBCompressionType) @end -/** - Options to define how arbitrary objects (keys & values) should be converted to - NSData and vise versa. - */ -@interface RocksDBColumnFamilyOptions (Encoding) - -/** @brief - A block to convert `id` keys to NSData objects. - */ -@property (nonatomic, copy) NSData * (^ keyEncoder)(id key); - -/** @brief - A block to convert NSData objects to the corresponding `id` key. - */ -@property (nonatomic, copy) id (^ keyDecoder)(NSData *data); - -/** @brief - A block to convert `id` values to NSData objects. The block takes two - parameters, the key-value pair to allow multiplexing. - */ -@property (nonatomic, copy) NSData * (^ valueEncoder)(id key, id value); - -/** @brief A block to convert NSData objects to the corresponding value. */ -@property (nonatomic, copy) id (^ valueDecoder)(id key, NSData *data); - -/** @brief Use a predefined type for the keys. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType keyType; - -/** @brief Use a predefined type for the values. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType valueType; - -@end +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBColumnFamilyOptions.mm b/Code/RocksDBColumnFamilyOptions.mm index 8f9f3d9..eb9115b 100644 --- a/Code/RocksDBColumnFamilyOptions.mm +++ b/Code/RocksDBColumnFamilyOptions.mm @@ -7,7 +7,12 @@ // #import "RocksDBColumnFamilyOptions.h" -#import "RocksDBEncodingOptions.h" + +#import "RocksDBMemTableRepFactory.h" +#import "RocksDBTableFactory.h" +#import "RocksDBComparator.h" +#import "RocksDBMergeOperator.h" +#import "RocksDBPrefixExtractor.h" #import #import @@ -19,17 +24,14 @@ @class RocksDBOptions; @interface RocksDBComparator () -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, assign) const rocksdb::Comparator *comparator; @end @interface RocksDBMergeOperator () -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, assign) rocksdb::MergeOperator *mergeOperator; @end @interface RocksDBPrefixExtractor () -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, assign) const rocksdb::SliceTransform *sliceTransform; @end @@ -44,7 +46,6 @@ @interface RocksDBTableFactory () @interface RocksDBColumnFamilyOptions () { rocksdb::ColumnFamilyOptions _options; - RocksDBEncodingOptions *_encodingOptions; RocksDBComparator *_comparatorWrapper; RocksDBMergeOperator *_mergeOperatorWrapper; @@ -65,29 +66,16 @@ - (instancetype)init { self = [super init]; if (self) { - _encodingOptions = [RocksDBEncodingOptions new]; _options = rocksdb::ColumnFamilyOptions(); } return self; } -#pragma mark - Encoding Options - --(id) forwardingTargetForSelector:(SEL)aSelector -{ - if ([_encodingOptions respondsToSelector:aSelector]) { - return _encodingOptions; - } - - return nil; -} - #pragma mark - Column Family Options - (void)setComparator:(RocksDBComparator *)comparator { _comparatorWrapper = comparator; - _comparatorWrapper.encodingOptions = _encodingOptions; _options.comparator = _comparatorWrapper.comparator; } @@ -99,7 +87,6 @@ - (RocksDBComparator *)comparator - (void)setMergeOperator:(RocksDBMergeOperator *)mergeOperator { _mergeOperatorWrapper = mergeOperator; - _mergeOperatorWrapper.encodingOptions = _encodingOptions; _options.merge_operator.reset(_mergeOperatorWrapper.mergeOperator); } @@ -151,7 +138,6 @@ - (void)setCompressionType:(RocksDBCompressionType)compressionType - (void)setPrefixExtractor:(RocksDBPrefixExtractor *)prefixExtractor { _prefixExtractorWrapper = prefixExtractor; - _prefixExtractorWrapper.encodingOptions = _encodingOptions; _options.prefix_extractor.reset(_prefixExtractorWrapper.sliceTransform); } @@ -195,16 +181,6 @@ - (int)level0StopWritesTrigger return _options.level0_stop_writes_trigger; } -- (void)setMaxMemCompactionLevel:(int)maxMemCompactionLevel -{ - _options.max_mem_compaction_level = maxMemCompactionLevel; -} - -- (int)maxMemCompactionLevel -{ - return _options.max_mem_compaction_level; -} - - (void)setTargetFileSizeBase:(uint64_t)targetFileSizeBase { _options.target_file_size_base = targetFileSizeBase; diff --git a/Code/RocksDBComparator.h b/Code/RocksDBComparator.h index 6f1ccc4..ce7cbc2 100644 --- a/Code/RocksDBComparator.h +++ b/Code/RocksDBComparator.h @@ -26,12 +26,6 @@ typedef NS_ENUM(NSUInteger, RocksDBComparatorType) /** @brief Orders NSString keys in descending order via the compare selector. */ RocksDBComparatorStringCompareDescending, - - /** @brief Orders NSNumber keys in ascending order via the compare selector.*/ - RocksDBComparatorNumberAscending, - - /** @brief Orders NSNumber keys in descending order via the compare selector. */ - RocksDBComparatorNumberDescending }; /** @@ -57,7 +51,8 @@ typedef NS_ENUM(NSUInteger, RocksDBComparatorType) @param block The comparator block to apply on the keys in order to specify their order. @return a newly-initialized instance of a keys comparator. */ -- (instancetype)initWithName:(NSString *)name andBlock:(int (^)(id key1, id key2))block; +- (instancetype)initWithName:(NSString *)name + andBlock:(int (^)(NSData *key1, NSData *key2))block; @end diff --git a/Code/RocksDBComparator.mm b/Code/RocksDBComparator.mm index c462325..169404f 100644 --- a/Code/RocksDBComparator.mm +++ b/Code/RocksDBComparator.mm @@ -7,7 +7,6 @@ // #import "RocksDBComparator.h" -#import "RocksDBEncodingOptions.h" #import "RocksDBSlice.h" #import "RocksDBCallbackComparator.h" @@ -16,18 +15,15 @@ @interface RocksDBComparator () { - RocksDBEncodingOptions *_encodingOptions; NSString *_name; - int (^_comparatorBlock)(id data1, id data2); + int (^_comparatorBlock)(NSData *key1, NSData *key2); const rocksdb::Comparator *_comparator; } -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, strong) NSString *name; @property (nonatomic, assign) const rocksdb::Comparator *comparator; @end @implementation RocksDBComparator -@synthesize encodingOptions = _encodingOptions; @synthesize name = _name; @synthesize comparator = _comparator; @@ -43,30 +39,25 @@ + (instancetype)comaparatorWithType:(RocksDBComparatorType)type return [[self alloc] initWithNativeComparator:rocksdb::ReverseBytewiseComparator()]; case RocksDBComparatorStringCompareAscending: - return [[self alloc] initWithName:@"objectiverocks.string.compare.asc" andBlock:^int(id key1, id key2) { - return [key1 compare:key2]; + return [[self alloc] initWithName:@"objectiverocks.string.compare.asc" andBlock:^int(NSData *key1, NSData *key2) { + NSString *str1 = [[NSString alloc] initWithData:key1 encoding:NSUTF8StringEncoding]; + NSString *str2 = [[NSString alloc] initWithData:key2 encoding:NSUTF8StringEncoding]; + return [str1 compare:str2]; }]; case RocksDBComparatorStringCompareDescending: - return [[self alloc] initWithName:@"objectiverocks.string.compare.desc" andBlock:^int(id key1, id key2) { - return -1 * [key1 compare:key2]; - }]; - - case RocksDBComparatorNumberAscending: - return [[self alloc] initWithName:@"objectiverocks.number.asc" andBlock:^int(id key1, id key2) { - return [key1 compare:key2]; - }]; - - case RocksDBComparatorNumberDescending: - return [[self alloc] initWithName:@"objectiverocks.number.desc" andBlock:^int(id key1, id key2) { - return [key1 compare:key2] * -1; + return [[self alloc] initWithName:@"objectiverocks.string.compare.desc" andBlock:^int(NSData *key1, NSData *key2) { + NSString *str1 = [[NSString alloc] initWithData:key1 encoding:NSUTF8StringEncoding]; + NSString *str2 = [[NSString alloc] initWithData:key2 encoding:NSUTF8StringEncoding]; + return -1 * [str1 compare:str2]; }]; } } #pragma mark - Lifecycle -- (instancetype)initWithName:(NSString *)name andBlock:(int (^)(id key1, id key2))block +- (instancetype)initWithName:(NSString *)name + andBlock:(int (^)(NSData *key1, NSData *key2))block { self = [super init]; if (self) { @@ -91,8 +82,8 @@ - (instancetype)initWithNativeComparator:(const rocksdb::Comparator *)comparator - (int)compare:(const rocksdb::Slice &)slice1 with:(const rocksdb::Slice &)slice2 { - id key1 = DecodeKeySlice(slice1, _encodingOptions, nil); - id key2 = DecodeKeySlice(slice2, _encodingOptions, nil); + NSData *key1 = DataFromSlice(slice1); + NSData *key2 = DataFromSlice(slice2); return _comparatorBlock ? _comparatorBlock(key1, key2) : 0; } diff --git a/Code/RocksDBCuckooTableOptions.h b/Code/RocksDBCuckooTableOptions.h index f227306..ce0f2ff 100644 --- a/Code/RocksDBCuckooTableOptions.h +++ b/Code/RocksDBCuckooTableOptions.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface RocksDBCuckooTableOptions : NSObject /** @@ -56,3 +58,5 @@ @property (nonatomic, assign) BOOL useModuleHash; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBDatabaseOptions.h b/Code/RocksDBDatabaseOptions.h index cb07489..aeaa4e8 100644 --- a/Code/RocksDBDatabaseOptions.h +++ b/Code/RocksDBDatabaseOptions.h @@ -7,8 +7,11 @@ // #import -#import "RocksDBEnv.h" -#import "RocksDBStatistics.h" + +@class RocksDBEnv; +@class RocksDBStatistics; + +NS_ASSUME_NONNULL_BEGIN /** @brief The DB log level. */ typedef NS_ENUM(unsigned char, RocksDBLogLevel) @@ -63,7 +66,7 @@ typedef NS_ENUM(unsigned char, RocksDBLogLevel) @see RocksDBStatistics */ -@property (nonatomic, strong) RocksDBStatistics *statistics; +@property (nonatomic, strong, nullable) RocksDBStatistics *statistics; /** @brief If true, then the contents of manifest and data files are not synced to stable storage. @@ -93,3 +96,5 @@ typedef NS_ENUM(unsigned char, RocksDBLogLevel) @property (nonatomic, assign) uint64_t bytesPerSync; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBDatabaseOptions.mm b/Code/RocksDBDatabaseOptions.mm index b7d28a7..9a6dd0e 100644 --- a/Code/RocksDBDatabaseOptions.mm +++ b/Code/RocksDBDatabaseOptions.mm @@ -8,6 +8,9 @@ #import "RocksDBDatabaseOptions.h" +#import "RocksDBEnv.h" +#import "RocksDBStatistics.h" + #import @interface RocksDBStatistics () diff --git a/Code/RocksDBEncodingOptions.h b/Code/RocksDBEncodingOptions.h deleted file mode 100644 index d4c12fd..0000000 --- a/Code/RocksDBEncodingOptions.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// RocksDBEncodingOptions.h -// ObjectiveRocks -// -// Created by Iska on 29/12/14. -// Copyright (c) 2014 BrainCookie. All rights reserved. -// - -#import -#import "RocksDBTypes.h" - -/** - Options to define how arbitrary objects (keys & values) should be converted to - NSData and vise versa. - */ -@interface RocksDBEncodingOptions : NSObject - -/** @brief - A block to convert `id` keys to NSData objects. - */ -@property (nonatomic, copy) NSData * (^ keyEncoder)(id key); - -/** @brief - A block to convert NSData objects to the corresponding `id` key. - */ -@property (nonatomic, copy) id (^ keyDecoder)(NSData *data); - -/** @brief - A block to convert `id` values to NSData objects. The block takes two - parameters, the key-value pair to allow multiplexing. - */ -@property (nonatomic, copy) NSData * (^ valueEncoder)(id key, id value); - -/** @brief A block to convert NSData objects to the corresponding value. */ -@property (nonatomic, copy) id (^ valueDecoder)(id key, NSData *data); - -/** @brief Use a predefined type for the keys. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType keyType; - -/** @brief Use a predefined type for the values. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType valueType; - -@end diff --git a/Code/RocksDBEncodingOptions.mm b/Code/RocksDBEncodingOptions.mm deleted file mode 100644 index 541a51a..0000000 --- a/Code/RocksDBEncodingOptions.mm +++ /dev/null @@ -1,27 +0,0 @@ -// -// RocksDBEncodingOptions.m -// ObjectiveRocks -// -// Created by Iska on 29/12/14. -// Copyright (c) 2014 BrainCookie. All rights reserved. -// - -#import "RocksDBEncodingOptions.h" - -@implementation RocksDBEncodingOptions - -- (void)setKeyType:(RocksDBType)type -{ - self.keyEncoder = [RocksDBTypes keyEncoderForType:type]; - self.keyDecoder = [RocksDBTypes keyDecoderForType:type]; - _keyType = type; -} - -- (void)setValueType:(RocksDBType)type -{ - self.valueEncoder = [RocksDBTypes valueEncoderForType:type]; - self.valueDecoder = [RocksDBTypes valueDecoderForType:type]; - _valueType = type; -} - -@end diff --git a/Code/RocksDBEnv.h b/Code/RocksDBEnv.h index f1ce38d..dfcfe76 100644 --- a/Code/RocksDBEnv.h +++ b/Code/RocksDBEnv.h @@ -8,6 +8,10 @@ #import +#if ROCKSDB_USING_THREAD_STATUS +#import "RocksDBThreadStatus.h" +#endif + NS_ASSUME_NONNULL_BEGIN /** @@ -39,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN @warning This method is not available in RocksDB Lite. */ -- (NSArray *)threadList; +- (NSArray *)threadList; #endif @end diff --git a/Code/RocksDBFilterPolicy.h b/Code/RocksDBFilterPolicy.h index b09a2b7..0ed86e7 100644 --- a/Code/RocksDBFilterPolicy.h +++ b/Code/RocksDBFilterPolicy.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** Defines a filter policy for keys. */ @@ -31,3 +33,5 @@ + (instancetype)bloomFilterPolicyWithBitsPerKey:(int)bitsPerKey useBlockBasedBuilder:(BOOL)useBlockBasedBuilder; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBIndexedWriteBatch+Private.h b/Code/RocksDBIndexedWriteBatch+Private.h index a5ab8e6..d70ed4e 100644 --- a/Code/RocksDBIndexedWriteBatch+Private.h +++ b/Code/RocksDBIndexedWriteBatch+Private.h @@ -12,8 +12,6 @@ namespace rocksdb { class WriteBatchBase; } -@class RocksDBEncodingOptions; - /** This category is intended to hide all C++ types from the public interface in order to maintain a pure Objective-C API for Swift compatibility. @@ -26,14 +24,11 @@ namespace rocksdb { @param db The rocksdb::DB instance. @param columnFamily The rocks::ColumnFamilyHandle instance. - @param options The Encoding options. + @param readOptions The read options. @return a newly-initialized instance of `RocksDBIndexedWriteBatch`. - - @see RocksDBEncodingOptions */ - (instancetype)initWithDBInstance:(rocksdb::DB *)db columnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily - readOptions:(RocksDBReadOptions *)readOptions - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions; + readOptions:(RocksDBReadOptions *)readOptions; @end diff --git a/Code/RocksDBIndexedWriteBatch.h b/Code/RocksDBIndexedWriteBatch.h index aa88c42..d1801db 100644 --- a/Code/RocksDBIndexedWriteBatch.h +++ b/Code/RocksDBIndexedWriteBatch.h @@ -35,9 +35,9 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBColumnFamily */ -- (nullable id)objectForKey:(id)aKey - inColumnFamily:(RocksDBColumnFamily *)columnFamily - error:(NSError * _Nullable *)error; +- (nullable NSData *)dataForKey:(NSData *)aKey + inColumnFamily:(RocksDBColumnFamily *)columnFamily + error:(NSError * _Nullable *)error; /** Returns the object for the given key. @@ -60,10 +60,10 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBColumnFamily @see RocksDBReadOptions */ -- (nullable id)objectForKeyIncludingDatabase:(id)aKey - inColumnFamily:(RocksDBColumnFamily *)columnFamily - readOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions - error:(NSError * _Nullable *)error; +- (nullable NSData *)dataForKeyIncludingDatabase:(NSData *)aKey + inColumnFamily:(RocksDBColumnFamily *)columnFamily + readOptions:(nullable void (^)(RocksDBReadOptions *readOptions))readOptions + error:(NSError * _Nullable *)error; /** Creates and returns an iterator over this indexed write batch. diff --git a/Code/RocksDBIndexedWriteBatch.mm b/Code/RocksDBIndexedWriteBatch.mm index e7178f4..5d5429a 100644 --- a/Code/RocksDBIndexedWriteBatch.mm +++ b/Code/RocksDBIndexedWriteBatch.mm @@ -14,6 +14,7 @@ #import "RocksDBWriteBatchIterator+Private.h" #import "RocksDBColumnFamily+Private.h" +#import "RocksDBError.h" #import "RocksDBSlice.h" #import @@ -35,11 +36,9 @@ @implementation RocksDBIndexedWriteBatch - (instancetype)initWithDBInstance:(rocksdb::DB *)db columnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily readOptions:(RocksDBReadOptions *)readOptions - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions { self = [super initWithNativeWriteBatch:new rocksdb::WriteBatchWithIndex() - columnFamily:columnFamily - andEncodingOptions:encodingOptions]; + columnFamily:columnFamily]; if (self) { _db = db; _readOptions = [readOptions copy]; @@ -50,16 +49,16 @@ - (instancetype)initWithDBInstance:(rocksdb::DB *)db #pragma mark - Queries -- (id)objectForKey:(id)aKey - inColumnFamily:(RocksDBColumnFamily *)columnFamily - error:(NSError * __autoreleasing *)error +- (NSData *)dataForKey:(NSData *)aKey + inColumnFamily:(RocksDBColumnFamily *)columnFamily + error:(NSError * __autoreleasing *)error { rocksdb::ColumnFamilyHandle *columnFamilyHandle = columnFamily != nil ? columnFamily.columnFamily : nullptr; std::string value; rocksdb::Status status = _writeBatchWithIndex->GetFromBatch(columnFamilyHandle, _db->GetDBOptions(), - SliceFromKey(aKey, self.encodingOptions, nil), + SliceFromData(aKey), &value); if (!status.ok()) { NSError *temp = [RocksDBError errorWithRocksStatus:status]; @@ -69,13 +68,13 @@ - (id)objectForKey:(id)aKey return nil; } - return DecodeValueSlice(aKey, rocksdb::Slice(value), self.encodingOptions, error); + return DataFromSlice(rocksdb::Slice(value)); } -- (id)objectForKeyIncludingDatabase:(id)aKey - inColumnFamily:(RocksDBColumnFamily *)columnFamily - readOptions:(void (^)(RocksDBReadOptions *readOptions))readOptionsBlock - error:(NSError * __autoreleasing *)error +- (NSData *)dataForKeyIncludingDatabase:(NSData *)aKey + inColumnFamily:(RocksDBColumnFamily *)columnFamily + readOptions:(void (^)(RocksDBReadOptions *readOptions))readOptionsBlock + error:(NSError * __autoreleasing *)error { RocksDBReadOptions *readOptions = [_readOptions copy]; if (readOptionsBlock) { @@ -88,7 +87,7 @@ - (id)objectForKeyIncludingDatabase:(id)aKey rocksdb::Status status = _writeBatchWithIndex->GetFromBatchAndDB(_db, readOptions.options, columnFamilyHandle, - SliceFromKey(aKey, self.encodingOptions, nil), + SliceFromData(aKey), &value); if (!status.ok()) { NSError *temp = [RocksDBError errorWithRocksStatus:status]; @@ -98,7 +97,7 @@ - (id)objectForKeyIncludingDatabase:(id)aKey return nil; } - return DecodeValueSlice(aKey, rocksdb::Slice(value), self.encodingOptions, error); + return DataFromSlice(rocksdb::Slice(value)); } #pragma mark - Iterator @@ -106,8 +105,7 @@ - (id)objectForKeyIncludingDatabase:(id)aKey - (RocksDBWriteBatchIterator *)iterator { rocksdb::WBWIIterator *nativeIterator = _writeBatchWithIndex->NewIterator(self.columnFamily); - return [[RocksDBWriteBatchIterator alloc] initWithWriteBatchIterator:nativeIterator - andEncodingOptions:self.encodingOptions]; + return [[RocksDBWriteBatchIterator alloc] initWithWriteBatchIterator:nativeIterator]; } @end diff --git a/Code/RocksDBIterator+Private.h b/Code/RocksDBIterator+Private.h index d9cf4d9..937ab88 100644 --- a/Code/RocksDBIterator+Private.h +++ b/Code/RocksDBIterator+Private.h @@ -23,12 +23,8 @@ namespace rocksdb { rocksdb::Iterator instance. @param iterator The rocks::Iterator instance. - @param options The Encoding options. @return a newly-initialized instance of `RocksDBIterator`. - - @see RocksDBEncodingOptions */ -- (instancetype)initWithDBIterator:(rocksdb::Iterator *)iterator - andEncodingOptions:(RocksDBEncodingOptions *)options; +- (instancetype)initWithDBIterator:(rocksdb::Iterator *)iterator; @end diff --git a/Code/RocksDBIterator.h b/Code/RocksDBIterator.h index 76bb1fb..a2617ef 100644 --- a/Code/RocksDBIterator.h +++ b/Code/RocksDBIterator.h @@ -7,7 +7,6 @@ // #import -#import "RocksDBEncodingOptions.h" #import "RocksDBRange.h" NS_ASSUME_NONNULL_BEGIN @@ -46,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN @param aKey The key to position the tartaritartor at. */ -- (void)seekToKey:(id)aKey; +- (void)seekToKey:(NSData *)aKey; /** Moves to the next entry in the source. After this call, `isValid` is @@ -66,7 +65,7 @@ NS_ASSUME_NONNULL_BEGIN @return The key at the current position. */ -- (id)key; +- (NSData *)key; /** Returns the value for the current entry. The underlying storage for the returned @@ -74,14 +73,14 @@ NS_ASSUME_NONNULL_BEGIN @return The value for the key at the current position. */ -- (id)value; +- (NSData *)value; /** Executes a given block for each key in the iterator. @param block The block to apply to elements. */ -- (void)enumerateKeysUsingBlock:(void (^)(id key, BOOL *stop))block; +- (void)enumerateKeysUsingBlock:(void (^)(NSData *key, BOOL *stop))block; /** Executes a given block for each key in the iterator in reverse order. @@ -89,7 +88,8 @@ NS_ASSUME_NONNULL_BEGIN @param reverse BOOL indicating whether to enumerate in the reverse order. @param block The block to apply to elements. */ -- (void)enumerateKeysInReverse:(BOOL)reverse usingBlock:(void (^)(id key, BOOL *stop))block; +- (void)enumerateKeysInReverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, BOOL *stop))block; /** Executes a given block for each key in the iterator in the given key range. @@ -100,14 +100,16 @@ NS_ASSUME_NONNULL_BEGIN @see RocksDBIteratorKeyRange */ -- (void)enumerateKeysInRange:(RocksDBKeyRange *)range reverse:(BOOL)reverse usingBlock:(void (^)(id key, BOOL *stop))block; +- (void)enumerateKeysInRange:(RocksDBKeyRange *)range + reverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, BOOL *stop))block; /** Executes a given block for each key-value pair in the iterator. @param block The block to apply to elements. */ -- (void)enumerateKeysAndValuesUsingBlock:(void (^)(id key, id value, BOOL *stop))block; +- (void)enumerateKeysAndValuesUsingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block; /** Executes a given block for each key-value pair in the iterator in reverse order. @@ -115,7 +117,8 @@ NS_ASSUME_NONNULL_BEGIN @param reverse BOOL indicating whether to enumerate in the reverse order. @param block The block to apply to elements. */ -- (void)enumerateKeysAndValuesInReverse:(BOOL)reverse usingBlock:(void (^)(id key, id value, BOOL *stop))block; +- (void)enumerateKeysAndValuesInReverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block; /** Executes a given block for each key-value pair in the iterator in the given key range. @@ -124,21 +127,25 @@ NS_ASSUME_NONNULL_BEGIN @parame reverse BOOL indicating whether to enumerate in the reverse order. @param block The block to apply to elements. */ -- (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range reverse:(BOOL)reverse usingBlock:(void (^)(id key, id value, BOOL *stop))block; +- (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range + reverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block; /** Executes a given block for each key with the given prefix in the iterator. @param block The block to apply to elements. */ -- (void)enumerateKeysWithPrefix:(id)prefix usingBlock:(void (^)(id key, BOOL *stop))block; +- (void)enumerateKeysWithPrefix:(NSData *)prefix + usingBlock:(void (^)(NSData *key, BOOL *stop))block; /** Executes a given block for each key-value pair with the given prefix in the iterator. @param block The block to apply to elements. */ -- (void)enumerateKeysAndValuesWithPrefix:(id)prefix usingBlock:(void (^)(id key, id value, BOOL *stop))block; +- (void)enumerateKeysAndValuesWithPrefix:(NSData *)prefix + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block; @end diff --git a/Code/RocksDBIterator.mm b/Code/RocksDBIterator.mm index de95690..d1e48d8 100644 --- a/Code/RocksDBIterator.mm +++ b/Code/RocksDBIterator.mm @@ -16,7 +16,6 @@ @interface RocksDBIterator () { rocksdb::Iterator *_iterator; - RocksDBEncodingOptions *_options; } @end @@ -25,12 +24,10 @@ @implementation RocksDBIterator #pragma mark - Lifecycle - (instancetype)initWithDBIterator:(rocksdb::Iterator *)iterator - andEncodingOptions:(RocksDBEncodingOptions *)options { self = [super init]; if (self) { _iterator = iterator; - _options = options; } return self; } @@ -67,10 +64,10 @@ - (void)seekToLast _iterator->SeekToLast(); } -- (void)seekToKey:(id)aKey +- (void)seekToKey:(NSData *)aKey { if (aKey != nil) { - _iterator->Seek(SliceFromKey(aKey, _options, nil)); + _iterator->Seek(SliceFromData(aKey)); } } @@ -84,56 +81,62 @@ - (void)previous _iterator->Prev(); } -- (id)key +- (NSData *)key { rocksdb::Slice keySlice = _iterator->key(); - id key = DecodeKeySlice(keySlice, _options, nil); + NSData *key = DataFromSlice(keySlice); return key; } -- (id)value +- (NSData *)value { rocksdb::Slice valueSlice = _iterator->value(); - id value = DecodeValueSlice(self.key, valueSlice, _options, nil); + NSData *value = DataFromSlice(valueSlice); return value; } #pragma mark - Enumerate Keys -- (void)enumerateKeysUsingBlock:(void (^)(id key, BOOL *stop))block +- (void)enumerateKeysUsingBlock:(void (^)(NSData *key, BOOL *stop))block { - [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:NO usingBlock:^(id key, id value, BOOL *stop) { + [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:NO usingBlock:^(NSData *key, NSData *value, BOOL *stop) { block(key, stop); }]; } -- (void)enumerateKeysInReverse:(BOOL)reverse usingBlock:(void (^)(id key, BOOL *stop))block +- (void)enumerateKeysInReverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, BOOL *stop))block { - [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:reverse usingBlock:^(id key, id value, BOOL *stop) { + [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:reverse usingBlock:^(NSData *key, NSData *value, BOOL *stop) { block(key, stop); }]; } -- (void)enumerateKeysInRange:(RocksDBKeyRange *)range reverse:(BOOL)reverse usingBlock:(void (^)(id key, BOOL *stop))block +- (void)enumerateKeysInRange:(RocksDBKeyRange *)range + reverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, BOOL *stop))block { - [self enumerateKeysAndValuesInRange:range reverse:reverse usingBlock:^(id key, id value, BOOL *stop) { + [self enumerateKeysAndValuesInRange:range reverse:reverse usingBlock:^(NSData *key, NSData *value, BOOL *stop) { block(key, stop); }]; } #pragma mark - Enumerate Keys & Values -- (void)enumerateKeysAndValuesUsingBlock:(void (^)(id key, id value, BOOL *stop))block +- (void)enumerateKeysAndValuesUsingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block { [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:NO usingBlock:block]; } -- (void)enumerateKeysAndValuesInReverse:(BOOL)reverse usingBlock:(void (^)(id key, id value, BOOL *stop))block +- (void)enumerateKeysAndValuesInReverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block { [self enumerateKeysAndValuesInRange:RocksDBOpenRange reverse:reverse usingBlock:block]; } -- (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range reverse:(BOOL)reverse usingBlock:(void (^)(id key, id value, BOOL *stop))block +- (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range + reverse:(BOOL)reverse + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block { BOOL stop = NO; @@ -145,7 +148,7 @@ - (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range reverse:(BOOL)rev rocksdb::Slice limitSlice; if (range.end != nil) { - limitSlice = SliceFromKey(range.end, _options, nil); + limitSlice = SliceFromData(range.end); } BOOL (^ checkLimit)(BOOL, rocksdb::Slice) = ^ BOOL (BOOL reverse, rocksdb::Slice key) { @@ -167,18 +170,18 @@ - (void)enumerateKeysAndValuesInRange:(RocksDBKeyRange *)range reverse:(BOOL)rev #pragma mark - Enumerate Prefix -- (void)enumerateKeysWithPrefix:(id)prefix usingBlock:(void (^)(id key, BOOL *stop))block +- (void)enumerateKeysWithPrefix:(NSData *)prefix usingBlock:(void (^)(NSData *key, BOOL *stop))block { - [self enumerateKeysAndValuesWithPrefix:prefix usingBlock:^(id key, id value, BOOL *stop) { + [self enumerateKeysAndValuesWithPrefix:prefix usingBlock:^(NSData *key, NSData *value, BOOL *stop) { block(key, stop); }]; } -- (void)enumerateKeysAndValuesWithPrefix:(id)prefix usingBlock:(void (^)(id key, id value, BOOL *stop))block +- (void)enumerateKeysAndValuesWithPrefix:(NSData *)prefix + usingBlock:(void (^)(NSData *key, NSData *value, BOOL *stop))block { BOOL stop = NO; - - rocksdb::Slice prefixSlice = SliceFromKey(prefix, _options, nil); + rocksdb::Slice prefixSlice = SliceFromData(prefix); for (_iterator->Seek(prefixSlice); _iterator->Valid(); _iterator->Next()) { if (_iterator->key().starts_with(prefixSlice) == false) continue; diff --git a/Code/RocksDBMemTableRepFactory.h b/Code/RocksDBMemTableRepFactory.h index 21a8327..8fdfe03 100644 --- a/Code/RocksDBMemTableRepFactory.h +++ b/Code/RocksDBMemTableRepFactory.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** A factory for MemTableRep objects */ @@ -55,3 +57,5 @@ #endif @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBMergeOperator.h b/Code/RocksDBMergeOperator.h index 29698fe..f157e95 100644 --- a/Code/RocksDBMergeOperator.h +++ b/Code/RocksDBMergeOperator.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN /** Initializes a new instance of an associative merge operator. - @discussion This Merge Operator can be use for associative data: + This Merge Operator can be used for associative data: * The merge operands are formatted the same as the Put values, AND * It is okay to combine multiple operands into one (as long as they are in the same order) @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @return A newly-initialized instance of the Merge Operator. */ + (instancetype)operatorWithName:(NSString *)name - andBlock:(id (^)(id key, id _Nullable existingValue, id value))block; + andBlock:(NSData * (^)(NSData * key, NSData * _Nullable existingValue, NSData *value))block; /** Initializes a new instance of a generic merge operator. @@ -53,8 +53,8 @@ NS_ASSUME_NONNULL_BEGIN @return A newly-initialized instance of the Merge Operator. */ + (instancetype)operatorWithName:(NSString *)name - partialMergeBlock:(NSString * _Nullable (^)(id key, NSString *leftOperand, NSString *rightOperand))partialMergeBlock - fullMergeBlock:(id _Nullable (^)(id key, id _Nullable existingValue, NSArray *operandList))fullMergeBlock; + partialMergeBlock:(NSData * _Nullable (^)(NSData * key, NSData *leftOperand, NSData *rightOperand))partialMergeBlock + fullMergeBlock:(NSData * _Nullable (^)(NSData * key, NSData * _Nullable existingValue, NSArray *operandList))fullMergeBlock; @end diff --git a/Code/RocksDBMergeOperator.mm b/Code/RocksDBMergeOperator.mm index d670674..559c1e5 100644 --- a/Code/RocksDBMergeOperator.mm +++ b/Code/RocksDBMergeOperator.mm @@ -7,7 +7,6 @@ // #import "RocksDBMergeOperator.h" -#import "RocksDBEncodingOptions.h" #import "RocksDBSlice.h" #import "RocksDBCallbackAssociativeMergeOperator.h" #import "RocksDBCallbackMergeOperator.h" @@ -19,11 +18,9 @@ @interface RocksDBMergeOperator () { - RocksDBEncodingOptions *_encodingOptions; NSString *_name; rocksdb::MergeOperator *_mergeOperator; } -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, copy) NSString *name; @property (nonatomic, assign) rocksdb::MergeOperator *mergeOperator; @end @@ -32,13 +29,13 @@ @interface RocksDBMergeOperator () @interface RocksDBAssociativeMergeOperator : RocksDBMergeOperator { - id (^ _associativeMergeBlock)(id, id existingValue, id value); + NSData * (^ _associativeMergeBlock)(NSData *, NSData *existingValue, NSData *value); } @end @implementation RocksDBAssociativeMergeOperator -- (instancetype)initWithName:(NSString *)name andBlock:(id (^)(id, id, id))block +- (instancetype)initWithName:(NSString *)name andBlock:(NSData * (^)(NSData *, NSData *, NSData *))block { self = [super init]; if (self) { @@ -68,13 +65,12 @@ - (NSData *)mergeForKey:(const rocksdb::Slice &)keySlice withExistingValue:(const rocksdb::Slice *)existingSlice andValue:(const rocksdb::Slice &)valueSlice { - id key = DecodeKeySlice(keySlice, self.encodingOptions, nil); - id previous = (existingSlice == nullptr) ? nil : DecodeValueSlice(key, *existingSlice, self.encodingOptions, nil); - id value = DecodeValueSlice(key, valueSlice, self.encodingOptions, nil); + NSData *key = DataFromSlice(keySlice); + NSData *previous = (existingSlice == nullptr) ? nil : DataFromSlice(*existingSlice); + NSData *value = DataFromSlice(valueSlice); - id mergeResult = _associativeMergeBlock ? _associativeMergeBlock(key, previous, value): nil; - - return EncodeValue(key, mergeResult, self.encodingOptions, nil); + NSData *mergeResult = _associativeMergeBlock ? _associativeMergeBlock(key, previous, value): nil; + return mergeResult; } @end @@ -83,16 +79,16 @@ - (NSData *)mergeForKey:(const rocksdb::Slice &)keySlice @interface RocksDBGenericMergeOperator : RocksDBMergeOperator { - NSString * (^ _partialMergeBlock)(id key, NSString *leftOperand, NSString *rightOperand); - id (^ _fullMergeBlock)(id key, id existingValue, NSArray *operandList); + NSData * (^ _partialMergeBlock)(NSData * key, NSData *leftOperand, NSData *rightOperand); + NSData * (^ _fullMergeBlock)(NSData * key, NSData * existingValue, NSArray *operandList); } @end @implementation RocksDBGenericMergeOperator - (instancetype)initWithName:(NSString *)name - partialMergeBlock:(NSString * (^)(id key, NSString *leftOperand, NSString *rightOperand))partialMergeBlock - fullMergeBlock:(id (^)(id key, id existingValue, NSArray *operandList))fullMergeBlock + partialMergeBlock:(NSData * (^)(NSData *key, NSData *leftOperand, NSData *rightOperand))partialMergeBlock + fullMergeBlock:(NSData * (^)(NSData *key, NSData *existingValue, NSArray *operandList))fullMergeBlock { self = [super init]; if (self) { @@ -126,13 +122,12 @@ - (NSData *)partialMergeForKey:(const rocksdb::Slice &)keySlice withLeftOperand:(const rocksdb::Slice &)leftSlice andRightOperand:(const rocksdb::Slice &)rightSlice { - id key = DecodeKeySlice(keySlice, self.encodingOptions, nil); - id left = DecodeValueSlice(key, leftSlice, self.encodingOptions, nil); - id right = DecodeValueSlice(key, rightSlice, self.encodingOptions, nil); - - NSString * mergeResult = _partialMergeBlock ? _partialMergeBlock(key, left, right): nil; + NSData *key = DataFromSlice(keySlice); + NSData *left = DataFromSlice(leftSlice); + NSData *right = DataFromSlice(rightSlice); - return [mergeResult dataUsingEncoding:NSUTF8StringEncoding]; + NSData *mergeResult = _partialMergeBlock ? _partialMergeBlock(key, left, right): nil; + return mergeResult; } bool trampolineFullMerge(void* instance, @@ -158,21 +153,20 @@ - (NSData *)fullMergeForKey:(const rocksdb::Slice &)keySlice withExistingValue:(const rocksdb::Slice *)existingSlice andOperandList:(const std::deque &)operand_list { - id key = DecodeKeySlice(keySlice, self.encodingOptions, nil); - id previous = (existingSlice == nullptr) ? nil : DecodeValueSlice(key, *existingSlice, self.encodingOptions, nil); + NSData *key = DataFromSlice(keySlice); + NSData *previous = (existingSlice == nullptr) ? nil : DataFromSlice(*existingSlice); NSMutableArray *operands = [NSMutableArray arrayWithCapacity:operand_list.size()]; for (const auto &value : operand_list) { - id decoded = [NSString stringWithCString:value.c_str() encoding:NSUTF8StringEncoding]; - if (decoded != nil) { - [operands addObject:decoded]; + NSData *data = DataFromSlice(rocksdb::Slice(value)); + if (data != nil) { + [operands addObject:data]; } } - id mergeResult = _fullMergeBlock ? _fullMergeBlock(key, previous, operands) : nil; - - return EncodeValue(key, mergeResult, self.encodingOptions, nil);; + NSData *mergeResult = _fullMergeBlock ? _fullMergeBlock(key, previous, operands) : nil; + return mergeResult; } @end @@ -181,17 +175,16 @@ - (NSData *)fullMergeForKey:(const rocksdb::Slice &)keySlice @implementation RocksDBMergeOperator @synthesize name = _name; -@synthesize encodingOptions = _encodingOptions; @synthesize mergeOperator = _mergeOperator; -+ (instancetype)operatorWithName:(NSString *)name andBlock:(id (^)(id, id, id))block ++ (instancetype)operatorWithName:(NSString *)name andBlock:(NSData * (^)(NSData *, NSData *, NSData *))block { return [[RocksDBAssociativeMergeOperator alloc] initWithName:name andBlock:block]; } + (instancetype)operatorWithName:(NSString *)name - partialMergeBlock:(NSString * (^)(id key, NSString *leftOperand, NSString *rightOperand))partialMergeBlock - fullMergeBlock:(id (^)(id key, id existingValue, NSArray *operandList))fullMergeBlock + partialMergeBlock:(NSData * (^)(NSData * key, NSData *leftOperand, NSData *rightOperand))partialMergeBlock + fullMergeBlock:(NSData * (^)(NSData *key, NSData *existingValue, NSArray *operandList))fullMergeBlock { return [[RocksDBGenericMergeOperator alloc] initWithName:name partialMergeBlock:partialMergeBlock fullMergeBlock:fullMergeBlock]; } diff --git a/Code/RocksDBOptions.h b/Code/RocksDBOptions.h index 05cc9a1..791a2be 100644 --- a/Code/RocksDBOptions.h +++ b/Code/RocksDBOptions.h @@ -7,14 +7,14 @@ // #import - #import "RocksDBDatabaseOptions.h" -#import "RocksDBEncodingOptions.h" #import "RocksDBColumnFamilyOptions.h" -#import "RocksDBComparator.h" -#import "RocksDBMergeOperator.h" -#import "RocksDBPrefixExtractor.h" -#import "RocksDBTypes.h" + +@class RocksDBComparator; +@class RocksDBMergeOperator; +@class RocksDBPrefixExtractor; + +NS_ASSUME_NONNULL_BEGIN #pragma mark - Options @@ -38,45 +38,6 @@ @end -#pragma mark - Encoding Options - -/** - Options to define how arbitrary objects (keys & values) should be converted to - NSData and vise versa. - */ -@interface RocksDBOptions (Encoding) - -/** @brief - A block to convert `id` keys to NSData objects. - */ -@property (nonatomic, copy) NSData * (^ keyEncoder)(id key); - -/** @brief - A block to convert NSData objects to the corresponding `id` key. - */ -@property (nonatomic, copy) id (^ keyDecoder)(NSData *data); - -/** @brief - A block to convert `id` values to NSData objects. The block takes two - parameters, the key-value pair to allow multiplexing. - */ -@property (nonatomic, copy) NSData * (^ valueEncoder)(id key, id value); - -/** @brief A block to convert NSData objects to the corresponding value. */ -@property (nonatomic, copy) id (^ valueDecoder)(id key, NSData *data); - -/** @brief Use a predefined type for the keys. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType keyType; - -/** @brief Use a predefined type for the values. - @see RocksDBTypes - */ -@property (nonatomic, assign) RocksDBType valueType; - -@end - #pragma mark - DB Options /** @@ -109,12 +70,12 @@ /** @brief Number of open files that can be used by the DB. The default is 5000. */ -@property (nonatomic, assign) int maxOpenFiles; +@property (nonatomic, assign) int maxOpenFiles; /** @brief Once write-ahead logs exceed this size, column families whose memtables are backed by the oldest live WAL file will be forced to flush. The default is 0. */ -@property (nonatomic, assign) uint64_t maxWriteAheadLogSize; +@property (nonatomic, assign) uint64_t maxWriteAheadLogSize; /** @brief If non-nil, metrics about database operations will be collected. Statistics objects should not be shared between DB instances. @@ -122,7 +83,7 @@ @see RocksDBStatistics */ -@property (nonatomic, strong) RocksDBStatistics *statistics; +@property (nonatomic, strong, nullable) RocksDBStatistics *statistics; /** @brief If true, then the contents of manifest and data files are not synced to stable storage. @@ -166,7 +127,7 @@ @see RocksDBComparator */ -@property (nonatomic, strong) RocksDBComparator *comparator; +@property (nonatomic, strong, nullable) RocksDBComparator *comparator; /** @brief The client must provide a merge operator if Merge operation needs to be accessed. @@ -178,7 +139,7 @@ @see RocksDBMergeOperator */ -@property (nonatomic, strong) RocksDBMergeOperator *mergeOperator; +@property (nonatomic, strong, nullable) RocksDBMergeOperator *mergeOperator; /** @brief Amount of data to build up in memory (backed by an unsorted log on disk) before converting to a sorted on-disk file. @@ -207,7 +168,7 @@ @see RocksDBPrefixExtractor */ -@property (nonatomic, strong) RocksDBPrefixExtractor *prefixExtractor; +@property (nonatomic, strong, nullable) RocksDBPrefixExtractor *prefixExtractor; /** @brief Number of levels for this DB. */ @property (nonatomic, assign) int numLevels; @@ -300,7 +261,7 @@ @see RocksDBMemTableRepFactory */ -@property (nonatomic, strong) RocksDBMemTableRepFactory *memTableRepFactory; +@property (nonatomic, strong, nullable) RocksDBMemTableRepFactory *memTableRepFactory; /** @brief This is a factory that provides TableFactory objects. Default: A block-based table factory that provides a default @@ -309,7 +270,7 @@ @see RocksDBTableFactory */ -@property (nonatomic, strong) RocksDBTableFactory *tableFacotry; +@property (nonatomic, strong, nullable) RocksDBTableFactory *tableFacotry; /** @brief If prefixExtractor is set and bloom_bits is not 0, create prefix bloom for memtable @@ -341,3 +302,5 @@ @property (nonatomic, assign) uint32_t minPartialMergeOperands; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBOptions.mm b/Code/RocksDBOptions.mm index f0b266c..70de8eb 100644 --- a/Code/RocksDBOptions.mm +++ b/Code/RocksDBOptions.mm @@ -8,6 +8,10 @@ #import "RocksDBOptions.h" +#import "RocksDBComparator.h" +#import "RocksDBMergeOperator.h" +#import "RocksDBPrefixExtractor.h" + #import #import #import diff --git a/Code/RocksDBPlainTableOptions.h b/Code/RocksDBPlainTableOptions.h index 09d596f..698df6f 100644 --- a/Code/RocksDBPlainTableOptions.h +++ b/Code/RocksDBPlainTableOptions.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + typedef NS_ENUM(char, PlainTableEncodingType) { PlainTableEncodingPlain, @@ -74,3 +76,5 @@ typedef NS_ENUM(char, PlainTableEncodingType) @property (nonatomic, assign) BOOL storeIndexInFile; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBPrefixExtractor.h b/Code/RocksDBPrefixExtractor.h index 4512cc7..d43c938 100644 --- a/Code/RocksDBPrefixExtractor.h +++ b/Code/RocksDBPrefixExtractor.h @@ -48,9 +48,9 @@ typedef NS_ENUM(NSUInteger, RocksDBPrefixType) @return A newly-initialized instance of a prefix extractor. */ - (instancetype)initWithName:(NSString *)name - transformBlock:(id (^)(id key))transformBlock - prefixCandidateBlock:(BOOL (^)(id key))prefixCandidateBlock - validPrefixBlock:(BOOL (^)(id prefix))validPrefixBlock; + transformBlock:(NSData * (^)(NSData *key))transformBlock + prefixCandidateBlock:(BOOL (^)(NSData *key))prefixCandidateBlock + validPrefixBlock:(BOOL (^)(NSData *prefix))validPrefixBlock; @end diff --git a/Code/RocksDBPrefixExtractor.mm b/Code/RocksDBPrefixExtractor.mm index ce1529d..d52d116 100644 --- a/Code/RocksDBPrefixExtractor.mm +++ b/Code/RocksDBPrefixExtractor.mm @@ -7,7 +7,6 @@ // #import "RocksDBPrefixExtractor.h" -#import "RocksDBEncodingOptions.h" #import "RocksDBSlice.h" #import "RocksDBCallbackSliceTransform.h" @@ -16,21 +15,18 @@ @interface RocksDBPrefixExtractor () { - RocksDBEncodingOptions *_encodingOptions; NSString *_name; const rocksdb::SliceTransform *_sliceTransform; - id (^ _transformBlock)(id key); - BOOL (^ _prefixCandidateBlock)(id key); - BOOL (^ _validPrefixBlock)(id prefix); + NSData * (^ _transformBlock)(NSData *key); + BOOL (^ _prefixCandidateBlock)(NSData * key); + BOOL (^ _validPrefixBlock)(NSData *prefix); } -@property (nonatomic, strong) RocksDBEncodingOptions *encodingOptions; @property (nonatomic, strong) NSString *name; @property (nonatomic, assign) const rocksdb::SliceTransform *sliceTransform; @end @implementation RocksDBPrefixExtractor -@synthesize encodingOptions = _encodingOptions; @synthesize name = _name; @synthesize sliceTransform = _sliceTransform; @@ -55,9 +51,9 @@ - (instancetype)initWithNativeSliceTransform:(const rocksdb::SliceTransform *)sl } - (instancetype)initWithName:(NSString *)name - transformBlock:(id (^)(id key))transformBlock - prefixCandidateBlock:(BOOL (^)(id key))prefixCandidateBlock - validPrefixBlock:(BOOL (^)(id prefix))validPrefixBlock + transformBlock:(NSData * (^)(NSData *key))transformBlock + prefixCandidateBlock:(BOOL (^)(NSData *key))prefixCandidateBlock + validPrefixBlock:(BOOL (^)(NSData *prefix))validPrefixBlock { self = [super init]; if (self) { @@ -91,9 +87,9 @@ - (void)dealloc - (NSData *)transformKey:(const rocksdb::Slice &)keySlice { - id key = DecodeKeySlice(keySlice, _encodingOptions, nil); - id transformed = _transformBlock(key); - return EncodeKey(transformed, _encodingOptions, nil); + NSData *key = DataFromSlice(keySlice); + NSData * transformed = _transformBlock(key); + return transformed; } bool trampolineInDomain(void* instance, const rocksdb::Slice& src) @@ -103,7 +99,7 @@ bool trampolineInDomain(void* instance, const rocksdb::Slice& src) - (BOOL)isKeyPrefixCandidate:(const rocksdb::Slice &)keySlice { - id key = DecodeKeySlice(keySlice, _encodingOptions, nil); + NSData *key = DataFromSlice(keySlice); return _prefixCandidateBlock(key); } @@ -114,8 +110,8 @@ bool trampolineInRange(void* instance, const rocksdb::Slice& dst) - (BOOL)isPrefixValid:(const rocksdb::Slice &)prefixSlice { - id prefix = DecodeKeySlice(prefixSlice, _encodingOptions, nil); - return _prefixCandidateBlock(prefix); + NSData *prefix = DataFromSlice(prefixSlice); + return _validPrefixBlock(prefix); } @end diff --git a/Code/RocksDBRange.h b/Code/RocksDBRange.h index 9d6e24f..4e0a7b1 100644 --- a/Code/RocksDBRange.h +++ b/Code/RocksDBRange.h @@ -16,16 +16,16 @@ NS_ASSUME_NONNULL_BEGIN @interface RocksDBKeyRange : NSObject /* @breif Start key */ -@property (nonatomic, strong, nullable) id start; +@property (nonatomic, strong, nullable) NSData * start; /* @breif End key */ -@property (nonatomic, strong, nullable) id end; +@property (nonatomic, strong, nullable) NSData * end; /** Creates a new RocksDBKeyRange from the specified values. @return RocksDBKeyRange with start and end keys. */ -- (instancetype)initWithStart:(__nullable id)start end:(__nullable id)end; +- (instancetype)initWithStart:(nullable NSData *)start end:(nullable NSData *)end; @end @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN @return RocksDBKeyRange with start and end keys. */ -NS_INLINE RocksDBKeyRange * RocksDBMakeKeyRange(__nullable id start, __nullable id end) +NS_INLINE RocksDBKeyRange * RocksDBMakeKeyRange(NSData * _Nullable start, NSData * _Nullable end) { return [[RocksDBKeyRange alloc] initWithStart:start end:end]; } diff --git a/Code/RocksDBReadOptions.h b/Code/RocksDBReadOptions.h index 93e5fe4..12379be 100644 --- a/Code/RocksDBReadOptions.h +++ b/Code/RocksDBReadOptions.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** Options that control read operations. */ @interface RocksDBReadOptions : NSObject @@ -25,3 +27,5 @@ @property (nonatomic, assign) BOOL fillCache; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBSlice.h b/Code/RocksDBSlice.h index 42e738e..43cef30 100644 --- a/Code/RocksDBSlice.h +++ b/Code/RocksDBSlice.h @@ -7,9 +7,6 @@ // #import -#import "RocksDBEncodingOptions.h" -#import "RocksDBError.h" - #import NS_INLINE rocksdb::Slice SliceFromData(NSData *data) @@ -21,97 +18,3 @@ NS_INLINE NSData * DataFromSlice(rocksdb::Slice slice) { return [NSData dataWithBytes:slice.data() length:slice.size()]; } - -#pragma mark - Key Encoding - -NS_INLINE NSData * EncodeKey(id aKey, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - if ([aKey isKindOfClass:[NSData class]]) { - return aKey; - } - - NSData *encoded = nil; - if (options.keyEncoder != nil) { - encoded = options.keyEncoder(aKey); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return encoded; -} - -NS_INLINE rocksdb::Slice SliceFromKey(id aKey, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - return SliceFromData(EncodeKey(aKey, options, error)); -} - -NS_INLINE id DecodeKeySlice(rocksdb::Slice slice, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - id key = DataFromSlice(slice); - if (options.keyDecoder != nil) { - key = options.keyDecoder(key); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return key; -} - -NS_INLINE id DecodeKeyData(NSData *data, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - id key = nil; - if (options.keyDecoder != nil) { - key = options.keyDecoder(data); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return key; -} - -#pragma mark - Value Encoding - -NS_INLINE NSData * EncodeValue(id aKey, id value, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - if ([value isKindOfClass:[NSData class]]) { - return value; - } - - NSData *encoded = nil; - if (options.valueEncoder != nil) { - encoded = options.valueEncoder(aKey, value); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return encoded; -} - -NS_INLINE rocksdb::Slice SliceFromValue(id aKey, id value, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - return SliceFromData(EncodeValue(aKey, value, options, error)); -} - -NS_INLINE id DecodeValueSlice(id aKey, rocksdb::Slice slice, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - id value = DataFromSlice(slice); - if (options.valueDecoder != nil) { - value = options.valueDecoder(aKey, value); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return value; -} - -NS_INLINE id DecodeValueData(id aKey, NSData *data, RocksDBEncodingOptions *options, NSError * __autoreleasing *error) -{ - id value = nil; - if (options.valueDecoder != nil) { - value = options.valueDecoder(aKey, data); - } else if (error && *error == nil) { - NSError *temp = [RocksDBError errorForMissingConversionBlock]; - *error = temp; - } - return value; -} diff --git a/Code/RocksDBSnapshot.h b/Code/RocksDBSnapshot.h index e2b4048..0cad807 100644 --- a/Code/RocksDBSnapshot.h +++ b/Code/RocksDBSnapshot.h @@ -45,17 +45,17 @@ NS_ASSUME_NONNULL_BEGIN - (RocksDBColumnFamilyMetaData *)columnFamilyMetaData UNAVAILABLE("Column Family API not available"); #endif -+ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path UNAVAILABLE("Column Family API not available"); ++ (NSArray *)listColumnFamiliesInDatabaseAtPath:(NSString *)path UNAVAILABLE("Column Family API not available"); - (RocksDBColumnFamily *)createColumnFamilyWithName:(NSString *)name andOptions:(void (^)(RocksDBColumnFamilyOptions *options))optionsBlock UNAVAILABLE("Column Family API not available"); -- (NSArray *)columnFamilies UNAVAILABLE("Column Family API not available"); +- (NSArray *)columnFamilies UNAVAILABLE("Column Family API not available"); - (void)setDefaultReadOptions:(void (^)(RocksDBReadOptions *readOptions))readOptions andWriteOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions UNAVAILABLE("Specify options when creating snapshot via DB instance"); - (RocksDBSnapshot *)snapshot UNAVAILABLE("Yo Dawg, Snapshot in Snapshot ... "); -- (RocksDBSnapshot *)snapshotWithReadOptions:(void (^)(RocksDBReadOptions *readOptions))readOptions UNAVAILABLE("Yo Dawg, Snapshot in Snapshot ... "); +- (RocksDBSnapshot *)snapshotWithReadOptions:(void (^)(RocksDBReadOptions *readOptions))readOptions UNAVAILABLE("Yo Dawg, Snapshot in Snapshot ... "); #define NA_SELECTOR(sel) sel UNAVAILABLE("Snapshot is read-only"); SNAPSHOT_PUT_MERGE_DELETE_SELECTORS diff --git a/Code/RocksDBSnapshotUnavailable.h b/Code/RocksDBSnapshotUnavailable.h index c9227a3..1100dae 100644 --- a/Code/RocksDBSnapshotUnavailable.h +++ b/Code/RocksDBSnapshotUnavailable.h @@ -9,26 +9,15 @@ #define UNAVAILABLE(x) __attribute__((unavailable(x))) #define SNAPSHOT_PUT_MERGE_DELETE_SELECTORS \ -NA_SELECTOR(- (BOOL)setObject:(id)anObject forKey:(id)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)setObject:(id)anObject forKey:(id)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ +NA_SELECTOR(- (BOOL)setData:(NSData *)anObject forKey:(NSData *)aKey error:(NSError * _Nullable *)error) \ +NA_SELECTOR(- (BOOL)setData:(NSData *)anObject forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ \ -NA_SELECTOR(- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)setData:(NSData *)data forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ -\ -NA_SELECTOR(- (BOOL)mergeObject:(id)anObject forKey:(id)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)mergeObject:(id)anObject forKey:(id)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ -\ -NA_SELECTOR(- (BOOL)mergeOperation:(NSString *)aMerge forKey:(id)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)mergeOperation:(NSString *)aMerge forKey:(id)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ -\ -NA_SELECTOR(- (BOOL)mergeData:(NSData *)data forKey:(NSData *)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)mergeData:(NSData *)data forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ -\ -NA_SELECTOR(- (BOOL)deleteObjectForKey:(id)aKey error:(NSError * _Nullable *)error) \ -NA_SELECTOR(- (BOOL)deleteObjectForKey:(id)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ +NA_SELECTOR(- (BOOL)mergeData:(NSData *)anObject forKey:(NSData *)aKey error:(NSError * _Nullable *)error) \ +NA_SELECTOR(- (BOOL)mergeData:(NSData *)anObject forKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ \ NA_SELECTOR(- (BOOL)deleteDataForKey:(NSData *)aKey error:(NSError * _Nullable *)error) \ NA_SELECTOR(- (BOOL)deleteDataForKey:(NSData *)aKey writeOptions:(void (^)(RocksDBWriteOptions *writeOptions))writeOptions error:(NSError * _Nullable *)error) \ +\ #if !(defined(ROCKSDB_LITE) && defined(TARGET_OS_IPHONE)) diff --git a/Code/RocksDBTableFactory.h b/Code/RocksDBTableFactory.h index 7e2cc34..49b5279 100644 --- a/Code/RocksDBTableFactory.h +++ b/Code/RocksDBTableFactory.h @@ -14,6 +14,8 @@ #import "RocksDBCuckooTableOptions.h" #endif +NS_ASSUME_NONNULL_BEGIN + /** A factory for the TableFactory objects. */ @interface RocksDBTableFactory : NSObject @@ -47,3 +49,5 @@ #endif @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBTypes.h b/Code/RocksDBTypes.h deleted file mode 100644 index d464584..0000000 --- a/Code/RocksDBTypes.h +++ /dev/null @@ -1,61 +0,0 @@ -// -// RocksDBTypes.h -// ObjectiveRocks -// -// Created by Iska on 25/12/14. -// Copyright (c) 2014 BrainCookie. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** The predefined supported types */ -typedef NS_ENUM(NSUInteger, RocksDBType) -{ - /** @brief Type for keys/values that are NSString objects. */ - RocksDBTypeNSString, - /** @brief Type for keys/values that are serializable via - the NSJSONSerialization. */ - RocksDBTypeNSJSONSerializable -}; - -/** Utility class for the predefined key/value encoders. */ -@interface RocksDBTypes : NSObject - -/** - Returns a predefined key encoder for the given type. - - @param type The predefined type. - @return The predefined key encoder. - */ -+ (NSData *(^)(id))keyEncoderForType:(RocksDBType)type; - -/** - Returns a predefined key decoder for the given type. - - @param type The predefined type. - @return The predefined key decoder. - */ -+ (id (^)(NSData *))keyDecoderForType:(RocksDBType)type; - - -/** - Returns a predefined value decoder for the given type. - - @param type The predefined type. - @return The predefined value decoder. - */ -+ (NSData *(^)(id, id))valueEncoderForType:(RocksDBType)type; - -/** - Returns a predefined value decoder for the given type. - - @param type The predefined type. - @return The predefined value decoder. - */ -+ (id (^)(id, NSData *))valueDecoderForType:(RocksDBType)type; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBTypes.mm b/Code/RocksDBTypes.mm deleted file mode 100644 index e7739a7..0000000 --- a/Code/RocksDBTypes.mm +++ /dev/null @@ -1,106 +0,0 @@ -// -// RocksDBTypes.mm -// ObjectiveRocks -// -// Created by Iska on 25/12/14. -// Copyright (c) 2014 BrainCookie. All rights reserved. -// - -#import "RocksDBTypes.h" - -@implementation RocksDBTypes - -+ (NSData *(^)(id))keyEncoderForType:(RocksDBType)type -{ - switch (type) { - case RocksDBTypeNSString: - return ^NSData * (id key) { - return [key dataUsingEncoding:NSUTF8StringEncoding]; - }; - - case RocksDBTypeNSJSONSerializable: - return ^NSData * (id key) { - NSError *error = nil; - NSData *data = [NSJSONSerialization dataWithJSONObject:key - options:0 - error:&error]; - if (error) { - NSLog(@"Error encoding key: %@", error.debugDescription); - } - return data; - }; - } -} - -+ (id (^)(NSData *))keyDecoderForType:(RocksDBType)type -{ - switch (type) { - case RocksDBTypeNSString: - return ^id (NSData *data) { - if (data == nil) return nil; - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - }; - - case RocksDBTypeNSJSONSerializable: - return ^id (NSData * data) { - if (data == nil) return nil; - NSError *error = nil; - id obj = [NSJSONSerialization JSONObjectWithData:data - options:NSJSONReadingMutableContainers - error:&error]; - if (error) { - NSLog(@"Error decoding key: %@", error.debugDescription); - } - return obj; - }; - } -} - -+ (NSData *(^)(id, id))valueEncoderForType:(RocksDBType)type -{ - switch (type) { - case RocksDBTypeNSString: - return ^NSData * (id key, id value) { - return [value dataUsingEncoding:NSUTF8StringEncoding]; - }; - - case RocksDBTypeNSJSONSerializable: - return ^NSData * (id key, id value) { - NSError *error = nil; - NSData *data = [NSJSONSerialization dataWithJSONObject:value - options:0 - error:&error]; - if (error) { - NSLog(@"Error encoding value: %@", error.debugDescription); - } - return data; - }; - - } -} - -+ (id (^)(id, NSData *))valueDecoderForType:(RocksDBType)type -{ - switch (type) { - case RocksDBTypeNSString: - return ^id (id key, NSData *data) { - if (data == nil) return nil; - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - }; - - case RocksDBTypeNSJSONSerializable: - return ^id (id key, NSData * data) { - if (data == nil) return nil; - NSError *error = nil; - id obj = [NSJSONSerialization JSONObjectWithData:data - options:NSJSONReadingMutableContainers - error:&error]; - if (error) { - NSLog(@"Error decoding value: %@", error.debugDescription); - } - return obj; - }; - } -} - -@end diff --git a/Code/RocksDBWriteBatch+Private.h b/Code/RocksDBWriteBatch+Private.h index 0332281..d5d213b 100644 --- a/Code/RocksDBWriteBatch+Private.h +++ b/Code/RocksDBWriteBatch+Private.h @@ -14,8 +14,6 @@ namespace rocksdb { class WriteBatchBase; } -@class RocksDBEncodingOptions; - /** This category is intended to hide all C++ types from the public interface in order to maintain a pure Objective-C API for Swift compatibility. @@ -28,9 +26,6 @@ namespace rocksdb { /** @brief The rocksdb::ColumnFamilyHandle associated with this instance. */ @property (nonatomic, readonly) rocksdb::ColumnFamilyHandle *columnFamily; -/** @brief The RocksDBEncodingOptions associated with this instance. */ -@property (nonatomic, readonly) RocksDBEncodingOptions *encodingOptions; - /** Initializes a new instance of `RocksDBWriteBatch` with the given native rocksdb::WriteBatchBase instance, encoding options and rocksdb::ColumnFamilyHandle instance. @@ -39,26 +34,18 @@ namespace rocksdb { @param writeBatchBase An instance of a concrete subclass implementation of rocksdb::WriteBatchBase. @param columnFamily The rocks::ColumnFamilyHandle instance. - @param options The Encoding options. @return a newly-initialized instance of `RocksDBWriteBatch`. - - @see RocksDBEncodingOptions */ - (instancetype)initWithNativeWriteBatch:(rocksdb::WriteBatchBase *)writeBatchBase - columnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions; + columnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily; /** Initializes a new instance of a simple `RocksDBWriteBatch` with the given options and rocksdb::ColumnFamilyHandle instance. @param columnFamily The rocks::ColumnFamilyHandle instance. - @param options The Encoding options. @return a newly-initialized instance of `RocksDBWriteBatch`. - - @see RocksDBEncodingOptions */ -- (instancetype)initWithColumnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions; +- (instancetype)initWithColumnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily; @end diff --git a/Code/RocksDBWriteBatch.h b/Code/RocksDBWriteBatch.h index 0616fd4..90d31e0 100644 --- a/Code/RocksDBWriteBatch.h +++ b/Code/RocksDBWriteBatch.h @@ -7,7 +7,6 @@ // #import -#import "RocksDBEncodingOptions.h" NS_ASSUME_NONNULL_BEGIN @@ -30,15 +29,7 @@ NS_ASSUME_NONNULL_BEGIN @param anObject The object for key. @param aKey The key for object. */ -- (void)setObject:(id)anObject forKey:(id)aKey; - -/** - Stores the given key-data pair into the Write Batch. - - @param data The data for key. - @param aKey The key for object. - */ -- (void)setData:(NSData *)data forKey:(NSData *)aKey; +- (void)setData:(NSData *)anObject forKey:(NSData *)aKey; /** Stores the given key-object pair for the given Column Family into the Write Batch. @@ -47,41 +38,7 @@ NS_ASSUME_NONNULL_BEGIN @param aKey The key for object. @param columnFamily The column family where data should be written. */ -- (void)setObject:(id)anObject forKey:(id)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; - -/** - Stores the given key-data pair for the given Column Family into the Write Batch. - - @param data The data for key. - @param aKey The key for object. - @param columnFamily The column family where data should be written. - */ -- (void)setData:(NSData *)data forKey:(NSData *)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; - -/** - Perform the merge operation in the Write Batch. - - @param aMerge A merge opration. - @param aKey The key for the merge. - */ -- (void)mergeOperation:(NSString *)aMerge forKey:(id)aKey; - -/** - Perform the merge operation for the given Column Family in the Write Batch. - - @param aMerge A merge opration. - @param aKey The key for the merge. - @param columnFamily The column family where data should be merged. - */ -- (void)mergeOperation:(NSString *)aMerge forKey:(id)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; - -/** - Merges the given key-object pair into the Write Batch. - - @param anObject The object for key. - @param aKey The key for object. - */ -- (void)mergeObject:(id)anObject forKey:(id)aKey; +- (void)setData:(NSData *)anObject forKey:(NSData *)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; /** Merges the given key-object pair into the Write Batch. @@ -89,8 +46,7 @@ NS_ASSUME_NONNULL_BEGIN @param anObject The object for key. @param aKey The key for object. */ -- (void)mergeData:(NSData *)data forKey:(NSData *)aKey; - +- (void)mergeData:(NSData *)anObject forKey:(NSData *)aKey; /** Merges the given key-object pair for the given Column Family into the Write Batch. @@ -99,27 +55,11 @@ NS_ASSUME_NONNULL_BEGIN @param aKey The key for object. @param columnFamily The column family where data should be written. */ -- (void)mergeObject:(id)anObject forKey:(id)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; - -/** - Merges the given key-data pair for the given Column Family into the Write Batch. - - @param data The data for key. - @param aKey The key for object. - @param columnFamily The column family where data should be written. - */ -- (void)mergeData:(NSData *)data forKey:(NSData *)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; +- (void)mergeData:(NSData *)anObject forKey:(NSData *)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; /** Deletes the object for the given key from this Write Batch. - @param aKey The key to delete. - */ -- (void)deleteObjectForKey:(id)aKey; - -/** - Deletes the data for the given key from this Write Batch. - @param aKey The key to delete. */ - (void)deleteDataForKey:(NSData *)aKey; @@ -127,15 +67,6 @@ NS_ASSUME_NONNULL_BEGIN /** Deletes the object for the given key in the given Column Family from this Write Batch. - @param data The data for key. - @param aKey The key for object. - @param columnFamily The column family from which the data should be deleted. - */ -- (void)deleteObjectForKey:(id)aKey inColumnFamily:(nullable RocksDBColumnFamily *)columnFamily; - -/** - Deletes the object for the given key in the given Column Family from the Write Batch. - @param data The data for key. @param aKey The key for object. @param columnFamily The column family from which the data should be deleted. diff --git a/Code/RocksDBWriteBatch.mm b/Code/RocksDBWriteBatch.mm index ad00c22..2dd4b6c 100644 --- a/Code/RocksDBWriteBatch.mm +++ b/Code/RocksDBWriteBatch.mm @@ -18,7 +18,6 @@ @interface RocksDBWriteBatch () { rocksdb::ColumnFamilyHandle *_columnFamily; - RocksDBEncodingOptions *_encodingOptions; } @property (nonatomic, assign) rocksdb::WriteBatchBase *writeBatchBase; @end @@ -29,22 +28,18 @@ @implementation RocksDBWriteBatch #pragma mark - Lifecycle - (instancetype)initWithColumnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions { return [self initWithNativeWriteBatch:new rocksdb::WriteBatch() - columnFamily:columnFamily - andEncodingOptions:encodingOptions]; + columnFamily:columnFamily]; } - (instancetype)initWithNativeWriteBatch:(rocksdb::WriteBatchBase *)writeBatchBase columnFamily:(rocksdb::ColumnFamilyHandle *)columnFamily - andEncodingOptions:(RocksDBEncodingOptions *)encodingOptions { self = [super init]; if (self) { _writeBatchBase = writeBatchBase; _columnFamily = columnFamily; - _encodingOptions = encodingOptions; } return self; } @@ -61,100 +56,49 @@ - (void)dealloc #pragma mark - Put -- (void)setObject:(id)anObject forKey:(id)aKey +- (void)setData:(NSData *)anObject forKey:(NSData *)aKey { - [self setObject:anObject forKey:aKey inColumnFamily:nil]; + [self setData:anObject forKey:aKey inColumnFamily:nil]; } -- (void)setData:(NSData *)data forKey:(NSData *)aKey +- (void)setData:(NSData *)anObject forKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily { - [self setData:data forKey:aKey inColumnFamily:nil]; -} - -- (void)setObject:(id)anObject forKey:(id)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily -{ - [self setData:EncodeValue(aKey, anObject, _encodingOptions, nil) - forKey:EncodeKey(aKey, _encodingOptions, nil) - inColumnFamily:columnFamily]; -} - -- (void)setData:(NSData *)data forKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily -{ - if (aKey != nil && data != nil) { + if (aKey != nil && anObject != nil) { rocksdb::ColumnFamilyHandle *handle = _columnFamily; if (columnFamily != nil) { handle = columnFamily.columnFamily; } - _writeBatchBase->Put(handle, - SliceFromData(aKey), - SliceFromData(data)); + _writeBatchBase->Put(handle, SliceFromData(aKey), SliceFromData(anObject)); } } #pragma mark - Merge -- (void)mergeOperation:(NSString *)aMerge forKey:(id)aKey -{ - [self mergeOperation:aMerge forKey:aKey inColumnFamily:nil]; -} - -- (void)mergeObject:(id)anObject forKey:(id)aKey -{ - [self mergeObject:anObject forKey:aKey inColumnFamily:nil]; -} - -- (void)mergeData:(NSData *)data forKey:(NSData *)aKey +- (void)mergeData:(NSData *)anObject forKey:(NSData *)aKey { - [self mergeData:data forKey:aKey inColumnFamily:nil]; + [self mergeData:anObject forKey:aKey inColumnFamily:nil]; } -- (void)mergeOperation:(NSString *)aMerge forKey:(id)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily +- (void)mergeData:(NSData *)anObject forKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily { - [self mergeData:[aMerge dataUsingEncoding:NSUTF8StringEncoding] - forKey:EncodeKey(aKey, _encodingOptions, nil) - inColumnFamily:columnFamily]; -} - -- (void)mergeObject:(id)anObject forKey:(id)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily -{ - [self mergeData:EncodeValue(aKey, anObject, _encodingOptions, nil) - forKey:EncodeKey(aKey, _encodingOptions, nil) - inColumnFamily:columnFamily]; -} - -- (void)mergeData:(NSData *)data forKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily; -{ - if (aKey != nil && data != nil) { + if (aKey != nil && anObject != nil) { rocksdb::ColumnFamilyHandle *handle = _columnFamily; if (columnFamily != nil) { handle = columnFamily.columnFamily; } - _writeBatchBase->Merge(handle, - SliceFromData(aKey), - SliceFromData(data)); + _writeBatchBase->Merge(handle, SliceFromData(aKey), SliceFromData(anObject)); } } #pragma mark - Delete -- (void)deleteObjectForKey:(id)aKey -{ - [self deleteObjectForKey:aKey inColumnFamily:nil]; -} - - (void)deleteDataForKey:(NSData *)aKey { [self deleteDataForKey:aKey inColumnFamily:nil]; } -- (void)deleteObjectForKey:(id)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily -{ - [self deleteDataForKey:EncodeKey(aKey, _encodingOptions, nil) - inColumnFamily:columnFamily]; -} - - (void)deleteDataForKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)columnFamily { if (aKey != nil) { @@ -163,8 +107,7 @@ - (void)deleteDataForKey:(NSData *)aKey inColumnFamily:(RocksDBColumnFamily *)co handle = columnFamily.columnFamily; } - _writeBatchBase->Delete(handle, - SliceFromData(aKey)); + _writeBatchBase->Delete(handle, SliceFromData(aKey)); } } diff --git a/Code/RocksDBWriteBatchIterator+Private.h b/Code/RocksDBWriteBatchIterator+Private.h index 373af80..77897ec 100644 --- a/Code/RocksDBWriteBatchIterator+Private.h +++ b/Code/RocksDBWriteBatchIterator+Private.h @@ -23,12 +23,8 @@ namespace rocksdb { rocksdb::WBWIIterator instance. @param iterator The rocks::WBWIIterator instance. - @param options The Encoding options. @return a newly-initialized instance of `RocksDBWriteBatchIterator`. - - @see RocksDBEncodingOptions */ -- (instancetype)initWithWriteBatchIterator:(rocksdb::WBWIIterator *)iterator - andEncodingOptions:(RocksDBEncodingOptions *)options; +- (instancetype)initWithWriteBatchIterator:(rocksdb::WBWIIterator *)iterator; @end diff --git a/Code/RocksDBWriteBatchIterator.h b/Code/RocksDBWriteBatchIterator.h index 6c22a1d..158689b 100644 --- a/Code/RocksDBWriteBatchIterator.h +++ b/Code/RocksDBWriteBatchIterator.h @@ -21,8 +21,8 @@ typedef NS_ENUM(NSUInteger, RocksDBWriteBatchEntryType) @interface RocksDBWriteBatchEntry : NSObject @property (nonatomic, readonly) RocksDBWriteBatchEntryType type; -@property (nonatomic, readonly) id key; -@property (nonatomic, readonly) id value; +@property (nonatomic, readonly) NSData *key; +@property (nonatomic, readonly) NSData *value; @end @@ -57,7 +57,7 @@ typedef NS_ENUM(NSUInteger, RocksDBWriteBatchEntryType) @param aKey The key to position the tartaritartor at. */ -- (void)seekToKey:(id)aKey; +- (void)seekToKey:(NSData *)aKey; /** Moves to the next entry in the source. After this call, `isValid` is diff --git a/Code/RocksDBWriteBatchIterator.mm b/Code/RocksDBWriteBatchIterator.mm index c0c54d5..07e9b33 100644 --- a/Code/RocksDBWriteBatchIterator.mm +++ b/Code/RocksDBWriteBatchIterator.mm @@ -26,7 +26,6 @@ @implementation RocksDBWriteBatchEntry @interface RocksDBWriteBatchIterator () { rocksdb::WBWIIterator *_iterator; - RocksDBEncodingOptions *_options; } @end @@ -35,12 +34,10 @@ @implementation RocksDBWriteBatchIterator #pragma mark - Lifecycle - (instancetype)initWithWriteBatchIterator:(rocksdb::WBWIIterator *)iterator - andEncodingOptions:(RocksDBEncodingOptions *)options { self = [super init]; if (self) { _iterator = iterator; - _options = options; } return self; } @@ -77,10 +74,10 @@ - (void)seekToLast _iterator->SeekToLast(); } -- (void)seekToKey:(id)aKey +- (void)seekToKey:(NSData *)aKey { if (aKey != nil) { - _iterator->Seek(SliceFromKey(aKey, _options, nil)); + _iterator->Seek(SliceFromData(aKey)); } } @@ -99,8 +96,8 @@ - (RocksDBWriteBatchEntry *)entry rocksdb::WriteEntry nativeEntry = _iterator->Entry(); RocksDBWriteBatchEntry *writeEntry = [RocksDBWriteBatchEntry new]; writeEntry.type = (RocksDBWriteBatchEntryType)nativeEntry.type; - writeEntry.key = DecodeKeySlice(nativeEntry.key, _options, nil); - writeEntry.value = DecodeKeySlice(nativeEntry.value, _options, nil); + writeEntry.key = DataFromSlice(nativeEntry.key); + writeEntry.value = DataFromSlice(nativeEntry.value); return writeEntry; } diff --git a/Code/RocksDBWriteOptions.h b/Code/RocksDBWriteOptions.h index 9cc4059..2b4c34b 100644 --- a/Code/RocksDBWriteOptions.h +++ b/Code/RocksDBWriteOptions.h @@ -8,6 +8,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** Options that control write operations. */ @interface RocksDBWriteOptions : NSObject @@ -22,12 +24,6 @@ */ @property (nonatomic, assign) BOOL disableWriteAheadLog; -/** @brief If non-zero, then associated write waiting longer than the specified - time MAY be aborted and returns Status::TimedOut. - Default: 0 - */ -@property (nonatomic, assign) uint64_t timeoutHint; - /** @brief If true and if user is trying to write to column families that don't exist then the write will be ignored. Default: false @@ -35,3 +31,5 @@ @property (nonatomic, assign) BOOL ignoreMissingColumnFamilies; @end + +NS_ASSUME_NONNULL_END diff --git a/Code/RocksDBWriteOptions.mm b/Code/RocksDBWriteOptions.mm index 0ff8539..3ea3616 100644 --- a/Code/RocksDBWriteOptions.mm +++ b/Code/RocksDBWriteOptions.mm @@ -51,16 +51,6 @@ - (void)setDisableWriteAheadLog:(BOOL)disableWriteAheadLog _options.disableWAL = disableWriteAheadLog; } -- (uint64_t)timeoutHint -{ - return _options.timeout_hint_us; -} - -- (void)setTimeoutHint:(uint64_t)timeoutHint -{ - _options.timeout_hint_us = timeoutHint; -} - - (BOOL)ignoreMissingColumnFamilies { return _options.ignore_missing_column_families; diff --git a/Framework/Info.plist b/Framework/Info.plist index c30ab6d..26873bf 100644 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.6.0 + 0.7.0 CFBundleSignature ???? CFBundleVersion diff --git a/ObjectiveRocks.playground/Contents.swift b/ObjectiveRocks.playground/Contents.swift deleted file mode 100644 index 801bdab..0000000 --- a/ObjectiveRocks.playground/Contents.swift +++ /dev/null @@ -1,55 +0,0 @@ -//: Playground - noun: a place where people can play - -import Cocoa -import XCPlayground -import ObjectiveRocks - -XCPlaygroundPage.currentPage.needsIndefiniteExecution = true - -let url = XCPlaygroundSharedDataDirectoryURL.URLByAppendingPathComponent("Rocks") -try NSFileManager.defaultManager().removeItemAtPath(url.path!) - -let rocks = RocksDB.databaseAtPath(url.path) { options in - options.createIfMissing = true - options.keyType = .NSString - options.valueEncoder = { key, number in - var value: Int = (number as! NSNumber).integerValue - return NSData(bytes: &value, length: sizeof(Int)) - } - options.valueDecoder = { key, data in - var value: Int = 0 - data.getBytes(&value, length: sizeof(Int)) - return NSNumber(integer: value) - } -} - -guard rocks != nil else { - XCPlaygroundPage.currentPage.finishExecution() -} - -try rocks.performWriteBatch { batch, writeOptions -> Void in - batch.setObject(-10, forKey: "0001") - batch.setObject(9, forKey: "0011") - batch.setObject(-8, forKey: "0002") - batch.setObject(7, forKey: "0003") - batch.setObject(-6, forKey: "0012") - batch.setObject(5, forKey: "0004") - batch.setObject(-4, forKey: "0005") - batch.setObject(3, forKey: "0006") - batch.setObject(-2, forKey: "0007") - batch.setObject(11, forKey: "0008") - batch.setObject(1, forKey: "0009") -} - -rocks.iterator().enumerateKeysWithPrefix("000") { key, stop -> Void in - do { - let value = try rocks.objectForKey(key) - - if value.integerValue > 10 { - var shouldStop: ObjCBool = true - stop.initialize(shouldStop) - } - } catch {} -} - -XCPlaygroundPage.currentPage.finishExecution() diff --git a/ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..3eb0f54 --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/Contents.swift @@ -0,0 +1,45 @@ +//: [Previous](@previous) + +/*: +# Rocks Basics +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +/*: +To open a database you have to specify its location: +*/ +let url: URL = playgroundURL(forDB: "Basics") + +/*: +`RocksDB` features many configuration settings, that can be specified when opening the database. `ObjectiveRocks` offers a blocks-based initializer for this purpose. The minimum configuration that you'll need is `createIfMissing` in order to create a new database if it doesn't already exist: +*/ +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true +} + +guard let rocks = rocks else { + PlaygroundPage.current.finishExecution() +} + +/*: +`RocksDB` provides three basic operations, `Put`, `Get`, and `Delete` to store/query data. Keys and values in `RocksDB` are arbitrary byte arrays: +*/ +try! rocks.setData("RocksDB".data(using: .utf8)!, forKey: "First Key".data(using: .utf8)!) + +/*: +Alternatively, you can define some mappers or extensions for a more friendly usage: + +> Checkout the extensions in `Support.swift` file in this playground +*/ +try! rocks.setData("World", forKey: "Hello") +try! rocks.setData("Bar", forKey: "Foo") + +let data = try! rocks.data(forKey: "Hello") +let string = String(data: data, encoding: .utf8) + +try! rocks.deleteData(forKey: "Hello") + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/timeline.xctimeline b/ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/timeline.xctimeline similarity index 70% rename from ObjectiveRocks.playground/timeline.xctimeline rename to ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/timeline.xctimeline index 7e8c30f..b666366 100644 --- a/ObjectiveRocks.playground/timeline.xctimeline +++ b/ObjectiveRocks.playground/Pages/Basics.xcplaygroundpage/timeline.xctimeline @@ -3,7 +3,7 @@ version = "3.0"> diff --git a/ObjectiveRocks.playground/Pages/Column Families.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Column Families.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..7dfc9e0 --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Column Families.xcplaygroundpage/Contents.swift @@ -0,0 +1,105 @@ +//: [Previous](@previous) + +/*: +# Column Families +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +/*: +`RocksDB` supports `Column Families`: +* Column Families provide a way to logically partition the database, think collections in MongoDB +* Can be configured independently +* Can be added/dropped on the fly +* Key-value pairs are associated with exactly one `Column Family` in the database +**** + +To demonsrate the basic concept behind `ColumnFamilies` let's take a look at the following example: +*/ + +let url: URL = playgroundURL(forDB: "ColumnFamilies") + +/*: +`RocksDB` has a `default` Column Family that is always used if not specified otherwise. The `RocksDBColumnFamilyOptions` that you provide +when opening a DB instance are assigned to this `default` Column Family. In this case a `RocksDBComparator` is provided, that sorts String keys in ascending order: +*/ +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) +} + +guard let rocks = rocks else { + PlaygroundPage.current.finishExecution() +} + +try! rocks.setData("1", forKey: "A") +try! rocks.setData("2", forKey: "B") +try! rocks.setData("3", forKey: "C") + +/*: +Once you have a `RocksDB` instance you can create and drop column families on the fly. Here we provide a `RocksDBComparator` is provided, that sorts String keys in descending order: + +> Notice that you can assign completely different `RocksDBColumnFamilyOptions` for the new Column Family +*/ +let columnFamily = rocks.createColumnFamily(withName: "new_column_family") { options in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareDescending) +} + +guard let columnFamily = columnFamily else { + PlaygroundPage.current.finishExecution() +} + +try! columnFamily.setData("1", forKey: "A") +try! columnFamily.setData("3", forKey: "B") +try! columnFamily.setData("5", forKey: "Y") +try! columnFamily.setData("7", forKey: "Z") + +/*: +Now if we itereate both the DB and the Column Family, we get the following: +*/ +iterate(db: rocks, title: "DB Key/Values") +iterate(db: columnFamily, title: "Column Family Key/Values") + +columnFamily.close() +rocks.close() + +/*: +If the DB already contains Column Families other than the default, then you need to specify all Column Families that currently exist in the database when opening it, including the default one. You specify the Column Families using a `RocksDBColumnFamiliesDescriptor`: + +- important: +The names of `RocksDBComparator` and `RocksDBMergeOperator` are attached to the database and column families when they are created, and are checked on every subsequent database open. If the name changes, the open call will fail. Hence we provide the same key comparators when opening the DB as before. +*/ +let descriptor = RocksDBColumnFamilyDescriptor() +descriptor.addDefaultColumnFamily { (options) in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) +} +descriptor.addColumnFamily(withName: "new_column_family") { (options) in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareDescending) +} + +let newRocks = RocksDB.database(atPath: url.path, columnFamilies: descriptor) + +guard let newRocks = newRocks else { + PlaygroundPage.current.finishExecution() +} + +/*: +Accessing the column families in the DB just as easy: +*/ +let newColumnFamily = newRocks.columnFamilies().last + +guard let newColumnFamily = newColumnFamily else { + PlaygroundPage.current.finishExecution() +} + +/*: +And here is the content of the DB after opening it again: +*/ +iterate(db: newRocks, title: "DB Key/Values") +iterate(db: newColumnFamily, title: "Column Family Key/Values") + +newRocks.close() + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/Pages/DB Options.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/DB Options.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..868bed7 --- /dev/null +++ b/ObjectiveRocks.playground/Pages/DB Options.xcplaygroundpage/Contents.swift @@ -0,0 +1,84 @@ +//: [Previous](@previous) + +/*: +# Rocks Options +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +/*: +`RocksDB` features highly flexible configuration settings that may be tuned to run on a variety of production environments. A production ready setup for example could look like this: +*/ + +let url: URL = playgroundURL(forDB: "DBOptions") + +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true + + options.writeBufferSize = 64 * 1024 * 1024 + options.maxWriteBufferNumber = 7 + options.targetFileSizeBase = UInt64(64 * 1024 * 1024) + options.numLevels = 7 + + options.maxLogFileSize = 50 * 1024 * 1024 + options.keepLogFileNum = 30 + + options.tableFacotry = RocksDBTableFactory.blockBasedTableFactory { options in + options.filterPolicy = RocksDBFilterPolicy.bloomFilterPolicy(withBitsPerKey: 10) + options.blockCache = RocksDBCache.lruCache(withCapacity: 1024 * 1024 * 1024) + options.blockSize = 64 * 1024; + } + + options.comparator = RocksDBComparator.comaparator(with: .bytewiseAscending) + + options.mergeOperator = RocksDBMergeOperator(name: "concat") { (key, existing, new) -> Data in + guard let existing = existing else { + return new + } + var res = existing + res.append(new) + return res + } +} + +guard let rocks = rocks else { + PlaygroundPage.current.finishExecution() +} + +/*: +> Notice the use of the `merge` operation. A `MergeOprator` is required in order to use `merges`. In this case the configured operator simply concatenates the data objects. +*/ +try! rocks.setData("Hello", forKey: "Key") +try! rocks.merge("World", forKey: "Key") + +let data = try! rocks.data(forKey: "Key") +let string = String(data: data, encoding: .utf8) + +/*: +In addition to the DB Options, `RocksDB` allows to define default read/write options for all operations: +*/ +rocks.setDefault( + readOptions: { readOptions in + readOptions.fillCache = false + }, + writeOptions: { writeOptions in + writeOptions.disableWriteAheadLog = false + } +) + +/*: +Nonetheless, each single read or write operation can be tuned via specific read/write options: +*/ +try! rocks.setData("Data", forKey: "Another Key") { writeOptions in + writeOptions.syncWrites = true + writeOptions.disableWriteAheadLog = true +} + +try! rocks.data(forKey: "Another Key") { readOptions in + readOptions.verifyChecksums = true + readOptions.fillCache = true +} + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/Pages/Intro.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Intro.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..0fa980e --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Intro.xcplaygroundpage/Contents.swift @@ -0,0 +1,72 @@ +/*: +# ObjectiveRocks + +ObjectiveRocks is an Objective-C wrapper of Facebook's [RocksDB](https://github.com/facebook/rocksdb) - A Persistent Key-Value Store for Flash and RAM Storage. +**** + +## Quick Overview + +RocksDB is a key-value store, where the keys and values are arbitrarily-sized byte streams. The keys are ordered within the key value store according to a specified comparator function. RocksDB supports atomic reads and writes, snapshots, iteration and features many configuration options. + +ObjectiveRocks provides an easy interface to RocksDB and an Objective-C friendly API that abstracts away the underlying C++ implementation, so you don't have to deal with it. While there is no need to learn the details about RocksDB to use this wrapper, a basic understanding of the internals is recommended and would explain the design decisions behind the, somewhat opinionated, API. + +If you are interested in the internals of RocksDB, please refer to the [RocksDB Wiki](https://github.com/facebook/rocksdb/wiki). + +## Swift + +ObjectiveRocks has a pure Objective-C interface and can be used with ease in Swift projects. + +## The Minimum You Need to Know + +* Keys and values are byte arrays +* All data in the database is logically arranged in sorted order via a given `Comparator` +* RocksDB supports `Column Families` + * Column Families provide a way to logically partition the database, think collections in MongoDB + * Can be configured independently + * Can be added/dropped on the fly + * Key-value pairs are associated with exactly one `Column Family` in the database. + * If no column family is specified, the `default` column family is used +* RocksDB provides three basic operations: + * Get(key) + * Put(key, value) + * Delete(key) +* Applications can define a merge operation via a `Merge Operator` + * A merge is an atomic Read-Modify-Write +* RocksDB features an `Iterator` API to perform `RangeScan` on the database +* RocksDB provides a `Snapshot` API allows an application to create a point-in-time view of a database +* There are many configuration options: + * `DBOptions`: Controls the behavior of the database + * `ColumnFamilyOptions`: Controls the behavior of column families + * `ReadOptions`: apply to single read operations + * `WriteOptions`: apply to single write operations + +## RocksDB Lite + +ObjectiveRocks incldues two targets, for iOS and macOS. The iOS target builds the RocksDB Lite version, which doesn't include the complete feature set. + +These features are only available in macOS: + +* Column Family Metadata +* Write Batch with Index +* Plain and Cuckoo Table Factories +* Vector, HashSkipList, HashLinkList and HashCuckoo Memtable Rep Factories +* Database Backups +* Database Statistics +* Database Properties +* Thread Status + +**** + +# Table of Contents + +- [Rocks Basics](Basics) +- [DB Options](DB%20Options) +- [Iteration](Iteration) +- [Prefix Seek](Prefix%20Seek) +- [Column Families](Column%20Families) +- [Write Batches](Write%20Batch) + +**** + +[Next](@next) +*/ diff --git a/ObjectiveRocks.playground/Pages/Iteration.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Iteration.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..445b26b --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Iteration.xcplaygroundpage/Contents.swift @@ -0,0 +1,73 @@ +//: [Previous](@previous) + +/*: +# Iteration +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +let url: URL = playgroundURL(forDB: "Iteration") + +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true +} + +guard let rocks = rocks else { + PlaygroundPage.current.finishExecution() +} + +try! rocks.setData("A", forKey: "A") +try! rocks.setData("B", forKey: "B") +try! rocks.setData("C", forKey: "C") +try! rocks.setData("D", forKey: "D") +try! rocks.setData("E", forKey: "E") +try! rocks.setData("F", forKey: "F") + +/*: +Iteration is provided via the `RocksDBIterator`. You get an instance of a `RocksDBIterator` via the DB object. The `Read Options` closure is optional and will default to those specified in DB instace. +*/ + +let iterator = rocks.iterator { readOptions in + // custom read options for this iterator +} + +/*: +With an iterator you can either iterate manually: +*/ + +print("--------------------------") +print("Manual Iteration:") +iterator.seek(toKey: "C") +while iterator.isValid() { + print(String(data: iterator.value(), encoding: .utf8)!) + iterator.next() +} + +/*: +or use one of the many provided iteration blocks. For example: +*/ +print("--------------------------") +print("Enumeration Block:") +iterator.enumerateKeysAndValues { (key, value, stop) in + print("\(String(data: key, encoding: .utf8)!): \(String(data: value, encoding: .utf8)!)") +} + +/*: +you can also iterate in reverse or in a given key range. +*/ +print("--------------------------") +print("Enumeration in Reverse in a Given Ragne:") +let range = RocksDBKeyRange(start: "E", end: "C") +iterator.enumerateKeysAndValues(in: range, reverse: true) { (key, value, stop) in + print("\(String(data: key, encoding: .utf8)!): \(String(data: value, encoding: .utf8)!)") +} + +/*: +> Do not forget to close the iterator when you are done using it: +*/ +iterator.close() +rocks.close() + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/Pages/Prefix Seek.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Prefix Seek.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..599fca2 --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Prefix Seek.xcplaygroundpage/Contents.swift @@ -0,0 +1,48 @@ +//: [Previous](@previous) + +/*: +# Prefix Seek +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + + +let url: URL = playgroundURL(forDB: "PrefixSeek") + +/*: +`RocksDBIterator` supports iterating inside a key-prefix by providing a `RocksDBPrefixExtractor`. One such extractor is built-in and it extracts a fixed-length prefix for each key: +*/ +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true + options.prefixExtractor = RocksDBPrefixExtractor(type: .fixedLength, length: 4) +} + +guard let rocks = rocks else { + PlaygroundPage.current.finishExecution() +} + +/*: +Given these contrived keys and values: +*/ +try! rocks.setData("A", forKey: "server_host") +try! rocks.setData("B", forKey: "db_host") +try! rocks.setData("C", forKey: "server_port") +try! rocks.setData("D", forKey: "db_port") +try! rocks.setData("E", forKey: "db_user") +try! rocks.setData("F", forKey: "server_alias") + +/*: +We could for example enumerate only the `server` keys: +*/ +let iterator = rocks.iterator() +iterator.enumerateKeysAndValues(withPrefix: "server") { (key, value, stop) in + print("\(String(data: key, encoding: .utf8)!): \(String(data: value, encoding: .utf8)!)") +} + +/*: +> Take a look at the `Column Families` for a more structured way to semantically partition/store your data in RocksDB +*/ + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/Pages/Write Batch.xcplaygroundpage/Contents.swift b/ObjectiveRocks.playground/Pages/Write Batch.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..66110ee --- /dev/null +++ b/ObjectiveRocks.playground/Pages/Write Batch.xcplaygroundpage/Contents.swift @@ -0,0 +1,73 @@ +//: [Previous](@previous) + +/*: +# Write Batches +*/ + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +/*: +You can atomically apply a set of updates to the database using a `WriteBatch`. + +Given the following DB and Column Family: +*/ + +let url: URL = playgroundURL(forDB: "WriteBatch") +let rocks = RocksDB.database(atPath: url.path) { options in + options.createIfMissing = true +} + +let columnFamily = rocks?.createColumnFamily(withName: "CF", andOptions: nil) + +guard + let rocks = rocks, + let columnFamily = columnFamily +else { + PlaygroundPage.current.finishExecution() +} + +try! rocks.setData("A", forKey: "A") +try! rocks.setData("B", forKey: "B") +try! columnFamily.setData("X", forKey: "X") + +/*: +There are two ways to use a `WriteBatch`: + +- via the `performWriteBatch` block, e.g.: +*/ + +try! rocks.performWriteBatch { (batch, options) in + batch.setData("A New", forKey: "A") + batch.deleteData(forKey: "B") + batch.setData("C", forKey: "C") + batch.setData("X New", forKey: "X", in: columnFamily) +} + +/*: +> The Write Batch object operates per default on the Column Family associated with the DB instance, which was used to create it. However, you can also specify the Column Family, in order to achieve an atomic write across multiple Column Families. +> Notice that the whole `WriteBatch` was applied as one atomic operation accross the db and the column family: +*/ +iterate(db: rocks, title: "DB Key/Values") +iterate(db: columnFamily, title: "Column Family Key/Values") + +/*: +The second way to use `WriteBatch`es is: + +- via a `WriteBatch` instance, which may be more flexible for "scattered" logic: +*/ +let writeBatch = rocks.writeBatch() +writeBatch.deleteData(forKey: "A") +writeBatch.setData("Y", forKey: "Y", in: columnFamily) +/* +At this point the contents of the DB are still the same, since the `WriteBatch` hasn't been applied yet. + +To write the batch you have to apply it: +*/ +try! rocks.applyWriteBatch(writeBatch, writeOptions: nil) + +iterate(db: rocks, title: "DB Key/Values") +iterate(db: columnFamily, title: "Column Family Key/Values") + +//: [Next](@next) diff --git a/ObjectiveRocks.playground/Sources/Support.swift b/ObjectiveRocks.playground/Sources/Support.swift new file mode 100644 index 0000000..01a91b6 --- /dev/null +++ b/ObjectiveRocks.playground/Sources/Support.swift @@ -0,0 +1,45 @@ +//: Playground - noun: a place where people can play + +import Foundation +import PlaygroundSupport +import ObjectiveRocks + +extension Data: ExpressibleByStringLiteral { + public init(stringLiteral value: String) { + self = value.data(using: .utf8)! + } + + public init(extendedGraphemeClusterLiteral value: String) { + self = value.data(using: .utf8)! + } + + public init(unicodeScalarLiteral value: String) { + self = value.data(using: .utf8)! + } +} + +extension Data: ExpressibleByIntegerLiteral { + public init(integerLiteral value: Int) { + var value = value + self.init(buffer: UnsafeBufferPointer(start: &value, count: 1)) + } +} + +public func playgroundURL(forDB name: String) -> URL { + let playgroundShared = PlaygroundSupport.playgroundSharedDataDirectory + let objectiveRocks = playgroundShared.appendingPathComponent("ObjectiveRocks") + try? FileManager.default.createDirectory(at: objectiveRocks, withIntermediateDirectories: true, attributes: nil) + let url = objectiveRocks.appendingPathComponent(name) + try? FileManager.default.removeItem(atPath: url.path) + return url +} + +public func iterate(db: RocksDB, title: String) { + print("--------------------------") + print(title) + let iterator = db.iterator() + iterator.enumerateKeysAndValues { (key, value, stop) in + print("\(String(data: key, encoding: .utf8)!): \(String(data: value, encoding: .utf8)!)") + } + iterator.close() +} diff --git a/ObjectiveRocks.playground/Support.remap b/ObjectiveRocks.playground/Support.remap new file mode 100644 index 0000000..0d4f101 --- /dev/null +++ b/ObjectiveRocks.playground/Support.remap @@ -0,0 +1,2 @@ +[ +] diff --git a/ObjectiveRocks.playground/contents.xcplayground b/ObjectiveRocks.playground/contents.xcplayground index 06828af..f6c3633 100644 --- a/ObjectiveRocks.playground/contents.xcplayground +++ b/ObjectiveRocks.playground/contents.xcplayground @@ -1,4 +1,12 @@ - - + + + + + + + + + + \ No newline at end of file diff --git a/ObjectiveRocks.podspec b/ObjectiveRocks.podspec index 21fe4bb..7072cf6 100644 --- a/ObjectiveRocks.podspec +++ b/ObjectiveRocks.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ObjectiveRocks' - s.version = '0.6.0' + s.version = '0.7.0' s.summary = 'Objective-C wrapper of RocksDB - A Persistent Key-Value Store for Flash and RAM Storage.' s.license = 'MIT' s.homepage = 'https://github.com/iabudiab/ObjectiveRocks' @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.social_media_url = 'https://twitter.com/_iabudiab' s.source = { :git => 'https://github.com/iabudiab/ObjectiveRocks.git', :tag => s.version, :submodules => true } - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.osx.deployment_target = '10.10' s.requires_arc = true diff --git a/ObjectiveRocks.xcodeproj/project.pbxproj b/ObjectiveRocks.xcodeproj/project.pbxproj index b28bb47..aa9db70 100644 --- a/ObjectiveRocks.xcodeproj/project.pbxproj +++ b/ObjectiveRocks.xcodeproj/project.pbxproj @@ -8,21 +8,18 @@ /* Begin PBXBuildFile section */ 620A2CAE1A3654D5007224A4 /* RocksDBMergeOperatorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620A2CAD1A3654D5007224A4 /* RocksDBMergeOperatorTests.mm */; }; - 62102D421A643A13007E63F0 /* RocksDBComparatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62102D411A643A13007E63F0 /* RocksDBComparatorTests.swift */; }; - 62102D431A643A13007E63F0 /* RocksDBComparatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62102D411A643A13007E63F0 /* RocksDBComparatorTests.swift */; }; - 6216360D1A62C9FB00B132CE /* RocksDBBasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360C1A62C9FB00B132CE /* RocksDBBasicTests.swift */; }; - 6216360E1A62C9FB00B132CE /* RocksDBBasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360C1A62C9FB00B132CE /* RocksDBBasicTests.swift */; }; - 621636101A62D1BE00B132CE /* RocksDBWriteBatchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360F1A62D1BE00B132CE /* RocksDBWriteBatchTests.swift */; }; - 621636111A62D1BE00B132CE /* RocksDBWriteBatchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360F1A62D1BE00B132CE /* RocksDBWriteBatchTests.swift */; }; - 621636131A62DF9400B132CE /* RocksDBPropertiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636121A62DF9400B132CE /* RocksDBPropertiesTests.swift */; }; - 621636151A62E47A00B132CE /* RocksDBSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636141A62E47A00B132CE /* RocksDBSnapshotTests.swift */; }; - 621636161A62E47A00B132CE /* RocksDBSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636141A62E47A00B132CE /* RocksDBSnapshotTests.swift */; }; - 621636181A631CE100B132CE /* RocksDBCheckpointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636171A631CE100B132CE /* RocksDBCheckpointTests.swift */; }; - 6216361B1A631F2900B132CE /* RocksDBStatisticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216361A1A631F2900B132CE /* RocksDBStatisticsTests.swift */; }; + 621897D51E3D3A580019C64E /* RocksDBBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E173E51A6AD40E00A00DF3 /* RocksDBBackupTests.swift */; }; + 621897D71E3D46720019C64E /* RocksDBColumnFamilyMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7B1A6AAF9A00489D6C /* RocksDBColumnFamilyMetadataTests.swift */; }; + 621897D81E3D46900019C64E /* RocksDBColumnFamilyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7D1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift */; }; + 621897D91E3D46910019C64E /* RocksDBColumnFamilyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7D1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift */; }; + 621897DA1E3D47A70019C64E /* RocksDBPrefixExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629416621A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift */; }; + 621897DB1E3D47A70019C64E /* RocksDBPrefixExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629416621A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift */; }; + 621897DC1E3D4D240019C64E /* RocksDBComparatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62102D411A643A13007E63F0 /* RocksDBComparatorTests.swift */; }; + 621897DD1E3D4D240019C64E /* RocksDBComparatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62102D411A643A13007E63F0 /* RocksDBComparatorTests.swift */; }; + 621897DE1E3D4E220019C64E /* RocksDBMergeOperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62456CBA1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift */; }; + 621897DF1E3D4E230019C64E /* RocksDBMergeOperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62456CBA1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift */; }; 621C6D971BEE4A4600044CB1 /* RocksDBStatistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 62A8B0631A58DD7D0069B4C8 /* RocksDBStatistics.h */; settings = {ATTRIBUTES = (Public, ); }; }; 621C6D981BEE4A4600044CB1 /* RocksDBStatisticsHistogram.h in Headers */ = {isa = PBXBuildFile; fileRef = 62A8B0671A58E4B60069B4C8 /* RocksDBStatisticsHistogram.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6221B7A71A629E1B00D28BF5 /* RockDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6221B7A41A629B3600D28BF5 /* RockDBTests.swift */; }; - 6221B7A81A629E2700D28BF5 /* RockDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6221B7A41A629B3600D28BF5 /* RockDBTests.swift */; }; 6236E25C1A4E19A300A81ED6 /* RocksDBPrefixExtractorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6236E25B1A4E19A300A81ED6 /* RocksDBPrefixExtractorTests.mm */; }; 62385EB41A2FCFB100493F18 /* RocksDBIteratorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62385EB31A2FCFB100493F18 /* RocksDBIteratorTests.mm */; }; 62385EB61A2FD05500493F18 /* RocksDBComparatorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62385EB51A2FD05500493F18 /* RocksDBComparatorTests.mm */; }; @@ -30,7 +27,6 @@ 624203CA1BED64F70043DD6F /* ObjectiveRocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 62AEF9B81A1D5CF000E63E89 /* ObjectiveRocks.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203CB1BED64F70043DD6F /* RocksDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 6299F80C1A17B28200123F56 /* RocksDB.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203CC1BED64F70043DD6F /* RocksDBProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 625F8F1A1A59C3EB007796BA /* RocksDBProperties.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 624203CD1BED64F70043DD6F /* RocksDBTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 62451AC81A4BAEC000AF11C8 /* RocksDBTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203CE1BED64F70043DD6F /* RocksDBError.h in Headers */ = {isa = PBXBuildFile; fileRef = 628B0CE81A1C104D0099C39B /* RocksDBError.h */; settings = {ATTRIBUTES = (Private, ); }; }; 624203CF1BED64F70043DD6F /* RocksDBColumnFamily.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629681A510D36001DEDC4 /* RocksDBColumnFamily.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203D01BED64F70043DD6F /* RocksDBColumnFamilyDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 62074F2B1A520EC2002B1885 /* RocksDBColumnFamilyDescriptor.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -42,7 +38,6 @@ 624203D61BED64F80043DD6F /* RocksDBWriteBatchIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 62F8C6011B853ABA00E2577F /* RocksDBWriteBatchIterator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203D71BED64F80043DD6F /* RocksDBComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 623224AA1A2116A400FB6625 /* RocksDBComparator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203D81BED64F80043DD6F /* RocksDBOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 62AEF9B91A1D5DA900E63E89 /* RocksDBOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 624203D91BED64F80043DD6F /* RocksDBEncodingOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629611A50ECCA001DEDC4 /* RocksDBEncodingOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203DA1BED64F80043DD6F /* RocksDBDatabaseOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629641A510056001DEDC4 /* RocksDBDatabaseOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203DB1BED64F80043DD6F /* RocksDBColumnFamilyOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6206295E1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624203DC1BED64F80043DD6F /* RocksDBWriteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6232B7331A1E80F900B14535 /* RocksDBWriteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -90,7 +85,6 @@ 624204061BED65250043DD6F /* RocksDBWriteBatchIterator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62F8C6021B853ABA00E2577F /* RocksDBWriteBatchIterator.mm */; }; 624204071BED65250043DD6F /* RocksDBComparator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 623224AB1A2116A400FB6625 /* RocksDBComparator.mm */; }; 624204081BED65250043DD6F /* RocksDBOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62AEF9BA1A1D5DA900E63E89 /* RocksDBOptions.mm */; }; - 624204091BED65250043DD6F /* RocksDBEncodingOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620629621A50ECCA001DEDC4 /* RocksDBEncodingOptions.mm */; }; 6242040A1BED65250043DD6F /* RocksDBDatabaseOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620629651A510056001DEDC4 /* RocksDBDatabaseOptions.mm */; }; 6242040B1BED65250043DD6F /* RocksDBColumnFamilyOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6206295F1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.mm */; }; 6242040C1BED65250043DD6F /* RocksDBWriteOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6232B7341A1E80F900B14535 /* RocksDBWriteOptions.mm */; }; @@ -111,19 +105,15 @@ 6242041B1BED65250043DD6F /* RocksDBStatisticsHistogram.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62A8B0681A58E4B60069B4C8 /* RocksDBStatisticsHistogram.mm */; }; 6242041C1BED65250043DD6F /* RocksDBBackupEngine.mm in Sources */ = {isa = PBXBuildFile; fileRef = 621CD71B1A4FB24700853E16 /* RocksDBBackupEngine.mm */; }; 6242041D1BED65250043DD6F /* RocksDBBackupInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62A8B0601A58CC400069B4C8 /* RocksDBBackupInfo.mm */; }; - 6242042C1BED652D0043DD6F /* RocksDBTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62451AC91A4BAEC000AF11C8 /* RocksDBTypes.mm */; }; 6242042D1BED65540043DD6F /* RocksDBCallbackComparator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62376BBD1A20EDF000C85DFB /* RocksDBCallbackComparator.cpp */; }; 6242042E1BED65540043DD6F /* RocksDBCallbackAssociativeMergeOperator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62EEC4B81A34FF0600624DA2 /* RocksDBCallbackAssociativeMergeOperator.cpp */; }; 6242042F1BED65540043DD6F /* RocksDBCallbackMergeOperator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6214FD071A3F698300B92E5C /* RocksDBCallbackMergeOperator.cpp */; }; 624204301BED65540043DD6F /* RocksDBCallbackSliceTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6236E2581A4DD71600A81ED6 /* RocksDBCallbackSliceTransform.cpp */; }; 624204CF1BED6B750043DD6F /* ObjectiveRocks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 624203C01BED64410043DD6F /* ObjectiveRocks.framework */; }; 624566C81A51DA79009AC3FB /* RocksDBColumnFamilyTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 624566C71A51DA79009AC3FB /* RocksDBColumnFamilyTests.mm */; }; - 62456CBB1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62456CBA1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift */; }; - 62456CBC1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62456CBA1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift */; }; 6249A3CC1A4A43CA00949B07 /* RocksDBTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6249A3CB1A4A43CA00949B07 /* RocksDBTests.mm */; }; 624F5DA01BEE41F500497FEF /* ObjectiveRocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 62AEF9B81A1D5CF000E63E89 /* ObjectiveRocks.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DA11BEE41F500497FEF /* RocksDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 6299F80C1A17B28200123F56 /* RocksDB.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 624F5DA31BEE41F500497FEF /* RocksDBTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 62451AC81A4BAEC000AF11C8 /* RocksDBTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DA51BEE41F500497FEF /* RocksDBColumnFamily.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629681A510D36001DEDC4 /* RocksDBColumnFamily.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DA61BEE41F500497FEF /* RocksDBColumnFamilyDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 62074F2B1A520EC2002B1885 /* RocksDBColumnFamilyDescriptor.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DA81BEE41F500497FEF /* RocksDBIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 62F8C6051B85632500E2577F /* RocksDBIterator.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -131,7 +121,6 @@ 624F5DAA1BEE41F500497FEF /* RocksDBWriteBatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 623FE74E1A2D2ED500E68421 /* RocksDBWriteBatch.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DAD1BEE41F600497FEF /* RocksDBComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 623224AA1A2116A400FB6625 /* RocksDBComparator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DAE1BEE41F600497FEF /* RocksDBOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 62AEF9B91A1D5DA900E63E89 /* RocksDBOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 624F5DAF1BEE41F600497FEF /* RocksDBEncodingOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629611A50ECCA001DEDC4 /* RocksDBEncodingOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DB01BEE41F600497FEF /* RocksDBDatabaseOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 620629641A510056001DEDC4 /* RocksDBDatabaseOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DB11BEE41F600497FEF /* RocksDBColumnFamilyOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6206295E1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DB21BEE41F600497FEF /* RocksDBWriteOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6232B7331A1E80F900B14535 /* RocksDBWriteOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -146,7 +135,6 @@ 624F5DBE1BEE41F700497FEF /* RocksDBSnapshotUnavailable.h in Headers */ = {isa = PBXBuildFile; fileRef = 628C51C71A3BD08500B96F8F /* RocksDBSnapshotUnavailable.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DC01BEE41F700497FEF /* RocksDBMergeOperator.h in Headers */ = {isa = PBXBuildFile; fileRef = 62EEC4B51A34FEE100624DA2 /* RocksDBMergeOperator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 624F5DC61BEE437C00497FEF /* RocksDB.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6299F80E1A17B28200123F56 /* RocksDB.mm */; }; - 624F5DC81BEE437C00497FEF /* RocksDBTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62451AC91A4BAEC000AF11C8 /* RocksDBTypes.mm */; }; 624F5DC91BEE437C00497FEF /* RocksDBError.mm in Sources */ = {isa = PBXBuildFile; fileRef = 628B0CE91A1C104D0099C39B /* RocksDBError.mm */; }; 624F5DCA1BEE437C00497FEF /* RocksDBColumnFamily.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620629691A510D36001DEDC4 /* RocksDBColumnFamily.mm */; }; 624F5DCB1BEE437C00497FEF /* RocksDBColumnFamilyDescriptor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62074F2C1A520EC2002B1885 /* RocksDBColumnFamilyDescriptor.mm */; }; @@ -155,7 +143,6 @@ 624F5DCF1BEE437C00497FEF /* RocksDBWriteBatch.mm in Sources */ = {isa = PBXBuildFile; fileRef = 623FE74F1A2D2ED500E68421 /* RocksDBWriteBatch.mm */; }; 624F5DD21BEE437C00497FEF /* RocksDBComparator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 623224AB1A2116A400FB6625 /* RocksDBComparator.mm */; }; 624F5DD31BEE437C00497FEF /* RocksDBOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62AEF9BA1A1D5DA900E63E89 /* RocksDBOptions.mm */; }; - 624F5DD41BEE437C00497FEF /* RocksDBEncodingOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620629621A50ECCA001DEDC4 /* RocksDBEncodingOptions.mm */; }; 624F5DD51BEE437C00497FEF /* RocksDBDatabaseOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620629651A510056001DEDC4 /* RocksDBDatabaseOptions.mm */; }; 624F5DD61BEE437C00497FEF /* RocksDBColumnFamilyOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6206295F1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.mm */; }; 624F5DD71BEE437C00497FEF /* RocksDBWriteOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6232B7341A1E80F900B14535 /* RocksDBWriteOptions.mm */; }; @@ -188,17 +175,30 @@ 624F5EE41BEE456200497FEF /* RocksDBCallbackSliceTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = 6236E2591A4DD71600A81ED6 /* RocksDBCallbackSliceTransform.h */; settings = {ATTRIBUTES = (Private, ); }; }; 624F5EE51BEE456200497FEF /* RocksDBSlice.h in Headers */ = {isa = PBXBuildFile; fileRef = 623D3C201A37C4FF00389207 /* RocksDBSlice.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6251A3731B783DA7009BABD5 /* RocksDBReadOnlyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6251A3721B783DA7009BABD5 /* RocksDBReadOnlyTests.m */; }; - 6251A3751B783DBC009BABD5 /* RocksDBReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6251A3741B783DBC009BABD5 /* RocksDBReadOnlyTests.swift */; }; 625EF4971D0C3A960058ACDA /* RocksDBRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 625EF4951D0C3A960058ACDA /* RocksDBRange.h */; settings = {ATTRIBUTES = (Public, ); }; }; 625EF4981D0C3A960058ACDA /* RocksDBRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 625EF4951D0C3A960058ACDA /* RocksDBRange.h */; settings = {ATTRIBUTES = (Public, ); }; }; 625EF4991D0C3A960058ACDA /* RocksDBRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 625EF4961D0C3A960058ACDA /* RocksDBRange.mm */; }; 625EF49A1D0C3A960058ACDA /* RocksDBRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 625EF4961D0C3A960058ACDA /* RocksDBRange.mm */; }; 625F8F1F1A59C9B3007796BA /* RocksDBPropertiesTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 625F8F1E1A59C9B3007796BA /* RocksDBPropertiesTests.mm */; }; 625F8F251A59D11D007796BA /* RocksDBCheckpointTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 625F8F241A59D11D007796BA /* RocksDBCheckpointTests.mm */; }; + 6261599F1E3D0B6200288079 /* RockDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6221B7A41A629B3600D28BF5 /* RockDBTests.swift */; }; + 626159A01E3D0B6200288079 /* RocksDBBasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360C1A62C9FB00B132CE /* RocksDBBasicTests.swift */; }; + 626159A11E3D0B6200288079 /* RocksDBReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6251A3741B783DBC009BABD5 /* RocksDBReadOnlyTests.swift */; }; + 626159A21E3D0B6200288079 /* RocksDBWriteBatchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360F1A62D1BE00B132CE /* RocksDBWriteBatchTests.swift */; }; + 626159A31E3D0B6300288079 /* RocksDBIndexedWriteBatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62662E951B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift */; }; + 626159A41E3D0B6300288079 /* RockDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6221B7A41A629B3600D28BF5 /* RockDBTests.swift */; }; + 626159A51E3D0B6300288079 /* RocksDBBasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360C1A62C9FB00B132CE /* RocksDBBasicTests.swift */; }; + 626159A71E3D0B6300288079 /* RocksDBWriteBatchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216360F1A62D1BE00B132CE /* RocksDBWriteBatchTests.swift */; }; + 626159A81E3D0B6300288079 /* RocksDBIndexedWriteBatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62662E951B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift */; }; + 626159A91E3D0B9200288079 /* RocksDBIteratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A37D131A632316003F6095 /* RocksDBIteratorTests.swift */; }; + 626159AA1E3D0B9200288079 /* RocksDBIteratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A37D131A632316003F6095 /* RocksDBIteratorTests.swift */; }; + 626159AD1E3D12CD00288079 /* RocksDBSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636141A62E47A00B132CE /* RocksDBSnapshotTests.swift */; }; + 626159AE1E3D12CE00288079 /* RocksDBSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636141A62E47A00B132CE /* RocksDBSnapshotTests.swift */; }; + 626159AF1E3D131200288079 /* RocksDBCheckpointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636171A631CE100B132CE /* RocksDBCheckpointTests.swift */; }; + 626159B11E3D135E00288079 /* RocksDBPropertiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621636121A62DF9400B132CE /* RocksDBPropertiesTests.swift */; }; + 626159B21E3D139500288079 /* RocksDBStatisticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6216361A1A631F2900B132CE /* RocksDBStatisticsTests.swift */; }; 62662E931B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 62662E921B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m */; }; 62662E941B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 62662E921B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m */; }; - 62662E961B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62662E951B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift */; }; - 62662E971B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62662E951B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift */; }; 62685CB91A2E600A009401B1 /* RocksDBWriteBatchTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62685CB81A2E600A009401B1 /* RocksDBWriteBatchTests.mm */; }; 6273A50E1D0C646C00CF8BF1 /* RocksDBCompactRangeOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6273A50C1D0C646C00CF8BF1 /* RocksDBCompactRangeOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6273A50F1D0C646C00CF8BF1 /* RocksDBCompactRangeOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6273A50C1D0C646C00CF8BF1 /* RocksDBCompactRangeOptions.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -997,11 +997,7 @@ 628B50EA1D03125A00E2D828 /* write_batch_with_index_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 628B4AA41D03125900E2D828 /* write_batch_with_index_internal.h */; }; 628B50EB1D03125A00E2D828 /* write_batch_with_index_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 628B4AA41D03125900E2D828 /* write_batch_with_index_internal.h */; }; 628CEBBB1D0CF4630096AA64 /* RocksDBIndexedWriteBatch+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 628CEBB91D0CF4630096AA64 /* RocksDBIndexedWriteBatch+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 629416631A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629416621A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift */; }; - 629416641A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629416621A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift */; }; 6299F8561A17B7AD00123F56 /* RocksDBBasicTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6299F8551A17B7AD00123F56 /* RocksDBBasicTests.mm */; }; - 62A37D141A632316003F6095 /* RocksDBIteratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A37D131A632316003F6095 /* RocksDBIteratorTests.swift */; }; - 62A37D151A632316003F6095 /* RocksDBIteratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A37D131A632316003F6095 /* RocksDBIteratorTests.swift */; }; 62A8B0481A58C40A0069B4C8 /* RocksDBBasicTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6299F8551A17B7AD00123F56 /* RocksDBBasicTests.mm */; }; 62A8B0491A58C40A0069B4C8 /* RocksDBTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6249A3CB1A4A43CA00949B07 /* RocksDBTests.mm */; }; 62A8B04A1A58C40A0069B4C8 /* RocksDBColumnFamilyTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 624566C71A51DA79009AC3FB /* RocksDBColumnFamilyTests.mm */; }; @@ -1012,10 +1008,6 @@ 62A8B04F1A58C40A0069B4C8 /* RocksDBWriteBatchTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62685CB81A2E600A009401B1 /* RocksDBWriteBatchTests.mm */; }; 62A8B0501A58C40A0069B4C8 /* RocksDBMergeOperatorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 620A2CAD1A3654D5007224A4 /* RocksDBMergeOperatorTests.mm */; }; 62A8B06B1A5900540069B4C8 /* RocksDBStatisticsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62A8B06A1A5900540069B4C8 /* RocksDBStatisticsTests.mm */; }; - 62E173E61A6AD40E00A00DF3 /* RocksDBBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E173E51A6AD40E00A00DF3 /* RocksDBBackupTests.swift */; }; - 62F4AA7C1A6AAF9A00489D6C /* RocksDBColumnFamilyMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7B1A6AAF9A00489D6C /* RocksDBColumnFamilyMetadataTests.swift */; }; - 62F4AA7E1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7D1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift */; }; - 62F4AA7F1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62F4AA7D1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift */; }; 62F4AA801A6AAFE500489D6C /* RocksDBColumnFamilyMetadataTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 627FBE761A61E0AA0038696A /* RocksDBColumnFamilyMetadataTests.mm */; }; 62FC8B471A565B19003DF5C6 /* RocksDBBackupTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 62FC8B461A565B19003DF5C6 /* RocksDBBackupTests.mm */; }; /* End PBXBuildFile section */ @@ -1042,8 +1034,6 @@ 620494861A3284A800A0E950 /* RocksDBSnapshot.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBSnapshot.mm; sourceTree = ""; }; 6206295E1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocksDBColumnFamilyOptions.h; sourceTree = ""; }; 6206295F1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBColumnFamilyOptions.mm; sourceTree = ""; }; - 620629611A50ECCA001DEDC4 /* RocksDBEncodingOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocksDBEncodingOptions.h; sourceTree = ""; }; - 620629621A50ECCA001DEDC4 /* RocksDBEncodingOptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBEncodingOptions.mm; sourceTree = ""; }; 620629641A510056001DEDC4 /* RocksDBDatabaseOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocksDBDatabaseOptions.h; sourceTree = ""; }; 620629651A510056001DEDC4 /* RocksDBDatabaseOptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBDatabaseOptions.mm; sourceTree = ""; }; 620629681A510D36001DEDC4 /* RocksDBColumnFamily.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocksDBColumnFamily.h; sourceTree = ""; }; @@ -1096,8 +1086,6 @@ 623FE74F1A2D2ED500E68421 /* RocksDBWriteBatch.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBWriteBatch.mm; sourceTree = ""; }; 624203C01BED64410043DD6F /* ObjectiveRocks.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjectiveRocks.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 624203C81BED64AE0043DD6F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Framework/Info.plist; sourceTree = SOURCE_ROOT; }; - 62451AC81A4BAEC000AF11C8 /* RocksDBTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocksDBTypes.h; sourceTree = ""; }; - 62451AC91A4BAEC000AF11C8 /* RocksDBTypes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBTypes.mm; sourceTree = ""; }; 624566C71A51DA79009AC3FB /* RocksDBColumnFamilyTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBColumnFamilyTests.mm; sourceTree = ""; }; 62456CBA1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RocksDBMergeOperatorTests.swift; sourceTree = ""; }; 6249A3CB1A4A43CA00949B07 /* RocksDBTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RocksDBTests.mm; sourceTree = ""; }; @@ -1663,6 +1651,15 @@ name = Swift; sourceTree = ""; }; + 621897E01E3D7AD10019C64E /* Properties */ = { + isa = PBXGroup; + children = ( + 625F8F1A1A59C3EB007796BA /* RocksDBProperties.h */, + 625F8F1B1A59C3EB007796BA /* RocksDBProperties.mm */, + ); + name = Properties; + sourceTree = ""; + }; 621CD7191A4FB22C00853E16 /* Backup */ = { isa = PBXGroup; children = ( @@ -1696,8 +1693,6 @@ children = ( 62AEF9B91A1D5DA900E63E89 /* RocksDBOptions.h */, 62AEF9BA1A1D5DA900E63E89 /* RocksDBOptions.mm */, - 620629611A50ECCA001DEDC4 /* RocksDBEncodingOptions.h */, - 620629621A50ECCA001DEDC4 /* RocksDBEncodingOptions.mm */, 620629641A510056001DEDC4 /* RocksDBDatabaseOptions.h */, 620629651A510056001DEDC4 /* RocksDBDatabaseOptions.mm */, 6206295E1A509DF1001DEDC4 /* RocksDBColumnFamilyOptions.h */, @@ -2481,10 +2476,6 @@ 6299F80E1A17B28200123F56 /* RocksDB.mm */, 625EF4951D0C3A960058ACDA /* RocksDBRange.h */, 625EF4961D0C3A960058ACDA /* RocksDBRange.mm */, - 625F8F1A1A59C3EB007796BA /* RocksDBProperties.h */, - 625F8F1B1A59C3EB007796BA /* RocksDBProperties.mm */, - 62451AC81A4BAEC000AF11C8 /* RocksDBTypes.h */, - 62451AC91A4BAEC000AF11C8 /* RocksDBTypes.mm */, 628B0CE81A1C104D0099C39B /* RocksDBError.h */, 628B0CE91A1C104D0099C39B /* RocksDBError.mm */, 620629671A510D24001DEDC4 /* Column Family */, @@ -2492,6 +2483,7 @@ 62685CBA1A2E8257009401B1 /* Write Batch */, 620494841A32809400A0E950 /* Comparator */, 62269EE21A200CD9005A58D3 /* Options */, + 621897E01E3D7AD10019C64E /* Properties */, 623DC2541A335B9300B61B18 /* Snapshot */, 62EEC4B41A34FEC500624DA2 /* Merge Operator */, 62A8B0621A58DD620069B4C8 /* Statistics */, @@ -2608,7 +2600,6 @@ 628B4C621D03125900E2D828 /* experimental.h in Headers */, 628B4E481D03125900E2D828 /* stack_trace.h in Headers */, 628B4EB81D03125A00E2D828 /* merger.h in Headers */, - 624203CD1BED64F70043DD6F /* RocksDBTypes.h in Headers */, 628B4CAE1D03125900E2D828 /* json_document.h in Headers */, 628B50B41D03125A00E2D828 /* utils.h in Headers */, 628B4BAC1D03125900E2D828 /* managed_iterator.h in Headers */, @@ -2661,7 +2652,6 @@ 628B50BE1D03125A00E2D828 /* optimistic_transaction_db_impl.h in Headers */, 628B4C9E1D03125900E2D828 /* checkpoint.h in Headers */, 628B4EA61D03125A00E2D828 /* full_filter_block.h in Headers */, - 624203D91BED64F80043DD6F /* RocksDBEncodingOptions.h in Headers */, 628B4F601D03125A00E2D828 /* allocator.h in Headers */, 628B4BEC1D03125900E2D828 /* transaction_log_impl.h in Headers */, 628B4C721D03125900E2D828 /* memtablerep.h in Headers */, @@ -2887,7 +2877,6 @@ 628B4B851D03125900E2D828 /* flush_job.h in Headers */, 624F5DA11BEE41F500497FEF /* RocksDB.h in Headers */, 628B4B8F1D03125900E2D828 /* forward_iterator.h in Headers */, - 624F5DA31BEE41F500497FEF /* RocksDBTypes.h in Headers */, 628B50491D03125A00E2D828 /* thread_operation.h in Headers */, 628B4FFD1D03125A00E2D828 /* options_helper.h in Headers */, 628B4BE31D03125900E2D828 /* table_cache.h in Headers */, @@ -2949,7 +2938,6 @@ 628B4E271D03125900E2D828 /* hash_cuckoo_rep.h in Headers */, 628B50371D03125A00E2D828 /* sync_point.h in Headers */, 628B4FBF1D03125A00E2D828 /* heap.h in Headers */, - 624F5DAF1BEE41F600497FEF /* RocksDBEncodingOptions.h in Headers */, 628B4C911D03125900E2D828 /* table.h in Headers */, 628B4C0B1D03125900E2D828 /* write_batch_internal.h in Headers */, 628B4C671D03125900E2D828 /* flush_block_policy.h in Headers */, @@ -3230,7 +3218,7 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = BrainCookie; TargetAttributes = { 624203BF1BED64410043DD6F = { @@ -3241,6 +3229,7 @@ }; 6299F8131A17B28200123F56 = { CreatedOnToolsVersion = 6.1; + LastSwiftMigration = 0820; }; }; }; @@ -3335,7 +3324,6 @@ 628B50801D03125A00E2D828 /* flashcache.cc in Sources */, 624203FC1BED65250043DD6F /* RocksDB.mm in Sources */, 628B4B7C1D03125900E2D828 /* filename.cc in Sources */, - 6242042C1BED652D0043DD6F /* RocksDBTypes.mm in Sources */, 628B4C181D03125900E2D828 /* write_thread.cc in Sources */, 628B4EB21D03125A00E2D828 /* iterator.cc in Sources */, 628B508A1D03125A00E2D828 /* leveldb_options.cc in Sources */, @@ -3386,7 +3374,6 @@ 628B50C01D03125A00E2D828 /* optimistic_transaction_impl.cc in Sources */, 628B4FA61D03125A00E2D828 /* event_logger.cc in Sources */, 628B4BAA1D03125900E2D828 /* managed_iterator.cc in Sources */, - 624204091BED65250043DD6F /* RocksDBEncodingOptions.mm in Sources */, 628B508E1D03125A00E2D828 /* memory_util.cc in Sources */, 628B4ED01D03125A00E2D828 /* plain_table_key_coding.cc in Sources */, 6242040A1BED65250043DD6F /* RocksDBDatabaseOptions.mm in Sources */, @@ -3547,7 +3534,6 @@ 628B4E251D03125900E2D828 /* hash_cuckoo_rep.cc in Sources */, 624F5DC61BEE437C00497FEF /* RocksDB.mm in Sources */, 628B505D1D03125A00E2D828 /* xfunc.cc in Sources */, - 624F5DC81BEE437C00497FEF /* RocksDBTypes.mm in Sources */, 628B502D1D03125A00E2D828 /* status_message.cc in Sources */, 628B4E631D03125900E2D828 /* block.cc in Sources */, 628B4F8D1D03125A00E2D828 /* crc32c.cc in Sources */, @@ -3612,7 +3598,6 @@ 628B50851D03125A00E2D828 /* geodb_impl.cc in Sources */, 628B4FC31D03125A00E2D828 /* histogram.cc in Sources */, 628B50D31D03125A00E2D828 /* transaction_impl.cc in Sources */, - 624F5DD41BEE437C00497FEF /* RocksDBEncodingOptions.mm in Sources */, 624F5DD51BEE437C00497FEF /* RocksDBDatabaseOptions.mm in Sources */, 628B4E291D03125900E2D828 /* hash_linklist_rep.cc in Sources */, 628B4FD11D03125A00E2D828 /* iostats_context.cc in Sources */, @@ -3749,38 +3734,38 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 62456CBB1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift in Sources */, 62F4AA801A6AAFE500489D6C /* RocksDBColumnFamilyMetadataTests.mm in Sources */, + 626159B21E3D139500288079 /* RocksDBStatisticsTests.swift in Sources */, 6299F8561A17B7AD00123F56 /* RocksDBBasicTests.mm in Sources */, - 62F4AA7E1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift in Sources */, - 62A37D141A632316003F6095 /* RocksDBIteratorTests.swift in Sources */, - 629416631A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift in Sources */, - 6216361B1A631F2900B132CE /* RocksDBStatisticsTests.swift in Sources */, 62FC8B471A565B19003DF5C6 /* RocksDBBackupTests.mm in Sources */, - 62E173E61A6AD40E00A00DF3 /* RocksDBBackupTests.swift in Sources */, + 626159A21E3D0B6200288079 /* RocksDBWriteBatchTests.swift in Sources */, 6251A3731B783DA7009BABD5 /* RocksDBReadOnlyTests.m in Sources */, - 62102D421A643A13007E63F0 /* RocksDBComparatorTests.swift in Sources */, - 62F4AA7C1A6AAF9A00489D6C /* RocksDBColumnFamilyMetadataTests.swift in Sources */, - 6251A3751B783DBC009BABD5 /* RocksDBReadOnlyTests.swift in Sources */, - 6221B7A71A629E1B00D28BF5 /* RockDBTests.swift in Sources */, - 621636181A631CE100B132CE /* RocksDBCheckpointTests.swift in Sources */, - 62662E961B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift in Sources */, 625F8F251A59D11D007796BA /* RocksDBCheckpointTests.mm in Sources */, 6249A3CC1A4A43CA00949B07 /* RocksDBTests.mm in Sources */, 62A8B06B1A5900540069B4C8 /* RocksDBStatisticsTests.mm in Sources */, + 626159A91E3D0B9200288079 /* RocksDBIteratorTests.swift in Sources */, 624566C81A51DA79009AC3FB /* RocksDBColumnFamilyTests.mm in Sources */, + 626159AF1E3D131200288079 /* RocksDBCheckpointTests.swift in Sources */, 62662E931B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m in Sources */, + 626159A01E3D0B6200288079 /* RocksDBBasicTests.swift in Sources */, 62385EB41A2FCFB100493F18 /* RocksDBIteratorTests.mm in Sources */, - 621636151A62E47A00B132CE /* RocksDBSnapshotTests.swift in Sources */, + 621897DA1E3D47A70019C64E /* RocksDBPrefixExtractorTests.swift in Sources */, + 626159B11E3D135E00288079 /* RocksDBPropertiesTests.swift in Sources */, + 621897DE1E3D4E220019C64E /* RocksDBMergeOperatorTests.swift in Sources */, 62385EB61A2FD05500493F18 /* RocksDBComparatorTests.mm in Sources */, + 621897D71E3D46720019C64E /* RocksDBColumnFamilyMetadataTests.swift in Sources */, + 6261599F1E3D0B6200288079 /* RockDBTests.swift in Sources */, + 626159A31E3D0B6300288079 /* RocksDBIndexedWriteBatch.swift in Sources */, + 626159A11E3D0B6200288079 /* RocksDBReadOnlyTests.swift in Sources */, + 621897D51E3D3A580019C64E /* RocksDBBackupTests.swift in Sources */, 625F8F1F1A59C9B3007796BA /* RocksDBPropertiesTests.mm in Sources */, 623DC2561A335BAF00B61B18 /* RocksDBSnapshotTests.mm in Sources */, 6236E25C1A4E19A300A81ED6 /* RocksDBPrefixExtractorTests.mm in Sources */, - 621636131A62DF9400B132CE /* RocksDBPropertiesTests.swift in Sources */, - 6216360D1A62C9FB00B132CE /* RocksDBBasicTests.swift in Sources */, + 621897D81E3D46900019C64E /* RocksDBColumnFamilyTests.swift in Sources */, 62685CB91A2E600A009401B1 /* RocksDBWriteBatchTests.mm in Sources */, 620A2CAE1A3654D5007224A4 /* RocksDBMergeOperatorTests.mm in Sources */, - 621636101A62D1BE00B132CE /* RocksDBWriteBatchTests.swift in Sources */, + 626159AD1E3D12CD00288079 /* RocksDBSnapshotTests.swift in Sources */, + 621897DC1E3D4D240019C64E /* RocksDBComparatorTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3788,26 +3773,26 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 62F4AA7F1A6AAFD700489D6C /* RocksDBColumnFamilyTests.swift in Sources */, - 6221B7A81A629E2700D28BF5 /* RockDBTests.swift in Sources */, - 62456CBC1A66FE0500329F11 /* RocksDBMergeOperatorTests.swift in Sources */, - 62662E971B8FCBA0008B4EF5 /* RocksDBIndexedWriteBatch.swift in Sources */, + 621897DF1E3D4E230019C64E /* RocksDBMergeOperatorTests.swift in Sources */, 62A8B0481A58C40A0069B4C8 /* RocksDBBasicTests.mm in Sources */, 62A8B0491A58C40A0069B4C8 /* RocksDBTests.mm in Sources */, - 62102D431A643A13007E63F0 /* RocksDBComparatorTests.swift in Sources */, + 621897DB1E3D47A70019C64E /* RocksDBPrefixExtractorTests.swift in Sources */, + 621897DD1E3D4D240019C64E /* RocksDBComparatorTests.swift in Sources */, 62662E941B8FCA8C008B4EF5 /* RocksDBIndexedWriteBatchTests.m in Sources */, - 621636161A62E47A00B132CE /* RocksDBSnapshotTests.swift in Sources */, - 629416641A69DFB000AA0498 /* RocksDBPrefixExtractorTests.swift in Sources */, - 621636111A62D1BE00B132CE /* RocksDBWriteBatchTests.swift in Sources */, + 621897D91E3D46910019C64E /* RocksDBColumnFamilyTests.swift in Sources */, + 626159A51E3D0B6300288079 /* RocksDBBasicTests.swift in Sources */, + 626159AE1E3D12CE00288079 /* RocksDBSnapshotTests.swift in Sources */, 62A8B04A1A58C40A0069B4C8 /* RocksDBColumnFamilyTests.mm in Sources */, 62A8B04B1A58C40A0069B4C8 /* RocksDBIteratorTests.mm in Sources */, 62A8B04C1A58C40A0069B4C8 /* RocksDBComparatorTests.mm in Sources */, - 62A37D151A632316003F6095 /* RocksDBIteratorTests.swift in Sources */, + 626159A81E3D0B6300288079 /* RocksDBIndexedWriteBatch.swift in Sources */, 62A8B04D1A58C40A0069B4C8 /* RocksDBSnapshotTests.mm in Sources */, + 626159AA1E3D0B9200288079 /* RocksDBIteratorTests.swift in Sources */, + 626159A71E3D0B6300288079 /* RocksDBWriteBatchTests.swift in Sources */, 62A8B04E1A58C40A0069B4C8 /* RocksDBPrefixExtractorTests.mm in Sources */, - 6216360E1A62C9FB00B132CE /* RocksDBBasicTests.swift in Sources */, 62A8B04F1A58C40A0069B4C8 /* RocksDBWriteBatchTests.mm in Sources */, 62A8B0501A58C40A0069B4C8 /* RocksDBMergeOperatorTests.mm in Sources */, + 626159A41E3D0B6300288079 /* RockDBTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3916,7 +3901,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; @@ -3940,7 +3925,7 @@ ); INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -3959,7 +3944,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -3984,7 +3969,7 @@ ); INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -4012,8 +3997,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -4021,6 +4008,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -4053,14 +4041,17 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -4070,6 +4061,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -4077,10 +4069,10 @@ 6299F8211A17B28200123F56 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -4088,38 +4080,46 @@ ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_LDFLAGS = ""; + OTHER_LDFLAGS = ( + "-all_load", + "-ObjC", + ); PRODUCT_BUNDLE_IDENTIFIER = "co.braincookie.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ObjectiveRocksTests; SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/ObjectiveRocksTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 6299F8221A17B28200123F56 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_LDFLAGS = ""; + OTHER_LDFLAGS = ( + "-all_load", + "-ObjC", + ); PRODUCT_BUNDLE_IDENTIFIER = "co.braincookie.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ObjectiveRocksTests; SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/ObjectiveRocksTests-Bridging-Header.h"; + SWIFT_VERSION = 3.0; }; name = Release; }; 62A8B0551A58C40A0069B4C8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -4135,14 +4135,15 @@ PRODUCT_NAME = "ObjectiveRocksTests-iOS"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/ObjectiveRocksTests-iOS-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 62A8B0561A58C40A0069B4C8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_PREPROCESSOR_DEFINITIONS = ( "OS_MACOSX=1", @@ -4156,6 +4157,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "co.braincookie.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "ObjectiveRocksTests-iOS"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/ObjectiveRocksTests-iOS-Bridging-Header.h"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/ObjectiveRocks.xcodeproj/xcshareddata/xcschemes/ObjectiveRocks-iOS.xcscheme b/ObjectiveRocks.xcodeproj/xcshareddata/xcschemes/ObjectiveRocks-iOS.xcscheme index 7cc7bc9..62dfb68 100644 --- a/ObjectiveRocks.xcodeproj/xcshareddata/xcschemes/ObjectiveRocks-iOS.xcscheme +++ b/ObjectiveRocks.xcodeproj/xcshareddata/xcschemes/ObjectiveRocks-iOS.xcscheme @@ -1,6 +1,6 @@ [![License MIT](https://img.shields.io/badge/license-MIT-4481C7.svg?style=flat)](https://opensource.org/licenses/MIT) -#Quick Overview +- [Quick Overview](#overview) +- [Installation](#installation) +- [Usage](#usage) +- [Open & Close a DB Instance](#open--close-a-db-instance) +- [Basic Operations](#basic-operations) +- [Iteration](#iteration) +- [Column Families](#column-families) +- [Atomic Updates](#atomic-updates) +- [Snapshot](#snapshot) +- [Checkpoint](#checkpoint) +- [Keys Comparator](#keys-comparator) +- [Merge Operator](#merge-operator) +- [Env & Thread Status](#env--thread-status) +- [Backup & Restore](#backup--restore) +- [Statistics](#statistics) +- [Properties](#properties) +- [Configuration](#configuration) + +# Quick Overview RocksDB is a key-value store, where the keys and values are arbitrarily-sized byte streams. The keys are ordered within the key value store according to a specified comparator function. RocksDB supports atomic reads and writes, snapshots, iteration and features many configuration options. @@ -47,9 +65,9 @@ ObjectiveRocks has a pure Objective-C interface and can be used in Swift project ## RocksDB Lite -ObjectiveRocks incldues two targets, for iOS and OSX. The iOS target builds the RocksDB Lite version, which doesn't include the complete feature set. +ObjectiveRocks incldues two targets, for iOS and macOS. The iOS target builds the RocksDB Lite version, which doesn't include the complete feature set. -These features are only available in OSX: +These features are only available in macOS: * Column Family Metadata * Write Batch with Index @@ -60,13 +78,51 @@ These features are only available in OSX: * Database Properties * Thread Status -## Installation +# Installation -Clone the repository and add ObjectiveRocks as a sub-project in Xcode. Notice that ObjectiveRocks depends on RocksDB and includes it as a Git submodule. +## Carthage + +[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. + +If you don't have Carthage yet, you can install it with Homebrew using the following command: + +```bash +$ brew update +$ brew install carthage +``` + +To add `ObjectiveRocks` as a dependency into your project using Carthage just add the following line in your `Cartfile`: + +``` +github "iabudiab/ObjectiveRocks" +``` + +Then run the following command to build the framework and drag the built `ObjectiveRocks.framework` into your Xcode project. + +```bash +$ carthage update +``` + +## Manually + +1- Add `ObjectiveRocks` as git submodule + +```bash +$ git submodule add https://github.com/iabudiab/ObjectiveRocks.git +``` + +2- Open the `ObjectiveRocks` folder and drag'n'drop the `ObjectiveRocks.xcodeproj` into the Project Navigator in Xcode to add it as a sub-project. + +3- In the General panel of your target add `ObjectiveRocks.framework` under the `Embedded Binaries` + +> Notice that ObjectiveRocks depends on RocksDB and includes it as a Git submodule. # Usage -## Open and close a database +> The README will use the `NSString` notation in place of `NSData` keys and values for brevity! + + +## Open & close a DB instance To open a database you have to specify its location: @@ -76,18 +132,15 @@ RocksDB *db = [RocksDB databaseAtPath:@"path/to/db"]; [db close]; ``` -RocksDB features many configuration settings, that can be specified when opening the database. ObjectiveRocks offers a blocks-based initializer for this purpose, for example: +`RocksDB` features many configuration settings, that can be specified when opening the database. `ObjectiveRocks` offers a blocks-based initializer for this purpose. The minimum configuration that you'll need is `createIfMissing` in order to create a new database if it doesn't already exist: ```objective-c RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; - options.maxOpenFiles = 3000; - options.writeBufferSize = 64 * 1024 * 1024; - options.maxWriteBufferNumber = 3; }]; ``` -The [configuration guide](#configuration), *currently in progress*, lists all currently available options along with their description. +The [configuration guide](#configuration), lists all currently available options along with their description. A more production ready setup could look like this: @@ -113,51 +166,9 @@ RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOption }]; ``` -## Open Column Families - -Once you have a `RocksDB` instance you can create and drop column families on the fly: - -```objective-c -RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:...]; - -RocksDBColumnFamily *columnFamily = [db createColumnFamilyWithName:@"new_column_family" andOptions:^(RocksDBColumnFamilyOptions *options) { - // Options for the new column family -}; -// Do stuff with columnFamily and close it when you're done -[columnFamily close]; - -// To drop it -[columnFamily drop]; -``` - -> Notice that the `RocksDBColumnFamily` is a subclass of `RocksDB` - -If the database already contains Column Families other than the default, then you need to specify all Column Families that currently exist in the database when opening it, including the default one. You specify the Column Families using a `RocksDBColumnFamiliesDescriptor` object: - -```objective-c -RocksDBColumnFamilyDescriptor *descriptor = [RocksDBColumnFamilyDescriptor new]; - -[descriptor addColumnFamilyWithName:@"default" andOptions:^(RocksDBColumnFamilyOptions *options) { - // Options for the default column family -}]; -[descriptor addColumnFamilyWithName:@"stuff_column_family" andOptions:^(RocksDBColumnFamilyOptions *options) { - // Options for the stuff_column_family -}]; - -RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" columnFamilies:descriptor andDatabaseOptions:^(RocksDBDatabaseOptions *options) { - // Database options here -}]; - -NSArray *columnFamilies = db.columnFamilies; -RocksDBColumnFamily *defaultColumnFamily = columnFamilies[0]; -RocksDBColumnFamily *stuffColumnFamily = columnFamilies[1]; -// At this point you can either use the db instance or -// the defaultColumnFamily instance to access the default column family -``` - ## Basic Operations -The database provides three basic methods, `Put`, `Get`, and `Delete` to store/query data. Keys and values in RocksDB are arbitrary byte arrays: +The database provides three basic operations, `Put`, `Get`, and `Delete` to store/query data. Keys and values in RocksDB are arbitrary byte arrays: ```objective-c RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOptions *options) { @@ -172,66 +183,6 @@ NSData *get = [db getDataForKey:key]; [db deleteDataForKey:key]; ``` -## Key-Value Encoding/Decoding - -Since working with `NSData` objects is cumbersome, ObjectiveRocks offers an easy mechanism to encode/decode arbitrary objects to/from `NSData`. For example, if you have `NSString` keys and `NSDictionary` objects, you could define your own conversion blocks like this: - - -```objective-c -RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - - options.keyEncoder = ^NSData * (id key) { - return [key dataUsingEncoding:NSUTF8StringEncoding]; - }; - options.keyDecoder = ^id (NSData *data) { - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - }; - options.valueEncoder = ^NSData * (id key, id value) { - return [NSJSONSerialization dataWithJSONObject:value - options:0 - error:nil]; - }; - options.valueDecoder = ^id (id key, NSData *data) { - return [NSJSONSerialization JSONObjectWithData:data - options:NSJSONReadingMutableContainers - error:nil]; - }; -}]; - -NSDictionary *object = @{@"Objective": @"Rocks"}; - -[db setObject:object forKey:@"Hello"]; -NSMutableDictionary *dictionary = [db objectForKey:@"Hello"]; -[db deleteObjectForKey:@"Hello"]; -``` - -The `valueEncoder` and `valueDecoder` blocks take the `key` as first parameter to allow for multiplexing the conversion, i.e. storing different kinds of objects depending on the given `key`. - -## Built-In Encoding Types - -ObjectiveRocks provides built-in support for some common key/value types. So the previous example can be written like this: - -```objective-c -RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSJSONSerializable; -}]; -``` - -The following types are currently supported: - -* `RocksDBTypeNSString` for NSString keys/values -* `RocksDBTypeNSJSONSerializable` for keys/values that can be serialized via `NSJSONSerialization`, i.e. all object that have the following properties: - * The top level object is an NSArray or NSDictionary. - * All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull. - * All dictionary keys are instances of NSString. - * Numbers are not NaN or infinity. - -> All further examples will use the `id`-based API assuming that the key-value encoders are in place - ### Read & Write Errors Database operations can be passed a `NSError` reference to check for any errors that have occurred: @@ -240,8 +191,8 @@ Database operations can be passed a `NSError` reference to check for any errors NSError *error = nil; [db setObject:object forKey:key error:&error]; -NSMutableDictionary *dictionary = [db objectForKey:@"Hello" error:&error]; -[db deleteObjectForKey:@"Hello" error:&error]; +NSMutableDictionary *dictionary = [db dataForKey:@"Hello" error:&error]; +[db deleteDataForKey:@"Hello" error:&error]; ``` ### Read & Write Options @@ -256,7 +207,7 @@ Each single read or write operation can be tuned via specific options: writeOptions.ignoreMissingColumnFamilies = NO; }]; -[db objectForKey:aKey readOptions:^(RocksDBReadOptions *readOptions) { +[db dataForKey:aKey readOptions:^(RocksDBReadOptions *readOptions) { readOptions.verifyChecksums = YES; readOptions.fillCache = NO; }]; @@ -276,65 +227,6 @@ Default options can also be set on a `RocksDB` or `RocksDBColumnFamily` instance You can read about the read and write options in the [configuration guide](#configuration) -## Atomic Updates - -You can atomically apply a set of updates to the database using a `WriteBatch`. There are two ways to use a `WriteBatch`: - -* An inline block-based approach: - -```objective-c -[db setObject:@"Value 1" forKey:@"Key 1"]; - -[db performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *writeOptions) { - [batch setObject:@"Value 2" forKey:@"Key 2"]; - [batch setObject:@"Value 3" forKey:@"Key 3"]; - [batch deleteObjectForKey:@"Key 1"]; -}]; -``` - -* Via a `WriteBatch` instance, which may be more flexible for "scattered" logic: - -```objective-c -[db setObject:@"Value 1" forKey:@"Key 1"]; - -RocksDBWriteBatch *batch = [db writeBatch]; -[batch setObject:@"Value 2" forKey:@"Key 2"]; -[batch setObject:@"Value 3" forKey:@"Key 3"]; -[batch deleteObjectForKey:@"Key 1"]; -... -[db applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { - // Write options here -}]; -``` - -The Write Batch object operates per default on the Column Family associated with the DB instance, which was used to create it. However, you can also specify the Column Family in a Write Batch associated with another one, in order to achieve an atomic write across multiple Column Families. In this case it doesn't matter on which instance you apply the batch: - -```objective-c -RocksDB *db = ...; -RocksDBColumnFamily *stuffColumnFamily = .../ - -// Write Batch for default column family -RocksDBWriteBatch *batch = [db writeBatch]; - -// Write Batch for stuffColumnFamily -RocksDBWriteBatch *cfBatch = [stuffColumnFamily writeBatch]; - -[batch setObject:@"Value 1" forKey:@"Key 1"]; -[batch setObject:@"Value 2" forKey:@"Key 2" inColumnFamily:stuffColumnFamily]; - -// You can apply the Write Batch object either on the DB instance -// or the stuffColumnFamily instance. -// The following two calls have the same effect: -/** - [db applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { - // Write options here - }]; - [stuffColumnFamily applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { - // Write options here - }]; -*/ -``` - ## Iteration Iteration is provided via the `RocksDBIterator` class. @@ -362,21 +254,21 @@ for ([iterator seekToKey:@"start"]; [iterator isValid]; [iterator next]) { or use one of the provided enumeration-blocks: ```objective-c -[db setObject:@"Value 1" forKey:@"A"]; -[db setObject:@"Value 2" forKey:@"B"]; -[db setObject:@"Value 3" forKey:@"C"]; -[db setObject:@"Value 3" forKey:@"D"]; +[db setData:@"Value 1" forKey:@"A"]; +[db setData:@"Value 2" forKey:@"B"]; +[db setData:@"Value 3" forKey:@"C"]; +[db setData:@"Value 3" forKey:@"D"]; RocksDBIterator *iterator = [db iterator]; /* Keys Enumeration */ -[db enumerateKeysUsingBlock:^(id key, BOOL *stop) { +[db enumerateKeysUsingBlock:^(NSData *key, BOOL *stop) { NSLog(@"%@", key); // A, B, C, D }]; // reverse enumeration -[db enumerateKeysInReverse:YES usingBlock:^(id key, BOOL *stop) { +[db enumerateKeysInReverse:YES usingBlock:^(NSData *key, BOOL *stop) { NSLog(@"%@", key); // D, C, B, A }]; @@ -384,27 +276,27 @@ RocksDBIterator *iterator = [db iterator]; // Enumeration in a given key-range [start, end) RocksDBIteratorKeyRange range = RocksDBMakeKeyRange(@"A", @"C"); -[db enumerateKeysInRange:range reverse:NO usingBlock:^(id key, BOOL *stop) { - NSLog(@"%@", key, [db objectForKey:key]); +[db enumerateKeysInRange:range reverse:NO usingBlock:^(NSData *key, BOOL *stop) { + NSLog(@"%@", key, [db dataForKey:key]); // B, C }]; /* Key-Value Enumeration */ -[db enumerateKeysAndValuesUsingBlock:^(id key, id value BOOL *stop) { +[db enumerateKeysAndValuesUsingBlock:^(NSData *key, NSData *value BOOL *stop) { NSLog(@"%@:%@", key, value); // A:1, B:2, C:3, D:4 }]; -[db enumerateKeysAndValuesInReverse:YES usingBlock:^(id key, BOOL *stop) { - NSLog(@"%@: %@", key, [db objectForKey:key]); +[db enumerateKeysAndValuesInReverse:YES usingBlock:^(NSData *key, BOOL *stop) { + NSLog(@"%@: %@", key, [db dataForKey:key]); // D:4, C:3, B:2, A:1 }]; // Enumeration in a given key-range [start, end) RocksDBIteratorKeyRange range = RocksDBMakeKeyRange(@"A", @"C"); -[db enumerateKeysAndValuesInRange:range reverse:YES usingBlock:^(id key, BOOL *stop) { - NSLog(@"%@:%@", key, [db objectForKey:key]); +[db enumerateKeysAndValuesInRange:range reverse:YES usingBlock:^(NSData *key, BOOL *stop) { + NSLog(@"%@:%@", key, [db dataForKey:key]); // B:2, C:3 }]; ``` @@ -417,30 +309,27 @@ RocksDBIteratorKeyRange range = RocksDBMakeKeyRange(@"A", @"C"); RocksDB *db = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.prefixExtractor = [RocksDBPrefixExtractor prefixExtractorWithType:RocksDBPrefixFixedLength length:2]; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; }]; -[db setObject:@"a" forKey:@"10.1"]; -[db setObject:@"b" forKey:@"10.2"]; -[db setObject:@"b" forKey:@"10.3"]; -[db setObject:@"c" forKey:@"11.1"]; -[db setObject:@"d" forKey:@"11.2"]; -[db setObject:@"d" forKey:@"11.3"]; +[db setData:@"a" forKey:@"10.1"]; +[db setData:@"b" forKey:@"10.2"]; +[db setData:@"b" forKey:@"10.3"]; +[db setData:@"c" forKey:@"11.1"]; +[db setData:@"d" forKey:@"11.2"]; +[db setData:@"d" forKey:@"11.3"]; RocksDBIterator *iterator = [db iterator]; // Enumeration starts with the key that is Greater-Than-Or-Equal to a key // with the given "prefix" parameter -[iterator enumerateKeysWithPrefix:@"10" usingBlock:^(id key, BOOL *stop) { +[iterator enumerateKeysWithPrefix:@"10" usingBlock:^(NSData *key, BOOL *stop) { NSLog(@"%@", key); // 10.1, 10.2, 10.3 }]; // .. so in this case the enumeration starts at key "10.2", even if "10.1" // has the same prefix -[iterator enumerateKeysWithPrefix:@"10.2" usingBlock:^(id key, BOOL *stop) { +[iterator enumerateKeysWithPrefix:@"10.2" usingBlock:^(NSData *key, BOOL *stop) { NSLog(@"%@", key); // 10.2, 10.3 }]; @@ -450,19 +339,19 @@ You can also define your own Prefix Extractor: ```objective-c RocksDBPrefixExtractor *extractor = [[RocksDBPrefixExtractor alloc] initWithName:@"custom_prefix" - transformBlock:^id (id key) { + transformBlock:^id (NSData *key) { // Apply your key transformation to extract the prefix part id prefix = extractPrefixFromKey(key); return prefix; } - prefixCandidateBlock:^BOOL (id key) { + prefixCandidateBlock:^BOOL (NSData *key) { // You can filter out keys that are not viable candidates for // your custom prefix format, e.g. key length is smaller than // the target prefix length BOOL isCandidate = canExtractPrefixFromKey(key); return isCandidate; } - validPrefixBlock:^BOOL (id prefix) { + validPrefixBlock:^BOOL (NSData *prefix) { // After a prefix is extracted you can perform extra // checks here to verify that the prefix is valid BOOL isValid = isExtractedPrefixValid(prefix); @@ -471,12 +360,113 @@ RocksDBPrefixExtractor *extractor = [[RocksDBPrefixExtractor alloc] initWithName ]; ``` +## Column Families + +Once you have a `RocksDB` instance you can create and drop column families on the fly: + +```objective-c +RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:...]; + +RocksDBColumnFamily *columnFamily = [db createColumnFamilyWithName:@"new_column_family" andOptions:^(RocksDBColumnFamilyOptions *options) { + // Options for the new column family +}; +// Do stuff with columnFamily and close it when you're done +[columnFamily close]; + +// To drop it +[columnFamily drop]; +``` + +> Notice that the `RocksDBColumnFamily` is a subclass of `RocksDB` + +If the database already contains Column Families other than the default, then you need to specify all Column Families that currently exist in the database when opening it, including the default one. You specify the Column Families using a `RocksDBColumnFamiliesDescriptor` object: + +```objective-c +RocksDBColumnFamilyDescriptor *descriptor = [RocksDBColumnFamilyDescriptor new]; + +[descriptor addColumnFamilyWithName:@"default" andOptions:^(RocksDBColumnFamilyOptions *options) { + // Options for the default column family +}]; +[descriptor addColumnFamilyWithName:@"stuff_column_family" andOptions:^(RocksDBColumnFamilyOptions *options) { + // Options for the stuff_column_family +}]; + +RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" columnFamilies:descriptor andDatabaseOptions:^(RocksDBDatabaseOptions *options) { + // Database options here +}]; + +NSArray *columnFamilies = db.columnFamilies; +RocksDBColumnFamily *defaultColumnFamily = columnFamilies[0]; +RocksDBColumnFamily *stuffColumnFamily = columnFamilies[1]; +// At this point you can either use the db instance or +// the defaultColumnFamily instance to access the default column family +``` + +## Atomic Updates + +You can atomically apply a set of updates to the database using a `WriteBatch`. There are two ways to use a `WriteBatch`: + +* An inline block-based approach: + +```objective-c +[db setData:@"Value 1" forKey:@"Key 1"]; + +[db performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *writeOptions) { + [batch setData:@"Value 2" forKey:@"Key 2"]; + [batch setData:@"Value 3" forKey:@"Key 3"]; + [batch deleteDataForKey:@"Key 1"]; +}]; +``` + +* Via a `WriteBatch` instance, which may be more flexible for "scattered" logic: + +```objective-c +[db setData:@"Value 1" forKey:@"Key 1"]; + +RocksDBWriteBatch *batch = [db writeBatch]; +[batch setData:@"Value 2" forKey:@"Key 2"]; +[batch setData:@"Value 3" forKey:@"Key 3"]; +[batch deleteDataForKey:@"Key 1"]; +... +[db applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { + // Write options here +}]; +``` + +The Write Batch object operates per default on the Column Family associated with the DB instance, which was used to create it. However, you can also specify the Column Family, in order to achieve an atomic write across multiple Column Families. In this case it doesn't matter on which instance you apply the batch: + +```objective-c +RocksDB *db = ...; +RocksDBColumnFamily *stuffColumnFamily = .../ + +// Write Batch for default column family +RocksDBWriteBatch *batch = [db writeBatch]; + +// Write Batch for stuffColumnFamily +RocksDBWriteBatch *cfBatch = [stuffColumnFamily writeBatch]; + +[batch setData:@"Value 1" forKey:@"Key 1"]; +[batch setData:@"Value 2" forKey:@"Key 2" inColumnFamily:stuffColumnFamily]; + +// You can apply the Write Batch object either on the DB instance +// or the stuffColumnFamily instance. +// The following two calls have the same effect: +/** + [db applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { + // Write options here + }]; + [stuffColumnFamily applyWriteBatch:batch withWriteOptions:^(RocksDBWriteOptions *writeOptions) { + // Write options here + }]; +*/ +``` + ## Snapshot A Snapshot provides consistent read-only view over the state of the key-value store. Do not forget to close the snapshot when it's no longer needed: ```objective-c -[db setObject:@"Value 1" forKey:@"A"]; +[db setData:@"Value 1" forKey:@"A"]; RocksDBSnapshot *snapshot = [db snapshot]; // Alternatively, you can get a snapshot with specific read options @@ -484,12 +474,12 @@ snapshot = [db snapshotWithReadOptions:^(RocksDBReadOptions *readOptions) { // Read options here }]; -[db deleteObjectForKey:@"A"]; -[db setObject:@"Value 2" forKey:@"B"]; +[db deleteDataForKey:@"A"]; +[db setData:@"Value 2" forKey:@"B"]; -NSString *value1 = [snapshot objectForKey:@"A"]; +NSString *value1 = [snapshot dataForKey:@"A"]; // value1 == @"Value 1" -NSString *value2 = [snapshot objectForKey:@"B"]; +NSString *value2 = [snapshot dataForKey:@"B"]; // value2 == nil ... [snapshot close]; @@ -500,8 +490,8 @@ NSString *value2 = [snapshot objectForKey:@"B"]; A checkpoint is an openable Snapshot of a database at a point in time: ```objective-c -[db setObject:@"Value 1" forKey:@"A"]; -[db setObject:@"Value 2" forKey:@"B"]; +[db setData:@"Value 1" forKey:@"A"]; +[db setData:@"Value 2" forKey:@"B"]; RocksDBCheckpoint *checkpoint = [[RocksDBCheckpoint alloc] initWithDatabase:db]; NSError *error = nil; @@ -522,7 +512,7 @@ This behavior can be changed by supplying a custom Comparator when opening a dat Say you have `NSString` keys and you want them to be ordered using a case-insensitive, localized, comparison: ```objective-c -RocksDBComparator *localizedKeys = [[RocksDBComparator alloc] initWithName:@"LocalizedKeys" andBlock:^int (id key1, id key2) { +RocksDBComparator *localizedKeys = [[RocksDBComparator alloc] initWithName:@"LocalizedKeys" andBlock:^int (NSData *key1, NSData *key2) { return [key1 localizedCaseInsensitiveCompare:key2]; ]; @@ -546,10 +536,10 @@ RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOption * `RocksDBComparatorBytewiseAscending:` orders the keys lexicographically in ascending order. * This is the default behavior if none is specified. * `RocksDBComparatorBytewiseDescending` orders the keys lexicographically ins descending order. -* `RocksDBComparatorStringCompareAscending` orders NSString keys in ascending order via the `compare` selector. -* `RocksDBComparatorStringCompareDescending` orders NSString keys in descending order via the `compare` selector. -* `RocksDBComparatorNumberAscending` orders NSNumber keys in ascending order via the `compare` selector. -* `RocksDBComparatorNumberDescending` orders NSNumber keys in descending order via the `compare` selector. +* `RocksDBComparatorStringCompareAscending` orders `NSString` keys in ascending order via the `compare` selector. + * This comparator assumes `NSString` keys and does convert the associated `NSData` via `initWithData:encoding:` using UTF-8 +* `RocksDBComparatorStringCompareDescending` orders `NSString` keys in descending order via the `compare` selector. + * This comparator assumes `NSString` keys and does convert the associated `NSData` via `initWithData:encoding:` using UTF-8 ## Merge Operator @@ -567,7 +557,7 @@ You can use this Merge Operator when you have associative data: For example we can use a merge operator to append entries to an existing array, instead of reading it completely, updating it and writing it back: ```objective-c -RocksDBMergeOperator *arrayAppend = [RocksDBMergeOperator operatorWithName:@"ArrayAppend" andBlock:^id (id key, id existingValue, id mergeValue) { +RocksDBMergeOperator *arrayAppend = [RocksDBMergeOperator operatorWithName:@"ArrayAppend" andBlock:^id (NSData *key, NSData *existingValue, NSData *mergeValue) { if (existingValue == nil) { return mergeValue; } else { @@ -578,16 +568,15 @@ RocksDBMergeOperator *arrayAppend = [RocksDBMergeOperator operatorWithName:@"Arr RocksDB *db = [RocksDB databaseAtPath:@"path/to/db" andDBOptions:^(RocksDBOptions *options) { options.mergeOperator = arrayAppend; - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSJSONSerializable; }]; NSMutableArray *letters = [NSMutableArray arrayWithObjects:@"A", @"B", nil]; -[db setObject:letters forKey:@"Key"]; -[db mergeObject:@[@"C", @"D"] forKey:@"Key"]; -[db mergeObject:@[@"E"] forKey:@"Key"]; -NSMutableArray *merged = [db objectForKey:@"Key"]; +[db setData:letters forKey:@"Key"]; +[db mergeData:@[@"C", @"D"] forKey:@"Key"]; +[db mergeData:@[@"E"] forKey:@"Key"]; + +NSMutableArray *merged = [db dataForKey:@"Key"]; // merged = @[@"A", @"B", @"C", @"D", @"E"]; ``` @@ -605,7 +594,7 @@ ObjectiveRocks has a new `mergeOperation` method for use with a generic Merge Op ```objective-c RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" - partialMergeBlock:^id(id key, NSString *leftOperand, NSString *rightOperand) { + partialMergeBlock:^id(NSData *key, NSData *leftOperand, NSData *rightOperand) { NSString *left = [leftOperand componentsSeparatedByString:@":"][0]; NSString *right = [rightOperand componentsSeparatedByString:@":"][0]; if ([left isEqualToString:right]) { @@ -629,9 +618,6 @@ RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operato RocksDB *db = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.mergeOperator = mergeOp; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSJSONSerializable; }]; NSDictionary *object = @{@"Key 1" : @"Value 1", @@ -640,12 +626,12 @@ NSDictionary *object = @{@"Key 1" : @"Value 1", [db setObject:object forKey:@"Dict Key"]; -[db mergeOperation:@"Key 1:UPDATE:Value X" forKey:@"Dict Key"]; -[db mergeOperation:@"Key 4:INSERT:Value 4" forKey:@"Dict Key"]; -[db mergeOperation:@"Key 2:DELETE" forKey:@"Dict Key"]; -[db mergeOperation:@"Key 1:UPDATE:Value 1 New" forKey:@"Dict Key"]; +[db mergeData:@"Key 1:UPDATE:Value X" forKey:@"Dict Key"]; +[db mergeData:@"Key 4:INSERT:Value 4" forKey:@"Dict Key"]; +[db mergeData:@"Key 2:DELETE" forKey:@"Dict Key"]; +[db mergeData:@"Key 1:UPDATE:Value 1 New" forKey:@"Dict Key"]; -id result = [db objectForKey:@"Dict Key"]; +id result = [db dataForKey:@"Dict Key"]; /** result = @{@"Key 1" : @"Value 1 New", @"Key 3" : @"Value 3", @@ -670,8 +656,6 @@ NSArray *threads = dbEnv.threadList; RocksDBThreadStatus *status = threads[0]; ``` -> Thread Status API is currently a WIP. - ## Backup & Restore To backup a database use the `RocksDBBackupEngine`: @@ -710,13 +694,13 @@ RocksDB *db = ... RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:@"path/to/backup"]; -[db setObject:@"Value 1" forKey:@"A"]; +[db setData:@"Value 1" forKey:@"A"]; [backupEngine createBackupForDatabase:db error:nil]; -[db setObject:@"Value 2" forKey:@"B"]; +[db setData:@"Value 2" forKey:@"B"]; [backupEngine createBackupForDatabase:db error:nil]; -[db setObject:@"Value 3" forKey:@"C"]; +[db setData:@"Value 3" forKey:@"C"]; [backupEngine createBackupForDatabase:db error:nil]; // An array containing RocksDBBackupInfo objects @@ -763,30 +747,12 @@ uint64_t sizeActiveMemTable = [db valueForIntProperty:RocksDBIntPropertyCurSizeA # Configuration -TBD - -## Table Formats - -* `BlockBasedTable`: is the default SST table format in RocksDB. -* `PlainTable`: is a RocksDB's SST file format optimized for low query latency on pure-memory or really low-latency media. -* `CuckooTable`: designed for applications that require fast point lookups but not fast range scans. - -## Memtable Formats - -* `SkipList`: uses a skip list to store keys. It is the default. -* `Vector`: creates MemTableReps that are backed by an std::vector. On iteration, the vector is sorted. This is useful for workloads where iteration is very rare and writes are generally not issued after reads begin. -* `HashSkipList`: contains a fixed array of buckets, each pointing to a skiplist. -* `HashLinkedList`: creates memtables based on a hash table: it contains a fixed array of buckets, each pointing to either a linked list or a skip list if number of entries inside the bucket exceeds a predefined threshold. -* `Cuckoo`: creates a cuckoo-hashing based mem-table representation. Cuckoo-hash is a closed-hash strategy, in which all key/value pairs are stored in the bucket array itself intead of in some data structures external to the bucket array - -For more details visit the wiki [Hash based memtable implementations](https://github.com/facebook/rocksdb/wiki/Hash-based-memtable-implementations) - -## ObjectiveRocks DBOptions - Currently only a subset of all RocksDB's available options are wrapped/provided. > Further options will be added in later versions (mostly when I get the time to experiment with them and figure out what they do) +## ObjectiveRocks DB Options + | Option | Description | Default Value | |-----------------------------|----------------------------------------------------------------------|------------------------------------| | createIfMissing | The database will be created if it is missing | false | @@ -796,15 +762,52 @@ Currently only a subset of all RocksDB's available options are wrapped/provided. | infoLogLevel | Log level | INFO | | maxOpenFiles | Number of open files that can be used by the DB | 5000 | | maxWriteAheadLogSize | Max size of write-ahead logs before force-flushing | 0 (= dynamically chosen) | +| statistics | If non-nil, metrics about database operations will be collected | nil | | disableDataSync | Contents of manifest and data files wont be synced to stable storage | false | | useFSync | Every store to stable storage will issue a fsync | false | | maxLogFileSize | Max size of the info log file, will rotate when exceeded | 0 (= all logs written to one file) | | logFileTimeToRoll | Time for the info log file to roll (in seconds) | 0 (disabled) | | keepLogFileNum | Maximal info log files to be kept | 1000 | | bytesPerSync | Incrementally sync files to disk while they are being written | 0 (disabled) | -| writeBufferSize | Amount of data to build up in memory before writing to disk | 4MB | -| maxWriteBufferNumber | The maximum number of write buffers that are built up in memory | 2 | -| compressionType | Compress blocks using the specified compression algorithm | Snappy Compression | + +## ObjectiveRocks Column Family Options + +| Option | Description | Default Value | +|-----------------------------|----------------------------------------------------------------------|------------------------------------------------| +| comparator | Used to define the order of keys in the table | Lexicographic byte-wise ordering | +| mergeOperator | Must be provided for merge operations | `nil` | +| writeBufferSize | Amount of data to build up in memory before writing to disk | 4 * 1048576 (4MB) | +| maxWriteBufferNumber | The maximum number of write buffers that are built up in memory | 2 | +| minWriteBufferNumberToMerge | The minimum number of write buffers that will be merged together before writing to storage | 1 | +| compressionType | Compress blocks using the specified compression algorithm | Snappy Compression | +| prefixExtractor | If non-nil, the specified function to determine the prefixes for keys will be used | `nil` | +| numLevels | Number of levels for the DB | 7 | +| level0FileNumCompactionTrigger | Compress blocks using the specified compression algorithm | 4 | +| level0SlowdownWritesTrigger | Soft limit on number of level-0 files | 20 | +| level0StopWritesTrigger | Maximum number of level-0 files | 24 | +| targetFileSizeBase | Target file size for compaction | 2 * 1048576 (2MB) | +| targetFileSizeMultiplier | Multiplier for sizes of files in different levels | 1 (files in different levels will have similar size) | +| maxBytesForLevelBase | Control maximum total data size for a level | 10 * 1048576 (10MB) | +| maxBytesForLevelMultiplier | Multiplier for file size per level | 10 | +| expandedCompactionFactor | Maximum number of bytes in all compacted files | 25 | +| sourceCompactionFactor | Maximum number of bytes in all source files to be compacted in a single compaction run | 1 | +| maxGrandparentOverlapFactor | Control maximum bytes of overlaps in grandparent (i.e., level+2) | 10 | +| softRateLimit | Puts are delayed 0-1 ms when any level has a compaction score that exceeds this limit | 0 (disabled) | +| hardRateLimit | Puts are delayed 1ms at a time when any level has a compaction score that exceeds this limit | 0 (disabled) | +| arenaBlockSize | Size of one block in arena memory allocation | 0 | +| disableAutoCompactions | Disable automatic compactions | false | +| purgeRedundantKvsWhileFlush | Purge duplicate/deleted keys when a memtable is flushed to storage | true | +| verifyChecksumsInCompaction | If true, compaction will verify checksum on every read that happens as part of compaction | true | +| filterDeletes | Use KeyMayExist API to filter deletes when this is true | false | +| maxSequentialSkipInIterations | An iteration->Next() sequentially skips over keys with the same user-key unless this option is set | 8 | +| memTableRepFactory | A factory that provides MemTableRep objects | `nil`. Internallty RocksDB will use a factory that provides a skip-list-based implementation of `MemTableRep` | +| tableFacotry | A factory that provides TableFactory objects | `nil`. Internallty RocksDB will use a block-based table factory that provides a default implementation of TableBuilder and TableReader with default `BlockBasedTableOptions` | +| memtablePrefixBloomBits | If prefixExtractor is set and bloom_bits is not 0, create prefix bloom for memtable | 0 | +| memtablePrefixBloomProbes | Number of hash probes per key | 6 | +| memtablePrefixBloomHugePageTlbSize | Page size for huge page TLB for bloom in memtable | 0 | +| bloomLocality | Control locality of bloom filter probes to improve cache miss rate | 0 | +| maxSuccessiveMerges | Maximum number of successive merge operations on a key in the memtable | 0 | +| minPartialMergeOperands | The number of partial merge operands to accumulate before partial merge will be performed | 2 | ## Read Options @@ -819,5 +822,20 @@ Currently only a subset of all RocksDB's available options are wrapped/provided. |-----------------------------|----------------------------------------------------------------------|------------------------------------| | syncWrites | Writes will be flushed from buffer before being considered complete | false | | disableWriteAheadLog | Writes will not first go to the write ahead log | true | -| timeoutHint | Timeout hint for write operation | 0 (no timeout) | | ignoreMissingColumnFamilies | Ignore writes to non-existing column families | false | + +## Table Formats + +* `BlockBasedTable`: is the default SST table format in RocksDB. +* `PlainTable`: is a RocksDB's SST file format optimized for low query latency on pure-memory or really low-latency media. +* `CuckooTable`: designed for applications that require fast point lookups but not fast range scans. + +## Memtable Formats + +* `SkipList`: uses a skip list to store keys. It is the default. +* `Vector`: creates MemTableReps that are backed by an std::vector. On iteration, the vector is sorted. This is useful for workloads where iteration is very rare and writes are generally not issued after reads begin. +* `HashSkipList`: contains a fixed array of buckets, each pointing to a skiplist. +* `HashLinkedList`: creates memtables based on a hash table: it contains a fixed array of buckets, each pointing to either a linked list or a skip list if number of entries inside the bucket exceeds a predefined threshold. +* `Cuckoo`: creates a cuckoo-hashing based mem-table representation. Cuckoo-hash is a closed-hash strategy, in which all key/value pairs are stored in the bucket array itself intead of in some data structures external to the bucket array + +For more details visit the wiki [Hash based memtable implementations](https://github.com/facebook/rocksdb/wiki/Hash-based-memtable-implementations) diff --git a/Tests/ObjectiveRocksTests-Bridging-Header.h b/Tests/ObjectiveRocksTests-Bridging-Header.h index 87bcb1d..e8231d0 100644 --- a/Tests/ObjectiveRocksTests-Bridging-Header.h +++ b/Tests/ObjectiveRocksTests-Bridging-Header.h @@ -15,7 +15,6 @@ #import #import -#import #import #import #import @@ -30,8 +29,6 @@ #import #import - -#import #import #import diff --git a/Tests/ObjectiveRocksTests-iOS-Bridging-Header.h b/Tests/ObjectiveRocksTests-iOS-Bridging-Header.h index e7c1ad6..6384d2f 100644 --- a/Tests/ObjectiveRocksTests-iOS-Bridging-Header.h +++ b/Tests/ObjectiveRocksTests-iOS-Bridging-Header.h @@ -15,7 +15,6 @@ #import #import -#import #import #import #import @@ -31,5 +30,4 @@ #import -#import #import diff --git a/Tests/RockDBTests.swift b/Tests/RockDBTests.swift index 9c0b666..d0ba4e6 100644 --- a/Tests/RockDBTests.swift +++ b/Tests/RockDBTests.swift @@ -10,11 +10,35 @@ import Foundation import XCTest import ObjectiveRocks -public func AssertThrows(message: String = "Expression did not throw", +// MARK:- Extension + +extension Data: ExpressibleByStringLiteral { + public init(stringLiteral value: String) { + self = value.data(using: .utf8)! + } + + public init(extendedGraphemeClusterLiteral value: String) { + self = value.data(using: .utf8)! + } + + public init(unicodeScalarLiteral value: String) { + self = value.data(using: .utf8)! + } +} + +extension String { + var data: Data { + return self.data(using: .utf8)! + } +} + +// MARK:- Util + +public func AssertThrows(_ message: String = "Expression did not throw", _ function: String = #function, - _ file: StaticString = #file, - _ line: UInt = #line, - expression: () throws -> Void) + _ file: StaticString = #file, + _ line: UInt = #line, + expression: () throws -> Void) { var thrown: NSError? = nil do { @@ -27,35 +51,7 @@ public func AssertThrows(message: String = "Expression did not throw", XCTAssertNotNil(thrown, completeMessage, file: file, line: line) } -public func Data(x: String) -> NSData { - return x.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)! -} - -public func Str(x: NSData) -> NSString { - return NSString(data: x, encoding: NSUTF8StringEncoding)! -} - -public func NumData(x: UInt64) -> NSData { - var val = x - return NSData(bytes: &val, length: sizeof(UInt64)) -} - -public func NumData(x: Float) -> NSData { - var val = x - return NSData(bytes: &val, length: sizeof(UInt64)) -} - -public func Val(data: NSData) -> UInt64 { - var val: UInt64 = 0 - data.getBytes(&val, length: sizeof(UInt64)) - return val -} - -public func Val(data: NSData) -> Float { - var val: Float = 0 - data.getBytes(&val, length: sizeof(Float)) - return val -} +// MARK:- Base class RocksDBTests : XCTestCase { @@ -69,12 +65,12 @@ class RocksDBTests : XCTestCase { override func setUp() { super.setUp() - let bundle = NSBundle(forClass: self.dynamicType) - path = (bundle.bundlePath as NSString).stringByAppendingPathComponent("ObjectiveRocks") - backupPath = path.stringByAppendingString("Backup") - restorePath = path.stringByAppendingString("Restore") - checkpointPath1 = path.stringByAppendingString("Snapshot1") - checkpointPath2 = path.stringByAppendingString("Snapshot2") + let bundle = Bundle(for: type(of: self)) + path = (bundle.bundlePath as NSString).appendingPathComponent("ObjectiveRocks") + backupPath = path + "Backup" + restorePath = path + "Restore" + checkpointPath1 = path + "Snapshot1" + checkpointPath2 = path + "Snapshot2" cleanupDatabase() } @@ -89,11 +85,11 @@ class RocksDBTests : XCTestCase { func cleanupDatabase() { do { - try NSFileManager.defaultManager().removeItemAtPath(path) - try NSFileManager.defaultManager().removeItemAtPath(backupPath) - try NSFileManager.defaultManager().removeItemAtPath(restorePath) - try NSFileManager.defaultManager().removeItemAtPath(checkpointPath1) - try NSFileManager.defaultManager().removeItemAtPath(checkpointPath2) + try FileManager.default.removeItem(atPath: path) + try FileManager.default.removeItem(atPath: backupPath) + try FileManager.default.removeItem(atPath: restorePath) + try FileManager.default.removeItem(atPath: checkpointPath1) + try FileManager.default.removeItem(atPath: checkpointPath2) } catch {} } } diff --git a/Tests/RocksDBBackupTests.mm b/Tests/RocksDBBackupTests.mm index a1b39a9..cad8d07 100644 --- a/Tests/RocksDBBackupTests.mm +++ b/Tests/RocksDBBackupTests.mm @@ -20,9 +20,9 @@ - (void)testBackup_Create options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; @@ -41,9 +41,9 @@ - (void)testBackup_BackupInfo options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; @@ -69,13 +69,13 @@ - (void)testBackup_BackupInfo_Multiple RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; [_rocks close]; @@ -98,13 +98,13 @@ - (void)testBackup_PurgeBackups RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; [_rocks close]; @@ -128,13 +128,13 @@ - (void)testBackup_DeleteBackup RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; [_rocks close]; @@ -156,17 +156,17 @@ - (void)testBackup_Restore options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 10") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 20") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 30") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 10".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 20".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 30".data forKey:@"key 3".data error:nil]; [_rocks close]; @@ -174,9 +174,9 @@ - (void)testBackup_Restore RocksDB *backupRocks = [RocksDB databaseAtPath:_restorePath andDBOptions:nil]; - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 2") error:nil], Data(@"value 2")); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 3") error:nil], Data(@"value 3")); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 2".data error:nil], @"value 2".data); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 3".data error:nil], @"value 3".data); [backupRocks close]; } @@ -189,13 +189,13 @@ - (void)testBackup_Restore_Specific RocksDBBackupEngine *backupEngine = [[RocksDBBackupEngine alloc] initWithPath:_backupPath]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; [backupEngine createBackupForDatabase:_rocks error:nil]; [_rocks close]; @@ -204,9 +204,9 @@ - (void)testBackup_Restore_Specific RocksDB *backupRocks = [RocksDB databaseAtPath:_restorePath andDBOptions:nil]; - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 2") error:nil], nil); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 3") error:nil], nil); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 2".data error:nil], nil); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 3".data error:nil], nil); [backupRocks close]; @@ -214,9 +214,9 @@ - (void)testBackup_Restore_Specific backupRocks = [RocksDB databaseAtPath:_restorePath andDBOptions:nil]; - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 2") error:nil], Data(@"value 2")); - XCTAssertEqualObjects([backupRocks dataForKey:Data(@"key 3") error:nil], nil); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 2".data error:nil], @"value 2".data); + XCTAssertEqualObjects([backupRocks dataForKey:@"key 3".data error:nil], nil); [backupRocks close]; } diff --git a/Tests/RocksDBBackupTests.swift b/Tests/RocksDBBackupTests.swift index 5818651..6024620 100644 --- a/Tests/RocksDBBackupTests.swift +++ b/Tests/RocksDBBackupTests.swift @@ -12,36 +12,36 @@ import ObjectiveRocks class RocksDBBackupTests : RocksDBTests { func testSwift_Backup_Create() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! backupEngine.createBackupForDatabase(rocks) + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() - let exists = NSFileManager.defaultManager().fileExistsAtPath(self.backupPath) + let exists = FileManager.default.fileExists(atPath: self.backupPath) XCTAssertTrue(exists) } func testSwift_Backup_BackupInfo() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! backupEngine.createBackupForDatabase(rocks) + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() @@ -50,28 +50,28 @@ class RocksDBBackupTests : RocksDBTests { XCTAssertNotNil(backupInfo) XCTAssertEqual(backupInfo.count, 1); - let info = backupInfo[0] as! RocksDBBackupInfo + let info = backupInfo[0] XCTAssertEqual(info.backupId, 1 as UInt32) } func testSwift_Backup_BackupInfo_Multiple() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") - try! backupEngine.createBackupForDatabase(rocks) + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 2", forKey: "key 2") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 3", forKey: "key 3") - try! backupEngine.createBackupForDatabase(rocks) + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() @@ -80,29 +80,29 @@ class RocksDBBackupTests : RocksDBTests { XCTAssertNotNil(backupInfo) XCTAssertEqual(backupInfo.count, 3); - XCTAssertEqual(backupInfo[0].backupId, 1 as UInt32) - XCTAssertEqual(backupInfo[1].backupId, 2 as UInt32) - XCTAssertEqual(backupInfo[2].backupId, 3 as UInt32) + XCTAssertEqual((backupInfo[0] as AnyObject).backupId, 1 as UInt32) + XCTAssertEqual((backupInfo[1] as AnyObject).backupId, 2 as UInt32) + XCTAssertEqual((backupInfo[2] as AnyObject).backupId, 3 as UInt32) } func testSwift_Backup_PurgeBackups() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") do { - try backupEngine.createBackupForDatabase(rocks) + try backupEngine.createBackup(forDatabase: rocks) } catch _ { } - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 2", forKey: "key 2") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 3", forKey: "key 3") + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() @@ -113,107 +113,106 @@ class RocksDBBackupTests : RocksDBTests { XCTAssertNotNil(backupInfo) XCTAssertEqual(backupInfo.count, 2); - XCTAssertEqual(backupInfo[0].backupId, 2 as UInt32) - XCTAssertEqual(backupInfo[1].backupId, 3 as UInt32) + XCTAssertEqual((backupInfo[0] as AnyObject).backupId, 2 as UInt32) + XCTAssertEqual((backupInfo[1] as AnyObject).backupId, 3 as UInt32) } func testSwift_Backup_DeleteBackup() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 1", forKey: "key 1") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 2", forKey: "key 2") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 3", forKey: "key 3") + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() - try! backupEngine.deleteBackupWithId(2) + try! backupEngine.deleteBackup(withId: 2) let backupInfo = backupEngine.backupInfo() XCTAssertNotNil(backupInfo) XCTAssertEqual(backupInfo.count, 2); - XCTAssertEqual(backupInfo[0].backupId, 1 as UInt32) - XCTAssertEqual(backupInfo[1].backupId, 3 as UInt32) + XCTAssertEqual((backupInfo[0] as AnyObject).backupId, 1 as UInt32) + XCTAssertEqual((backupInfo[1] as AnyObject).backupId, 3 as UInt32) } func testSwift_Backup_Restore() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! backupEngine.createBackupForDatabase(rocks) + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 10"), forKey: Data("key 1")) - try! rocks.setData(Data("value 20"), forKey: Data("key 2")) - try! rocks.setData(Data("value 30"), forKey: Data("key 3")) + try! rocks.setData("value 10", forKey: "key 1") + try! rocks.setData("value 20", forKey: "key 2") + try! rocks.setData("value 30", forKey: "key 3") rocks.close() - try! backupEngine.restoreBackupToDestinationPath(self.restorePath) + try! backupEngine.restoreBackup(toDestinationPath: self.restorePath) - let backupRocks = RocksDB.databaseAtPath(restorePath, andDBOptions: nil) + let backupRocks = RocksDB.database(atPath: restorePath, andDBOptions: nil) XCTAssertNotNil(backupRocks) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 1")), Data("value 1")) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 2")), Data("value 2")) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 3")), Data("value 3")) + XCTAssertEqual(try! backupRocks?.data(forKey: "key 1"), "value 1") + XCTAssertEqual(try! backupRocks?.data(forKey: "key 2"), "value 2") + XCTAssertEqual(try! backupRocks?.data(forKey: "key 3"), "value 3") backupRocks?.close() } func testSwift_Backup_Restore_Specific() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) let backupEngine = RocksDBBackupEngine(path: self.backupPath) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 1", forKey: "key 1") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 2", forKey: "key 2") + try! backupEngine.createBackup(forDatabase: rocks) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! backupEngine.createBackupForDatabase(rocks) + try! rocks.setData("value 3", forKey: "key 3") + try! backupEngine.createBackup(forDatabase: rocks) rocks.close() - try! backupEngine.restoreBackupWithId(1, toDestinationPath: self.restorePath) + try! backupEngine.restoreBackup(withId: 1, toDestinationPath: self.restorePath) - var backupRocks = RocksDB.databaseAtPath(restorePath, andDBOptions: nil) + var backupRocks = RocksDB.database(atPath: restorePath, andDBOptions: nil) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 1")), Data("value 1")) + XCTAssertEqual(try! backupRocks?.data(forKey: "key 1"), "value 1") - XCTAssertNil(try? backupRocks?.dataForKey(Data("key 2"))) - XCTAssertNil(try? backupRocks?.dataForKey(Data("key 3"))) + XCTAssertNil(try? backupRocks?.data(forKey: "key 2") as Any) + XCTAssertNil(try? backupRocks?.data(forKey: "key 3") as Any) backupRocks?.close() - try! backupEngine.restoreBackupWithId(2, toDestinationPath: self.restorePath) + try! backupEngine.restoreBackup(withId: 2, toDestinationPath: self.restorePath) - backupRocks = RocksDB.databaseAtPath(restorePath, andDBOptions: nil) + backupRocks = RocksDB.database(atPath: restorePath, andDBOptions: nil) - XCTAssertNotNil(backupRocks) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 1")), Data("value 1")) - XCTAssertEqual(try! backupRocks?.dataForKey(Data("key 2")), Data("value 2")) - XCTAssertNil(try? backupRocks?.dataForKey(Data("key 3"))) + XCTAssertEqual(try! backupRocks?.data(forKey: "key 1"), "value 1") + XCTAssertEqual(try! backupRocks?.data(forKey: "key 2"), "value 2") + XCTAssertNil(try? backupRocks?.data(forKey: "key 3") as Any) backupRocks?.close() } diff --git a/Tests/RocksDBBasicTests.mm b/Tests/RocksDBBasicTests.mm index 265130f..116aaec 100644 --- a/Tests/RocksDBBasicTests.mm +++ b/Tests/RocksDBBasicTests.mm @@ -36,56 +36,23 @@ - (void)testDB_CRUD [_rocks setDefaultReadOptions:^(RocksDBReadOptions *readOptions) { readOptions.fillCache = YES; readOptions.verifyChecksums = YES; - } andWriteOptions:^(RocksDBWriteOptions *writeOptions) { + } writeOptions:^(RocksDBWriteOptions *writeOptions) { writeOptions.syncWrites = YES; }]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + XCTAssertEqualObjects([_rocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"key 2".data error:nil], @"value 2".data); + XCTAssertEqualObjects([_rocks dataForKey:@"key 3".data error:nil], @"value 3".data); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 2") error:nil], Data(@"value 2")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 3") error:nil], Data(@"value 3")); - - [_rocks deleteDataForKey:Data(@"key 2") error:nil]; - XCTAssertNil([_rocks dataForKey:Data(@"key 2") error:nil]); - - NSError *error = nil; - BOOL ok = [_rocks deleteDataForKey:Data(@"key 2") error:&error]; - XCTAssertTrue(ok); - XCTAssertNil(error); -} - -- (void)testDB_CRUD_Encoded -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; - }]; - [_rocks setDefaultReadOptions:^(RocksDBReadOptions *readOptions) { - readOptions.fillCache = YES; - readOptions.verifyChecksums = YES; - } andWriteOptions:^(RocksDBWriteOptions *writeOptions) { - writeOptions.syncWrites = YES; - }]; - - - [_rocks setObject:@"value 1" forKey:@"key 1" error:nil]; - [_rocks setObject:@"value 2" forKey:@"key 2" error:nil]; - [_rocks setObject:@"value 3" forKey:@"key 3" error:nil]; - - XCTAssertEqualObjects([_rocks objectForKey:@"key 1" error:nil], @"value 1"); - XCTAssertEqualObjects([_rocks objectForKey:@"key 2" error:nil], @"value 2"); - XCTAssertEqualObjects([_rocks objectForKey:@"key 3" error:nil], @"value 3"); - - [_rocks deleteObjectForKey:@"key 2" error:nil]; - XCTAssertNil([_rocks objectForKey:@"key 2" error:nil]); + [_rocks deleteDataForKey:@"key 2".data error:nil]; + XCTAssertNil([_rocks dataForKey:@"key 2".data error:nil]); NSError *error = nil; - BOOL ok = [_rocks deleteObjectForKey:@"key 2" error:&error]; + BOOL ok = [_rocks deleteDataForKey:@"key 2".data error:&error]; XCTAssertTrue(ok); XCTAssertNil(error); } diff --git a/Tests/RocksDBBasicTests.swift b/Tests/RocksDBBasicTests.swift index d9b27e5..ad682da 100644 --- a/Tests/RocksDBBasicTests.swift +++ b/Tests/RocksDBBasicTests.swift @@ -12,12 +12,12 @@ import ObjectiveRocks class RocksDBBasicTests : RocksDBTests { func testSwift_DB_Open_ErrorIfExists() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) rocks.close() - let db = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + let db = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.errorIfExists = true }) @@ -25,54 +25,29 @@ class RocksDBBasicTests : RocksDBTests { } func testSwift_DB_CRUD() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - rocks.setDefaultReadOptions({ (readOptions) -> Void in - readOptions.fillCache = true - readOptions.verifyChecksums = true - }, andWriteOptions: { (writeOptions) -> Void in - writeOptions.syncWrites = true - }) - - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 3")), Data("value 3")); - - try! rocks.deleteDataForKey(Data("key 2")) - XCTAssertNil(try? rocks.dataForKey(Data("key 2"))); - - try! self.rocks.deleteDataForKey(Data("key 2")) - } - - func testSwift_DB_CRUD_Encoded() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.keyType = .NSString - options.valueType = .NSString - }) - rocks.setDefaultReadOptions({ (readOptions) -> Void in - readOptions.fillCache = true - readOptions.verifyChecksums = true - }, andWriteOptions: { (writeOptions) -> Void in + rocks.setDefault( + readOptions: { (readOptions) -> Void in + readOptions.fillCache = true + readOptions.verifyChecksums = true + }, + writeOptions: { (writeOptions) -> Void in writeOptions.syncWrites = true }) - try! rocks.setObject("value 1", forKey: "key 1") - try! rocks.setObject("value 2", forKey: "key 2") - try! rocks.setObject("value 3", forKey: "key 3") - XCTAssertEqual(try! rocks.objectForKey("key 1") as? String, "value 1"); - XCTAssertEqual(try! rocks.objectForKey("key 2") as? String, "value 2"); - XCTAssertEqual(try! rocks.objectForKey("key 3") as? String, "value 3"); + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data); + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2".data); + XCTAssertEqual(try! rocks.data(forKey: "key 3"), "value 3".data); - try! rocks.deleteObjectForKey("key 2") - let value = try? rocks.objectForKey("key 2") - XCTAssertNil(value); + try! rocks.deleteData(forKey: "key 2") + XCTAssertNil(try? rocks.data(forKey: "key 2")); - try! self.rocks.deleteObjectForKey("key 2") + try! self.rocks.deleteData(forKey: "key 2") } } diff --git a/Tests/RocksDBCheckpointTests.mm b/Tests/RocksDBCheckpointTests.mm index f7917eb..f908bb0 100644 --- a/Tests/RocksDBCheckpointTests.mm +++ b/Tests/RocksDBCheckpointTests.mm @@ -20,13 +20,13 @@ - (void)testCheckpoint options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; RocksDBCheckpoint *checkpoint = [[RocksDBCheckpoint alloc] initWithDatabase:_rocks]; [checkpoint createCheckpointAtPath:_chekpointPath_1 error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; [checkpoint createCheckpointAtPath:_chekpointPath_2 error:nil]; @@ -36,8 +36,8 @@ - (void)testCheckpoint options.createIfMissing = YES; }]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertNil([_rocks dataForKey:Data(@"key 2") error:nil]); + XCTAssertEqualObjects([_rocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertNil([_rocks dataForKey:@"key 2".data error:nil]); [_rocks close]; @@ -45,8 +45,8 @@ - (void)testCheckpoint options.createIfMissing = YES; }]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 1") error:nil], Data(@"value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"key 2") error:nil], Data(@"value 2")); + XCTAssertEqualObjects([_rocks dataForKey:@"key 1".data error:nil], @"value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"key 2".data error:nil], @"value 2".data); } @end diff --git a/Tests/RocksDBCheckpointTests.swift b/Tests/RocksDBCheckpointTests.swift index cdfc71c..a3041aa 100644 --- a/Tests/RocksDBCheckpointTests.swift +++ b/Tests/RocksDBCheckpointTests.swift @@ -12,36 +12,36 @@ import ObjectiveRocks class RocksDBCheckpointTests : RocksDBTests { func testSwift_Checkpoint() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let checkpoint = RocksDBCheckpoint(database: rocks) - try! checkpoint.createCheckpointAtPath(checkpointPath1) + try! checkpoint.createCheckpoint(atPath: checkpointPath1) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) + try! rocks.setData("value 2", forKey: "key 2") - try! checkpoint.createCheckpointAtPath(checkpointPath2) + try! checkpoint.createCheckpoint(atPath: checkpointPath2) rocks.close() - rocks = RocksDB.databaseAtPath(self.checkpointPath1, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.checkpointPath1, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")) - XCTAssertNil(try? rocks.dataForKey(Data("key 2"))) + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data) + XCTAssertNil(try? rocks.data(forKey: "key 2")) rocks.close() - rocks = RocksDB.databaseAtPath(self.checkpointPath2, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.checkpointPath2, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")) - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")) + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data) + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2".data) } } diff --git a/Tests/RocksDBColumnFamilyMetadataTests.mm b/Tests/RocksDBColumnFamilyMetadataTests.mm index edc16cf..2407661 100644 --- a/Tests/RocksDBColumnFamilyMetadataTests.mm +++ b/Tests/RocksDBColumnFamilyMetadataTests.mm @@ -28,11 +28,11 @@ - (void)testColumnFamilies_Metadata RocksDBColumnFamily *defaultColumnFamily = _rocks.columnFamilies[0]; RocksDBColumnFamily *newColumnFamily = _rocks.columnFamilies[1]; - [defaultColumnFamily setData:Data(@"df_value1") forKey:Data(@"df_key1") error:nil]; - [defaultColumnFamily setData:Data(@"df_value2") forKey:Data(@"df_key2") error:nil]; + [defaultColumnFamily setData:@"df_value1".data forKey:@"df_key1".data error:nil]; + [defaultColumnFamily setData:@"df_value2".data forKey:@"df_key2".data error:nil]; - [newColumnFamily setData:Data(@"cf_value1") forKey:Data(@"cf_key1") error:nil]; - [newColumnFamily setData:Data(@"cf_value2") forKey:Data(@"cf_key2") error:nil]; + [newColumnFamily setData:@"cf_value1".data forKey:@"cf_key1".data error:nil]; + [newColumnFamily setData:@"cf_value2".data forKey:@"cf_key2".data error:nil]; RocksDBColumnFamilyMetaData *defaultMetadata = defaultColumnFamily.columnFamilyMetaData; XCTAssertNotNil(defaultMetadata); diff --git a/Tests/RocksDBColumnFamilyMetadataTests.swift b/Tests/RocksDBColumnFamilyMetadataTests.swift index 727de6c..095162d 100644 --- a/Tests/RocksDBColumnFamilyMetadataTests.swift +++ b/Tests/RocksDBColumnFamilyMetadataTests.swift @@ -13,22 +13,22 @@ class RocksDBColumnFamilyMetadataTests : RocksDBTests { func testSwift_ColumnFamilies_Metadata() { let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions(nil) - descriptor.addColumnFamilyWithName("new_cf", andOptions: nil) + descriptor.addDefaultColumnFamily(options: nil) + descriptor.addColumnFamily(withName: "new_cf", andOptions: nil) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true options.createMissingColumnFamilies = true }) - let defaultColumnFamily = rocks.columnFamilies()[0] as! RocksDBColumnFamily - let newColumnFamily = rocks.columnFamilies()[1] as! RocksDBColumnFamily + let defaultColumnFamily = rocks.columnFamilies()[0] + let newColumnFamily = rocks.columnFamilies()[1] - try! defaultColumnFamily.setData(Data("df_value1"), forKey: Data("df_key1")) - try! defaultColumnFamily.setData(Data("df_value2"), forKey: Data("df_key2")) + try! defaultColumnFamily.setData("df_value1", forKey: "df_key1") + try! defaultColumnFamily.setData("df_value2", forKey: "df_key2") - try! newColumnFamily.setData(Data("cf_value1"), forKey: Data("cf_key1")) - try! newColumnFamily.setData(Data("cf_value2"), forKey: Data("cf_key2")) + try! newColumnFamily.setData("cf_value1", forKey: "cf_key1") + try! newColumnFamily.setData("cf_value2", forKey: "cf_key2") let defaultMetadata = defaultColumnFamily.columnFamilyMetaData() XCTAssertNotNil(defaultMetadata); diff --git a/Tests/RocksDBColumnFamilyTests.mm b/Tests/RocksDBColumnFamilyTests.mm index 309fa18..b19d2e7 100644 --- a/Tests/RocksDBColumnFamilyTests.mm +++ b/Tests/RocksDBColumnFamilyTests.mm @@ -150,13 +150,13 @@ - (void)testColumnFamilies_CRUD options.createIfMissing = YES; }]; - [_rocks setData:Data(@"df_value") forKey:Data(@"df_key1") error:nil]; - [_rocks setData:Data(@"df_value") forKey:Data(@"df_key2") error:nil]; + [_rocks setData:@"df_value".data forKey:@"df_key1".data error:nil]; + [_rocks setData:@"df_value".data forKey:@"df_key2".data error:nil]; RocksDBColumnFamily *columnFamily = [_rocks createColumnFamilyWithName:@"new_cf" andOptions:nil]; - [columnFamily setData:Data(@"cf_value") forKey:Data(@"cf_key1") error:nil]; - [columnFamily setData:Data(@"cf_value") forKey:Data(@"cf_key2") error:nil]; + [columnFamily setData:@"cf_value".data forKey:@"cf_key1".data error:nil]; + [columnFamily setData:@"cf_value".data forKey:@"cf_key2".data error:nil]; [columnFamily close]; [_rocks close]; @@ -172,28 +172,28 @@ - (void)testColumnFamilies_CRUD RocksDBColumnFamily *defaultColumnFamily = _rocks.columnFamilies[0]; RocksDBColumnFamily *newColumnFamily = _rocks.columnFamilies[1]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"df_key1") error:nil], Data(@"df_value")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"df_key2") error:nil], Data(@"df_value")); - XCTAssertNil([_rocks dataForKey:Data(@"cf_key1") error:nil]); - XCTAssertNil([_rocks dataForKey:Data(@"cf_key2") error:nil]); + XCTAssertEqualObjects([_rocks dataForKey:@"df_key1".data error:nil], @"df_value".data); + XCTAssertEqualObjects([_rocks dataForKey:@"df_key2".data error:nil], @"df_value".data); + XCTAssertNil([_rocks dataForKey:@"cf_key1".data error:nil]); + XCTAssertNil([_rocks dataForKey:@"cf_key2".data error:nil]); - XCTAssertEqualObjects([defaultColumnFamily dataForKey:Data(@"df_key1") error:nil], Data(@"df_value")); - XCTAssertEqualObjects([defaultColumnFamily dataForKey:Data(@"df_key2") error:nil], Data(@"df_value")); + XCTAssertEqualObjects([defaultColumnFamily dataForKey:@"df_key1".data error:nil], @"df_value".data); + XCTAssertEqualObjects([defaultColumnFamily dataForKey:@"df_key2".data error:nil], @"df_value".data); - XCTAssertNil([defaultColumnFamily dataForKey:Data(@"cf_key1") error:nil]); - XCTAssertNil([defaultColumnFamily dataForKey:Data(@"cf_key2") error:nil]); + XCTAssertNil([defaultColumnFamily dataForKey:@"cf_key1".data error:nil]); + XCTAssertNil([defaultColumnFamily dataForKey:@"cf_key2".data error:nil]); - XCTAssertEqualObjects([newColumnFamily dataForKey:Data(@"cf_key1") error:nil], Data(@"cf_value")); - XCTAssertEqualObjects([newColumnFamily dataForKey:Data(@"cf_key2") error:nil], Data(@"cf_value")); + XCTAssertEqualObjects([newColumnFamily dataForKey:@"cf_key1".data error:nil], @"cf_value".data); + XCTAssertEqualObjects([newColumnFamily dataForKey:@"cf_key2".data error:nil], @"cf_value".data); - XCTAssertNil([newColumnFamily dataForKey:Data(@"df_key1") error:nil]); - XCTAssertNil([newColumnFamily dataForKey:Data(@"df_key2") error:nil]); + XCTAssertNil([newColumnFamily dataForKey:@"df_key1".data error:nil]); + XCTAssertNil([newColumnFamily dataForKey:@"df_key2".data error:nil]); - [newColumnFamily deleteDataForKey:Data(@"cf_key1") error:nil]; - XCTAssertNil([newColumnFamily dataForKey:Data(@"cf_key1") error:nil]); + [newColumnFamily deleteDataForKey:@"cf_key1".data error:nil]; + XCTAssertNil([newColumnFamily dataForKey:@"cf_key1".data error:nil]); - [newColumnFamily deleteDataForKey:Data(@"cf_key1") error:nil]; - XCTAssertNil([newColumnFamily dataForKey:Data(@"cf_key1") error:nil]); + [newColumnFamily deleteDataForKey:@"cf_key1".data error:nil]; + XCTAssertNil([newColumnFamily dataForKey:@"cf_key1".data error:nil]); [defaultColumnFamily close]; [newColumnFamily close]; @@ -213,28 +213,28 @@ - (void)testColumnFamilies_WriteBatch RocksDBColumnFamily *defaultColumnFamily = _rocks.columnFamilies[0]; RocksDBColumnFamily *newColumnFamily = _rocks.columnFamilies[1]; - [newColumnFamily setData:Data(@"xyz_value") forKey:Data(@"xyz") error:nil]; + [newColumnFamily setData:@"xyz_value".data forKey:@"xyz".data error:nil]; RocksDBWriteBatch *batch = [newColumnFamily writeBatch]; - [batch setData:Data(@"cf_value1") forKey:Data(@"cf_key1")]; - [batch setData:Data(@"df_value") forKey:Data(@"df_key") inColumnFamily:defaultColumnFamily]; - [batch setData:Data(@"cf_value2") forKey:Data(@"cf_key2")]; - [batch deleteDataForKey:Data(@"xyz") inColumnFamily:defaultColumnFamily]; - [batch deleteDataForKey:Data(@"xyz")]; + [batch setData:@"cf_value1".data forKey:@"cf_key1".data]; + [batch setData:@"df_value".data forKey:@"df_key".data inColumnFamily:defaultColumnFamily]; + [batch setData:@"cf_value2".data forKey:@"cf_key2".data]; + [batch deleteDataForKey:@"xyz".data inColumnFamily:defaultColumnFamily]; + [batch deleteDataForKey:@"xyz".data]; [_rocks applyWriteBatch:batch writeOptions:nil error:nil]; - XCTAssertEqualObjects([defaultColumnFamily dataForKey:Data(@"df_key") error:nil], Data(@"df_value")); - XCTAssertNil([defaultColumnFamily dataForKey:Data(@"df_key1") error:nil]); - XCTAssertNil([defaultColumnFamily dataForKey:Data(@"df_key2") error:nil]); + XCTAssertEqualObjects([defaultColumnFamily dataForKey:@"df_key".data error:nil], @"df_value".data); + XCTAssertNil([defaultColumnFamily dataForKey:@"df_key1".data error:nil]); + XCTAssertNil([defaultColumnFamily dataForKey:@"df_key2".data error:nil]); - XCTAssertEqualObjects([newColumnFamily dataForKey:Data(@"cf_key1") error:nil], Data(@"cf_value1")); - XCTAssertEqualObjects([newColumnFamily dataForKey:Data(@"cf_key2") error:nil], Data(@"cf_value2")); - XCTAssertNil([newColumnFamily dataForKey:Data(@"df_key") error:nil]); + XCTAssertEqualObjects([newColumnFamily dataForKey:@"cf_key1".data error:nil], @"cf_value1".data); + XCTAssertEqualObjects([newColumnFamily dataForKey:@"cf_key2".data error:nil], @"cf_value2".data); + XCTAssertNil([newColumnFamily dataForKey:@"df_key".data error:nil]); - XCTAssertNil([defaultColumnFamily dataForKey:Data(@"xyz") error:nil]); - XCTAssertNil([newColumnFamily dataForKey:Data(@"xyz") error:nil]); + XCTAssertNil([defaultColumnFamily dataForKey:@"xyz".data error:nil]); + XCTAssertNil([newColumnFamily dataForKey:@"xyz".data error:nil]); [defaultColumnFamily close]; [newColumnFamily close]; @@ -254,18 +254,18 @@ - (void)testColumnFamilies_Iterator RocksDBColumnFamily *defaultColumnFamily = _rocks.columnFamilies[0]; RocksDBColumnFamily *newColumnFamily = _rocks.columnFamilies[1]; - [defaultColumnFamily setData:Data(@"df_value1") forKey:Data(@"df_key1") error:nil]; - [defaultColumnFamily setData:Data(@"df_value2") forKey:Data(@"df_key2") error:nil]; + [defaultColumnFamily setData:@"df_value1".data forKey:@"df_key1".data error:nil]; + [defaultColumnFamily setData:@"df_value2".data forKey:@"df_key2".data error:nil]; - [newColumnFamily setData:Data(@"cf_value1") forKey:Data(@"cf_key1") error:nil]; - [newColumnFamily setData:Data(@"cf_value2") forKey:Data(@"cf_key2") error:nil]; + [newColumnFamily setData:@"cf_value1".data forKey:@"cf_key1".data error:nil]; + [newColumnFamily setData:@"cf_value2".data forKey:@"cf_key2".data error:nil]; RocksDBIterator *dfIterator = [defaultColumnFamily iterator]; NSMutableArray *actual = [NSMutableArray array]; for ([dfIterator seekToFirst]; [dfIterator isValid]; [dfIterator next]) { - [actual addObject:Str([dfIterator key])]; - [actual addObject:Str([dfIterator value])]; + [actual addObject:[[NSString alloc] initWithData:dfIterator.key]]; + [actual addObject:[[NSString alloc] initWithData:dfIterator.value]]; } NSArray *expected = @[ @"df_key1", @"df_value1", @"df_key2", @"df_value2" ]; @@ -277,8 +277,8 @@ - (void)testColumnFamilies_Iterator actual = [NSMutableArray array]; for ([cfIterator seekToFirst]; [cfIterator isValid]; [cfIterator next]) { - [actual addObject:Str([cfIterator key])]; - [actual addObject:Str([cfIterator value])]; + [actual addObject:[[NSString alloc] initWithData:cfIterator.key]]; + [actual addObject:[[NSString alloc] initWithData:cfIterator.value]]; } expected = @[ @"cf_key1", @"cf_value1", @"cf_key2", @"cf_value2" ]; diff --git a/Tests/RocksDBColumnFamilyTests.swift b/Tests/RocksDBColumnFamilyTests.swift index 859ab6f..6175f80 100644 --- a/Tests/RocksDBColumnFamilyTests.swift +++ b/Tests/RocksDBColumnFamilyTests.swift @@ -12,83 +12,83 @@ import ObjectiveRocks class RocksDBColumnFamilyTests : RocksDBTests { func testSwift_ColumnFamilies_List() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) rocks.close() - let names = RocksDB.listColumnFamiliesInDatabaseAtPath(self.path) + let names = RocksDB.listColumnFamiliesInDatabase(atPath: self.path) XCTAssertTrue(names.count == 1); - XCTAssertEqual(names[0] as? NSString, "default") + XCTAssertEqual(names[0], "default") } func testSwift_ColumnFamilies_Create() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - let columnFamily = rocks.createColumnFamilyWithName("new_cf", andOptions: nil) + let columnFamily = rocks.createColumnFamily(withName: "new_cf", andOptions: nil) XCTAssertNotNil(columnFamily) columnFamily?.close() rocks.close() - let names = RocksDB.listColumnFamiliesInDatabaseAtPath(self.path) + let names = RocksDB.listColumnFamiliesInDatabase(atPath: self.path) XCTAssertTrue(names.count == 2); - XCTAssertEqual(names[0] as? NSString, "default") - XCTAssertEqual(names[1] as? NSString, "new_cf") + XCTAssertEqual(names[0], "default") + XCTAssertEqual(names[1], "new_cf") } func testSwift_ColumnFamilies_Drop() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - let columnFamily = rocks.createColumnFamilyWithName("new_cf", andOptions: nil) + let columnFamily = rocks.createColumnFamily(withName: "new_cf", andOptions: nil) XCTAssertNotNil(columnFamily) columnFamily?.drop() columnFamily?.close() rocks.close() - let names = RocksDB.listColumnFamiliesInDatabaseAtPath(self.path) + let names = RocksDB.listColumnFamiliesInDatabase(atPath: self.path) XCTAssertTrue(names.count == 1); - XCTAssertEqual(names[0] as? NSString, "default") + XCTAssertEqual(names[0], "default") } func testSwift_ColumnFamilies_Open() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) }) - let columnFamily = rocks.createColumnFamilyWithName("new_cf", andOptions: { + let columnFamily = rocks.createColumnFamily(withName: "new_cf", andOptions: { (options) in - options.comparator = RocksDBComparator.comaparatorWithType(.BytewiseDescending) + options.comparator = RocksDBComparator.comaparator(with: .bytewiseDescending) }) XCTAssertNotNil(columnFamily) columnFamily?.close() rocks.close() - let names = RocksDB.listColumnFamiliesInDatabaseAtPath(self.path) + let names = RocksDB.listColumnFamiliesInDatabase(atPath: self.path) XCTAssertTrue(names.count == 2) - XCTAssertEqual(names[0] as? NSString, "default") - XCTAssertEqual(names[1] as? NSString, "new_cf") + XCTAssertEqual(names[0], "default") + XCTAssertEqual(names[1], "new_cf") let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions { (options) -> Void in - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) + descriptor.addDefaultColumnFamily { (options) -> Void in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) } - descriptor.addColumnFamilyWithName("new_cf", andOptions: { (options) -> Void in - options.comparator = RocksDBComparator.comaparatorWithType(.BytewiseDescending) + descriptor.addColumnFamily(withName: "new_cf", andOptions: { (options) -> Void in + options.comparator = RocksDBComparator.comaparator(with: .bytewiseDescending) }) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true }) @@ -96,8 +96,8 @@ class RocksDBColumnFamilyTests : RocksDBTests { XCTAssertTrue(rocks.columnFamilies().count == 2) - let defaultColumnFamily = rocks.columnFamilies()[0] as! RocksDBColumnFamily - let newColumnFamily = rocks.columnFamilies()[1] as! RocksDBColumnFamily + let defaultColumnFamily = rocks.columnFamilies()[0] + let newColumnFamily = rocks.columnFamilies()[1] XCTAssertNotNil(defaultColumnFamily) XCTAssertNotNil(newColumnFamily) @@ -107,36 +107,36 @@ class RocksDBColumnFamilyTests : RocksDBTests { } func testSwift_ColumnFamilies_Open_ComparatorMismatch() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) }) - let columnFamily = rocks.createColumnFamilyWithName("new_cf", andOptions: { + let columnFamily = rocks.createColumnFamily(withName: "new_cf", andOptions: { (options) in - options.comparator = RocksDBComparator.comaparatorWithType(.BytewiseDescending) + options.comparator = RocksDBComparator.comaparator(with: .bytewiseDescending) }) XCTAssertNotNil(columnFamily) columnFamily?.close() rocks.close() - let names = RocksDB.listColumnFamiliesInDatabaseAtPath(self.path) + let names = RocksDB.listColumnFamiliesInDatabase(atPath: self.path) XCTAssertTrue(names.count == 2) - XCTAssertEqual(names[0] as? NSString, "default") - XCTAssertEqual(names[1] as? NSString, "new_cf") + XCTAssertEqual(names[0], "default") + XCTAssertEqual(names[1], "new_cf") let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions { (options) -> Void in - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) + descriptor.addDefaultColumnFamily { (options) -> Void in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) } - descriptor.addColumnFamilyWithName("new_cf", andOptions: { (options) -> Void in - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) + descriptor.addColumnFamily(withName: "new_cf", andOptions: { (options) -> Void in + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) }) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true }) @@ -144,56 +144,56 @@ class RocksDBColumnFamilyTests : RocksDBTests { } func testSwift_ColumnFamilies_CRUD() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("df_value"), forKey: Data("df_key1")) - try! rocks.setData(Data("df_value"), forKey: Data("df_key2")) + try! rocks.setData("df_value", forKey: "df_key1") + try! rocks.setData("df_value", forKey: "df_key2") - let columnFamily = rocks.createColumnFamilyWithName("new_cf", andOptions:nil) + let columnFamily = rocks.createColumnFamily(withName: "new_cf", andOptions: nil) XCTAssertNotNil(columnFamily) - try! columnFamily?.setData(Data("cf_value"), forKey: Data("cf_key1")) - try! columnFamily?.setData(Data("cf_value"), forKey: Data("cf_key2")) + try! columnFamily?.setData("cf_value", forKey: "cf_key1") + try! columnFamily?.setData("cf_value", forKey: "cf_key2") columnFamily?.close() rocks.close() let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions(nil) - descriptor.addColumnFamilyWithName("new_cf", andOptions: nil) + descriptor.addDefaultColumnFamily(options: nil) + descriptor.addColumnFamily(withName: "new_cf", andOptions: nil) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true options.createMissingColumnFamilies = true }) - let defaultColumnFamily = rocks.columnFamilies()[0] as! RocksDBColumnFamily - let newColumnFamily = rocks.columnFamilies()[1] as! RocksDBColumnFamily + let defaultColumnFamily = rocks.columnFamilies()[0] + let newColumnFamily = rocks.columnFamilies()[1] - XCTAssertEqual(try! rocks.dataForKey(Data("df_key1")), Data("df_value")) - XCTAssertEqual(try! rocks.dataForKey(Data("df_key2")), Data("df_value")) - XCTAssertNil(try? rocks.dataForKey(Data("cf_key1"))) - XCTAssertNil(try? rocks.dataForKey(Data("cf_key2"))) + XCTAssertEqual(try! rocks.data(forKey: "df_key1"), "df_value".data) + XCTAssertEqual(try! rocks.data(forKey: "df_key2"), "df_value".data) + XCTAssertNil(try? rocks.data(forKey: "cf_key1")) + XCTAssertNil(try? rocks.data(forKey: "cf_key2")) - XCTAssertEqual(try! defaultColumnFamily.dataForKey(Data("df_key1")), Data("df_value")) - XCTAssertEqual(try! defaultColumnFamily.dataForKey(Data("df_key2")), Data("df_value")) + XCTAssertEqual(try! defaultColumnFamily.data(forKey: "df_key1"), "df_value".data) + XCTAssertEqual(try! defaultColumnFamily.data(forKey: "df_key2"), "df_value".data) - XCTAssertNil(try? defaultColumnFamily.dataForKey(Data("cf_key1"))) - XCTAssertNil(try? defaultColumnFamily.dataForKey(Data("cf_key2"))) + XCTAssertNil(try? defaultColumnFamily.data(forKey: "cf_key1")) + XCTAssertNil(try? defaultColumnFamily.data(forKey: "cf_key2")) - XCTAssertEqual(try! newColumnFamily.dataForKey(Data("cf_key1")), Data("cf_value")) - XCTAssertEqual(try! newColumnFamily.dataForKey(Data("cf_key2")), Data("cf_value")) + XCTAssertEqual(try! newColumnFamily.data(forKey: "cf_key1"), "cf_value".data) + XCTAssertEqual(try! newColumnFamily.data(forKey: "cf_key2"), "cf_value".data) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("df_key1"))) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("df_key2"))) + XCTAssertNil(try? newColumnFamily.data(forKey: "df_key1")) + XCTAssertNil(try? newColumnFamily.data(forKey: "df_key2")) - try! newColumnFamily.deleteDataForKey(Data("cf_key1")) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("cf_key1"))) + try! newColumnFamily.deleteData(forKey: "cf_key1") + XCTAssertNil(try? newColumnFamily.data(forKey: "cf_key1")) - try! newColumnFamily.deleteDataForKey(Data("cf_key1")) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("cf_key1"))) + try! newColumnFamily.deleteData(forKey: "cf_key1") + XCTAssertNil(try? newColumnFamily.data(forKey: "cf_key1")) defaultColumnFamily.close() newColumnFamily.close() @@ -202,39 +202,39 @@ class RocksDBColumnFamilyTests : RocksDBTests { func testSwift_ColumnFamilies_WriteBatch() { let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions(nil) - descriptor.addColumnFamilyWithName("new_cf", andOptions: nil) + descriptor.addDefaultColumnFamily(options: nil) + descriptor.addColumnFamily(withName: "new_cf", andOptions: nil) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true options.createMissingColumnFamilies = true }) - let defaultColumnFamily = rocks.columnFamilies()[0] as! RocksDBColumnFamily - let newColumnFamily = rocks.columnFamilies()[1] as! RocksDBColumnFamily + let defaultColumnFamily = rocks.columnFamilies()[0] + let newColumnFamily = rocks.columnFamilies()[1] - try! newColumnFamily.setData(Data("xyz_value"), forKey: Data("xyz")) + try! newColumnFamily.setData("xyz_value", forKey: "xyz") let batch = newColumnFamily.writeBatch() - batch.setData(Data("cf_value1"), forKey:Data("cf_key1")) - batch.setData(Data("df_value"), forKey:Data("df_key"), inColumnFamily:defaultColumnFamily) - batch.setData(Data("cf_value2"), forKey:Data("cf_key2")) - batch.deleteDataForKey(Data("xyz"), inColumnFamily:defaultColumnFamily) - batch.deleteDataForKey(Data("xyz")) + batch.setData("cf_value1", forKey:"cf_key1") + batch.setData("df_value", forKey:"df_key", in:defaultColumnFamily) + batch.setData("cf_value2", forKey:"cf_key2") + batch.deleteData(forKey: "xyz", in:defaultColumnFamily) + batch.deleteData(forKey: "xyz") try! rocks.applyWriteBatch(batch, writeOptions:nil) - XCTAssertEqual(try! defaultColumnFamily.dataForKey(Data("df_key")), Data("df_value")) - XCTAssertNil(try? defaultColumnFamily.dataForKey(Data("df_key1"))) - XCTAssertNil(try? defaultColumnFamily.dataForKey(Data("df_key2"))) + XCTAssertEqual(try! defaultColumnFamily.data(forKey: "df_key"), "df_value".data) + XCTAssertNil(try? defaultColumnFamily.data(forKey: "df_key1")) + XCTAssertNil(try? defaultColumnFamily.data(forKey: "df_key2")) - XCTAssertEqual(try! newColumnFamily.dataForKey(Data("cf_key1")), Data("cf_value1")) - XCTAssertEqual(try! newColumnFamily.dataForKey(Data("cf_key2")), Data("cf_value2")) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("df_key"))) + XCTAssertEqual(try! newColumnFamily.data(forKey: "cf_key1"), "cf_value1".data) + XCTAssertEqual(try! newColumnFamily.data(forKey: "cf_key2"), "cf_value2".data) + XCTAssertNil(try? newColumnFamily.data(forKey: "df_key")) - XCTAssertNil(try? defaultColumnFamily.dataForKey(Data("xyz"))) - XCTAssertNil(try? newColumnFamily.dataForKey(Data("xyz"))) + XCTAssertNil(try? defaultColumnFamily.data(forKey: "xyz")) + XCTAssertNil(try? newColumnFamily.data(forKey: "xyz")) defaultColumnFamily.close() newColumnFamily.close() @@ -243,31 +243,31 @@ class RocksDBColumnFamilyTests : RocksDBTests { func testSwift_ColumnFamilies_Iterator() { let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions(nil) - descriptor.addColumnFamilyWithName("new_cf", andOptions: nil) + descriptor.addDefaultColumnFamily(options: nil) + descriptor.addColumnFamily(withName: "new_cf", andOptions: nil) - rocks = RocksDB.databaseAtPath(self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true options.createMissingColumnFamilies = true }) - let defaultColumnFamily = rocks.columnFamilies()[0] as! RocksDBColumnFamily - let newColumnFamily = rocks.columnFamilies()[1] as! RocksDBColumnFamily + let defaultColumnFamily = rocks.columnFamilies()[0] + let newColumnFamily = rocks.columnFamilies()[1] - try! defaultColumnFamily.setData(Data("df_value1"), forKey: Data("df_key1")) - try! defaultColumnFamily.setData(Data("df_value2"), forKey: Data("df_key2")) + try! defaultColumnFamily.setData("df_value1", forKey: "df_key1") + try! defaultColumnFamily.setData("df_value2", forKey: "df_key2") - try! newColumnFamily.setData(Data("cf_value1"), forKey: Data("cf_key1")) - try! newColumnFamily.setData(Data("cf_value2"), forKey: Data("cf_key2")) + try! newColumnFamily.setData("cf_value1", forKey: "cf_key1") + try! newColumnFamily.setData("cf_value2", forKey: "cf_key2") let dfIterator = defaultColumnFamily.iterator() - let actual = NSMutableArray() + var actual = [String]() dfIterator.seekToFirst() while dfIterator.isValid() { - actual.addObject(Str(dfIterator.key() as! NSData)) - actual.addObject(Str(dfIterator.value() as! NSData)) + actual.append(String(data: dfIterator.key(), encoding: .utf8)!) + actual.append(String(data: dfIterator.value(), encoding: .utf8)!) dfIterator.next() } @@ -278,12 +278,12 @@ class RocksDBColumnFamilyTests : RocksDBTests { let cfIterator = newColumnFamily.iterator() - actual.removeAllObjects() + actual.removeAll() cfIterator.seekToFirst() while cfIterator.isValid() { - actual.addObject(Str(cfIterator.key() as! NSData)) - actual.addObject(Str(cfIterator.value() as! NSData)) + actual.append(String(data: cfIterator.key(), encoding: .utf8)!) + actual.append(String(data: cfIterator.value(), encoding: .utf8)!) cfIterator.next() } diff --git a/Tests/RocksDBComparatorTests.mm b/Tests/RocksDBComparatorTests.mm index 31efe21..2af3196 100644 --- a/Tests/RocksDBComparatorTests.mm +++ b/Tests/RocksDBComparatorTests.mm @@ -21,29 +21,29 @@ - (void)testComparator_Native_Bytewise_Ascending options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorBytewiseAscending]; }]; - [_rocks setData:Data(@"abc1") forKey:Data(@"abc1") error:nil]; - [_rocks setData:Data(@"abc2") forKey:Data(@"abc2") error:nil]; - [_rocks setData:Data(@"abc3") forKey:Data(@"abc3") error:nil]; + [_rocks setData:@"abc1".data forKey:@"abc1".data error:nil]; + [_rocks setData:@"abc2".data forKey:@"abc2".data error:nil]; + [_rocks setData:@"abc3".data forKey:@"abc3".data error:nil]; RocksDBIterator *iterator = [_rocks iterator]; [iterator seekToFirst]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc1")); - XCTAssertEqualObjects(iterator.value, Data(@"abc1")); + XCTAssertEqualObjects(iterator.key, @"abc1".data); + XCTAssertEqualObjects(iterator.value, @"abc1".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc2")); - XCTAssertEqualObjects(iterator.value, Data(@"abc2")); + XCTAssertEqualObjects(iterator.key, @"abc2".data); + XCTAssertEqualObjects(iterator.value, @"abc2".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc3")); - XCTAssertEqualObjects(iterator.value, Data(@"abc3")); + XCTAssertEqualObjects(iterator.key, @"abc3".data); + XCTAssertEqualObjects(iterator.value, @"abc3".data); [iterator next]; @@ -52,14 +52,14 @@ - (void)testComparator_Native_Bytewise_Ascending [iterator seekToLast]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc3")); - XCTAssertEqualObjects(iterator.value, Data(@"abc3")); + XCTAssertEqualObjects(iterator.key, @"abc3".data); + XCTAssertEqualObjects(iterator.value, @"abc3".data); - [iterator seekToKey:Data(@"abc")]; + [iterator seekToKey:@"abc".data]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc1")); - XCTAssertEqualObjects(iterator.value, Data(@"abc1")); + XCTAssertEqualObjects(iterator.key, @"abc1".data); + XCTAssertEqualObjects(iterator.value, @"abc1".data); [iterator close]; } @@ -71,29 +71,29 @@ - (void)testComparator_Native_Bytewise_Descending options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorBytewiseDescending]; }]; - [_rocks setData:Data(@"abc1") forKey:Data(@"abc1") error:nil]; - [_rocks setData:Data(@"abc2") forKey:Data(@"abc2") error:nil]; - [_rocks setData:Data(@"abc3") forKey:Data(@"abc3") error:nil]; + [_rocks setData:@"abc1".data forKey:@"abc1".data error:nil]; + [_rocks setData:@"abc2".data forKey:@"abc2".data error:nil]; + [_rocks setData:@"abc3".data forKey:@"abc3".data error:nil]; RocksDBIterator *iterator = [_rocks iterator]; [iterator seekToFirst]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc3")); - XCTAssertEqualObjects(iterator.value, Data(@"abc3")); + XCTAssertEqualObjects(iterator.key, @"abc3".data); + XCTAssertEqualObjects(iterator.value, @"abc3".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc2")); - XCTAssertEqualObjects(iterator.value, Data(@"abc2")); + XCTAssertEqualObjects(iterator.key, @"abc2".data); + XCTAssertEqualObjects(iterator.value, @"abc2".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc1")); - XCTAssertEqualObjects(iterator.value, Data(@"abc1")); + XCTAssertEqualObjects(iterator.key, @"abc1".data); + XCTAssertEqualObjects(iterator.value, @"abc1".data); [iterator next]; @@ -102,18 +102,18 @@ - (void)testComparator_Native_Bytewise_Descending [iterator seekToLast]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc1")); - XCTAssertEqualObjects(iterator.value, Data(@"abc1")); + XCTAssertEqualObjects(iterator.key, @"abc1".data); + XCTAssertEqualObjects(iterator.value, @"abc1".data); - [iterator seekToKey:Data(@"abc")]; + [iterator seekToKey:@"abc".data]; XCTAssertFalse(iterator.isValid); - [iterator seekToKey:Data(@"abc999")]; + [iterator seekToKey:@"abc999".data]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"abc3")); - XCTAssertEqualObjects(iterator.value, Data(@"abc3")); + XCTAssertEqualObjects(iterator.key, @"abc3".data); + XCTAssertEqualObjects(iterator.value, @"abc3".data); [iterator close]; } @@ -123,7 +123,6 @@ - (void)testComparator_StringCompare_Ascending _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorStringCompareAscending]; - options.keyType = RocksDBTypeNSString; }]; @@ -131,7 +130,7 @@ - (void)testComparator_StringCompare_Ascending for (int i = 0; i < 10000; i++) { NSString *str = [NSString stringWithFormat:@"A%d", i]; [expected addObject:str]; - [_rocks setData:Data(str) forKey:Data(str) error:nil]; + [_rocks setData:str.data forKey:str.data error:nil]; } /* Expected Array: [A0, A1, A10, A100, A1000, A1001, A1019, A102, A1020, ...] */ @@ -139,8 +138,8 @@ - (void)testComparator_StringCompare_Ascending __block NSUInteger idx = 0; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - XCTAssertEqualObjects(key, expected[idx]); + [iterator enumerateKeysUsingBlock:^(NSData *key, BOOL *stop) { + XCTAssertEqualObjects([[NSString alloc] initWithData:key], expected[idx]); idx++; }]; } @@ -150,7 +149,6 @@ - (void)testComparator_StringCompare_Descending _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorStringCompareDescending]; - options.keyType = RocksDBTypeNSString; }]; @@ -158,7 +156,7 @@ - (void)testComparator_StringCompare_Descending for (int i = 0; i < 10000; i++) { NSString *str = [NSString stringWithFormat:@"A%d", i]; [expected addObject:str]; - [_rocks setData:Data(str) forKey:Data(str) error:nil]; + [_rocks setData:str.data forKey:str.data error:nil]; } /* Expected Array: [A9999, A9998 .. A9990, A999, A9989, ...] */ @@ -166,90 +164,10 @@ - (void)testComparator_StringCompare_Descending __block NSUInteger idx = 9999; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - XCTAssertEqualObjects(key, expected[idx]); + [iterator enumerateKeysUsingBlock:^(NSData * key, BOOL *stop) { + XCTAssertEqualObjects([[NSString alloc] initWithData:key], expected[idx]); idx--; }]; } -- (void)testComparator_Number_Ascending -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorNumberAscending]; - - options.keyEncoder = ^ NSData * (id key) { - u_int32_t r = [key unsignedIntValue]; - return NumData(r); - }; - options.keyDecoder = ^ id (NSData *data) { - if (data == nil) return nil; - u_int32_t r; - Val(data, r); - return @(r); - }; - }]; - - for (int i = 0; i < 10000; i++) { - u_int32_t r = arc4random_uniform(UINT32_MAX); - if ([_rocks objectForKey:@(r) error:nil] != nil) { - i--; - } else { - [_rocks setObject:Data(@"value") forKey:@(r) error:nil]; - } - } - - __block NSUInteger count = 0; - __block NSNumber *lastKey = @(0); - - RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - XCTAssertGreaterThanOrEqual([key unsignedIntValue], [lastKey unsignedIntValue]); - lastKey = key; - count++; - }]; - - XCTAssertEqual(count, 10000); -} - -- (void)testComparator_Number_Descending -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.comparator = [RocksDBComparator comaparatorWithType:RocksDBComparatorNumberDescending]; - - options.keyEncoder = ^ NSData * (id key) { - u_int32_t r = [key unsignedIntValue]; - return NumData(r); - }; - options.keyDecoder = ^ id (NSData *data) { - if (data == nil) return nil; - u_int32_t r; - Val(data, r); - return @(r); - }; - }]; - - for (int i = 0; i < 10000; i++) { - u_int32_t r = arc4random_uniform(UINT32_MAX); - if ([_rocks objectForKey:@(r) error:nil] != nil) { - i--; - } else { - [_rocks setObject:Data(@"value") forKey:@(r) error:nil]; - } - } - - __block NSUInteger count = 0; - __block NSNumber *lastKey = @(UINT32_MAX); - - RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - XCTAssertLessThanOrEqual([key unsignedIntValue], [lastKey unsignedIntValue]); - lastKey = key; - count++; - }]; - - XCTAssertEqual(count, 10000); -} - @end diff --git a/Tests/RocksDBComparatorTests.swift b/Tests/RocksDBComparatorTests.swift index 8414f54..cd80860 100644 --- a/Tests/RocksDBComparatorTests.swift +++ b/Tests/RocksDBComparatorTests.swift @@ -12,34 +12,34 @@ import ObjectiveRocks class RocksDBComparatorTests : RocksDBTests { func testSwift_Comparator_Native_Bytewise_Ascending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.BytewiseAscending) + options.comparator = RocksDBComparator.comaparator(with: .bytewiseAscending) }) - try! rocks.setData(Data("abc1"), forKey: Data("abc1")) - try! rocks.setData(Data("abc2"), forKey: Data("abc2")) - try! rocks.setData(Data("abc3"), forKey: Data("abc3")) + try! rocks.setData("abc1", forKey: "abc1") + try! rocks.setData("abc2", forKey: "abc2") + try! rocks.setData("abc3", forKey: "abc3") let iterator = rocks.iterator() iterator.seekToFirst() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc1")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc1")) + XCTAssertEqual(iterator.key(), "abc1".data) + XCTAssertEqual(iterator.value(), "abc1".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc2")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc2")) + XCTAssertEqual(iterator.key(), "abc2".data) + XCTAssertEqual(iterator.value(), "abc2".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc3")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc3")) + XCTAssertEqual(iterator.key(), "abc3".data) + XCTAssertEqual(iterator.value(), "abc3".data) iterator.next() @@ -48,47 +48,47 @@ class RocksDBComparatorTests : RocksDBTests { iterator.seekToLast() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc3")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc3")) + XCTAssertEqual(iterator.key(), "abc3".data) + XCTAssertEqual(iterator.value(), "abc3".data) - iterator.seekToKey(Data("abc")) + iterator.seek(toKey: "abc") XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc1")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc1")) + XCTAssertEqual(iterator.key(), "abc1".data) + XCTAssertEqual(iterator.value(), "abc1".data) iterator.close() } func testSwift_Comparator_Native_Bytewise_Descending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.BytewiseDescending) + options.comparator = RocksDBComparator.comaparator(with: .bytewiseDescending) }) - try! rocks.setData(Data("abc1"), forKey: Data("abc1")) - try! rocks.setData(Data("abc2"), forKey: Data("abc2")) - try! rocks.setData(Data("abc3"), forKey: Data("abc3")) + try! rocks.setData("abc1", forKey: "abc1") + try! rocks.setData("abc2", forKey: "abc2") + try! rocks.setData("abc3", forKey: "abc3") let iterator = rocks.iterator() iterator.seekToFirst() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc3")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc3")) + XCTAssertEqual(iterator.key(), "abc3".data) + XCTAssertEqual(iterator.value(), "abc3".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc2")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc2")) + XCTAssertEqual(iterator.key(), "abc2".data) + XCTAssertEqual(iterator.value(), "abc2".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc1")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc1")) + XCTAssertEqual(iterator.key(), "abc1".data) + XCTAssertEqual(iterator.value(), "abc1".data) iterator.next() @@ -97,163 +97,71 @@ class RocksDBComparatorTests : RocksDBTests { iterator.seekToLast() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc1")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc1")) + XCTAssertEqual(iterator.key(), "abc1".data) + XCTAssertEqual(iterator.value(), "abc1".data) - iterator.seekToKey(Data("abc")) + iterator.seek(toKey: "abc") XCTAssertFalse(iterator.isValid()) - iterator.seekToKey(Data("abc999")) + iterator.seek(toKey: "abc999") XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("abc3")) - XCTAssertEqual(iterator.value() as? NSData, Data("abc3")) + XCTAssertEqual(iterator.key(), "abc3".data) + XCTAssertEqual(iterator.value(), "abc3".data) iterator.close() } func testSwift_Comparator_StringCompare_Ascending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareAscending) - options.keyType = .NSString - options.valueType = .NSString + options.comparator = RocksDBComparator.comaparator(with: .stringCompareAscending) }) - let expected = NSMutableArray() + var expected = [String]() for i in 0..<10000 { - let str = NSString(format: "a%d", i) - expected.addObject(str) - try! rocks.setObject(str, forKey: str) + let str = String(format: "a%d", i) + expected.append(str) + try! rocks.setData(str.data, forKey: str.data) } /* Expected Array: [A0, A1, A10, A100, A1000, A1001, A1019, A102, A1020, ...] */ - expected.sortUsingSelector(#selector(NSString.compare(_:))) + expected.sort() let iterator = rocks.iterator() var idx = 0 - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - XCTAssertEqual(key as? NSString, expected[idx] as? NSString) + iterator.enumerateKeys { (key, stop) -> Void in + XCTAssertEqual(String(data: key, encoding: .utf8)!, expected[idx]) idx += 1 } } func testSwift_Comparator_StringCompare_Descending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.StringCompareDescending) - options.keyType = .NSString - options.valueType = .NSString + options.comparator = RocksDBComparator.comaparator(with: .stringCompareDescending) }) - let expected = NSMutableArray() + var expected = [String]() for i in 0..<10000 { - let str = NSString(format: "a%d", i) - expected.addObject(str) - try! rocks.setObject(str, forKey: str) + let str = String(format: "a%d", i) + expected.append(str) + try! rocks.setData(str.data, forKey: str.data) } /* Expected Array: [A9999, A9998 .. A9990, A999, A9989, ...] */ - expected.sortUsingSelector(#selector(NSNumber.compare(_:))) + expected.sort() let iterator = rocks.iterator() var idx = 9999 - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - XCTAssertEqual(key as? NSString, expected[idx] as? NSString) + iterator.enumerateKeys { (key, stop) -> Void in + XCTAssertEqual(String(data: key, encoding: .utf8), expected[idx]) idx -= 1 } } - - func testSwift_Comparator_Number_Ascending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.NumberAscending) - options.keyEncoder = { - (number) -> NSData in - var r: UInt = number.unsignedIntegerValue - return NSData(bytes: &r, length: sizeof(UInt)) - } - options.keyDecoder = { - (data) -> AnyObject in - if (data == nil) { - return Optional.None! - } - var r: UInt = 0 - data.getBytes(&r, length: sizeof(NSInteger)) - return NSNumber(unsignedInteger: r) - } - }) - - var i = 0 - while i < 10000 { - let r = arc4random_uniform(UINT32_MAX); - let value = try? rocks.objectForKey(NSNumber(unsignedInt: r)) - if value as? NSData == nil { - try! rocks.setObject(Data("value"), forKey: NSNumber(unsignedInt: r)) - i += 1 - } - } - - var count = 0 - var lastKey: NSNumber = NSNumber(unsignedInteger: 0) - - let iterator = rocks.iterator() - - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - XCTAssertTrue(lastKey.compare(key as! NSNumber) == .OrderedAscending) - lastKey = key as! NSNumber - count += 1 - } - - XCTAssertEqual(count, 10000); - } - - func testSwift_Comparator_Number_Decending() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.comparator = RocksDBComparator.comaparatorWithType(.NumberDescending) - options.keyEncoder = { - (number) -> NSData in - var r: UInt = number.unsignedIntegerValue - return NSData(bytes: &r, length: sizeof(UInt)) - } - options.keyDecoder = { - (data) -> AnyObject in - if (data == nil) { - return Optional.None! - } - var r: UInt = 0 - data.getBytes(&r, length: sizeof(NSInteger)) - return NSNumber(unsignedInteger: r) - } - }) - - var i = 0 - while i < 10000 { - let r = arc4random_uniform(UINT32_MAX); - let value = try? rocks.objectForKey(NSNumber(unsignedInt: r)) - if value as? NSData == nil { - try! rocks.setObject(Data("value"), forKey: NSNumber(unsignedInt: r)) - i += 1 - } - } - - var count = 0 - var lastKey: NSNumber = NSNumber(unsignedInt: UINT32_MAX) - - let iterator = rocks.iterator() - - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - XCTAssertTrue(lastKey.compare(key as! NSNumber) == .OrderedDescending) - lastKey = key as! NSNumber - count += 1 - } - - XCTAssertEqual(count, 10000); - } } diff --git a/Tests/RocksDBIndexedWriteBatchTests.m b/Tests/RocksDBIndexedWriteBatchTests.m index 56714cb..5e85f2f 100644 --- a/Tests/RocksDBIndexedWriteBatchTests.m +++ b/Tests/RocksDBIndexedWriteBatchTests.m @@ -14,6 +14,4 @@ @interface RocksDBIndexedWriteBatchTests : RocksDBTests @implementation RocksDBIndexedWriteBatchTests - - @end diff --git a/Tests/RocksDBIteratorTests.mm b/Tests/RocksDBIteratorTests.mm index 2b5dc56..8c94629 100644 --- a/Tests/RocksDBIteratorTests.mm +++ b/Tests/RocksDBIteratorTests.mm @@ -20,14 +20,14 @@ - (void)testDB_Iterator options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; for ([iterator seekToFirst]; [iterator isValid]; [iterator next]) { - [actual addObject:Str([iterator key])]; + [actual addObject:[[NSString alloc] initWithData:iterator.key]]; } NSArray *expected = @[ @"key 1", @"key 2", @"key 3" ]; @@ -42,22 +42,22 @@ - (void)testDB_Iterator_Seek options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; RocksDBIterator *iterator = [_rocks iterator]; [iterator seekToFirst]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"key 1")); - XCTAssertEqualObjects(iterator.value, Data(@"value 1")); + XCTAssertEqualObjects(iterator.key, @"key 1".data); + XCTAssertEqualObjects(iterator.value, @"value 1".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"key 2")); - XCTAssertEqualObjects(iterator.value, Data(@"value 2")); + XCTAssertEqualObjects(iterator.key, @"key 2".data); + XCTAssertEqualObjects(iterator.value, @"value 2".data); [iterator next]; @@ -67,15 +67,15 @@ - (void)testDB_Iterator_Seek [iterator previous]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"key 1")); - XCTAssertEqualObjects(iterator.value, Data(@"value 1")); + XCTAssertEqualObjects(iterator.key, @"key 1".data); + XCTAssertEqualObjects(iterator.value, @"value 1".data); [iterator seekToFirst]; [iterator seekToLast]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, Data(@"key 2")); - XCTAssertEqualObjects(iterator.value, Data(@"value 2")); + XCTAssertEqualObjects(iterator.key, @"key 2".data); + XCTAssertEqualObjects(iterator.value, @"value 2".data); [iterator close]; } @@ -86,14 +86,14 @@ - (void)testDB_Iterator_EnumerateKeys options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"key 1", @"key 2", @"key 3" ]; @@ -108,14 +108,14 @@ - (void)testDB_Iterator_EnumerateKeys_Reverse options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysInReverse:YES usingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysInReverse:YES usingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"key 3", @"key 2", @"key 1" ]; @@ -130,15 +130,15 @@ - (void)testDB_Iterator_EnumerateKeys_RangeStart options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysInRange:RocksDBMakeKeyRange(Data(@"key 2"), nil) reverse:NO usingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysInRange:RocksDBMakeKeyRange(@"key 2".data, nil) reverse:NO usingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"key 2", @"key 3", @"key 4" ]; @@ -153,15 +153,15 @@ - (void)testDB_Iterator_EnumerateKeys_RangeEnd options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysInRange:RocksDBMakeKeyRange(nil, Data(@"key 4")) reverse:NO usingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysInRange:RocksDBMakeKeyRange(nil, @"key 4".data) reverse:NO usingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"key 1", @"key 2", @"key 3" ]; @@ -176,15 +176,15 @@ - (void)testDB_Iterator_EnumerateKeys_RangeStartEnd options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysInRange:RocksDBMakeKeyRange(Data(@"key 2"), Data(@"key 4")) reverse:NO usingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysInRange:RocksDBMakeKeyRange(@"key 2".data, @"key 4".data) reverse:NO usingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"key 2", @"key 3" ]; @@ -193,45 +193,21 @@ - (void)testDB_Iterator_EnumerateKeys_RangeStartEnd [iterator close]; } -- (void)testDB_Iterator_EnumerateKeys_Encoded -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; - }]; - - [_rocks setObject:@"value 1" forKey:@"Key 1" error:nil]; - [_rocks setObject:@"value 2" forKey:@"Key 2" error:nil]; - [_rocks setObject:@"value 3" forKey:@"Key 3" error:nil]; - - NSMutableArray *actual = [NSMutableArray array]; - RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - [actual addObject:key]; - }]; - - NSArray *expected = @[ @"Key 1", @"Key 2", @"Key 3" ]; - XCTAssertEqualObjects(actual, expected); - - [iterator close]; -} - - (void)testDB_Iterator_EnumerateKeysAndValues { _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesUsingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:Str(key)]; - [actual addObject:Str(value)]; + [iterator enumerateKeysAndValuesUsingBlock:^(NSData *key, NSData *value, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; + [actual addObject:[[NSString alloc] initWithData:value]]; }]; NSArray *expected = @[ @"key 1", @"value 1", @"key 2", @"value 2", @"key 3", @"value 3" ]; @@ -246,15 +222,15 @@ - (void)testDB_Iterator_EnumerateKeysAndValues_Reverse options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesInReverse:YES usingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:Str(key)]; - [actual addObject:Str(value)]; + [iterator enumerateKeysAndValuesInReverse:YES usingBlock:^(NSData *key, NSData *value, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; + [actual addObject:[[NSString alloc] initWithData:value]]; }]; NSArray *expected = @[ @"key 3", @"value 3", @"key 2", @"value 2", @"key 1", @"value 1" ]; @@ -269,18 +245,18 @@ - (void)testDB_Iterator_EnumerateKeysAndValues_RangeStart options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(Data(@"key 2"), nil) + [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(@"key 2".data, nil) reverse:NO - usingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:Str(key)]; - [actual addObject:Str(value)]; + usingBlock:^(NSData *key, NSData *value, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; + [actual addObject:[[NSString alloc] initWithData:value]]; }]; NSArray *expected = @[ @"key 2", @"value 2", @"key 3", @"value 3", @"key 4", @"value 4" ]; @@ -295,18 +271,18 @@ - (void)testDB_Iterator_EnumerateKeysAndValues_RangeEnd options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(nil, Data(@"key 4")) + [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(nil, @"key 4".data) reverse:NO - usingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:Str(key)]; - [actual addObject:Str(value)]; + usingBlock:^(NSData *key, NSData *value, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; + [actual addObject:[[NSString alloc] initWithData:value]]; }]; NSArray *expected = @[ @"key 1", @"value 1", @"key 2", @"value 2", @"key 3", @"value 3" ]; @@ -321,18 +297,18 @@ - (void)testDB_Iterator_EnumerateKeysAndValues_RangeStartEnd options.createIfMissing = YES; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; - [_rocks setData:Data(@"value 4") forKey:Data(@"key 4") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; + [_rocks setData:@"value 4".data forKey:@"key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(Data(@"key 2"), Data(@"key 4")) + [iterator enumerateKeysAndValuesInRange:RocksDBMakeKeyRange(@"key 2".data, @"key 4".data) reverse:NO - usingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:Str(key)]; - [actual addObject:Str(value)]; + usingBlock:^(NSData *key, NSData *value, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; + [actual addObject:[[NSString alloc] initWithData:value]]; }]; @@ -342,29 +318,4 @@ - (void)testDB_Iterator_EnumerateKeysAndValues_RangeStartEnd [iterator close]; } -- (void)testDB_Iterator_EnumerateKeysAndValues_Encoded -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; - }]; - - [_rocks setObject:@"value 1" forKey:@"Key 1" error:nil]; - [_rocks setObject:@"value 2" forKey:@"Key 2" error:nil]; - [_rocks setObject:@"value 3" forKey:@"Key 3" error:nil]; - - NSMutableArray *actual = [NSMutableArray array]; - RocksDBIterator *iterator = [_rocks iterator]; - [iterator enumerateKeysAndValuesUsingBlock:^(id key, id value, BOOL *stop) { - [actual addObject:key]; - [actual addObject:value]; - }]; - - NSArray *expected = @[ @"Key 1", @"value 1", @"Key 2", @"value 2", @"Key 3", @"value 3" ]; - XCTAssertEqualObjects(actual, expected); - - [iterator close]; -} - @end diff --git a/Tests/RocksDBIteratorTests.swift b/Tests/RocksDBIteratorTests.swift index 496f095..3f83d83 100644 --- a/Tests/RocksDBIteratorTests.swift +++ b/Tests/RocksDBIteratorTests.swift @@ -12,20 +12,20 @@ import ObjectiveRocks class RocksDBIteratorTests : RocksDBTests { func testSwift_DB_Iterator() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() iterator.seekToFirst() while iterator.isValid() { - actual.addObject(Str(iterator.key() as! NSData)) + actual.append(String(data: iterator.key(), encoding: .utf8)!) iterator.next() } @@ -36,26 +36,26 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_Seek() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") let iterator = rocks.iterator() iterator.seekToFirst() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("key 1")) - XCTAssertEqual(iterator.value() as? NSData, Data("value 1")) + XCTAssertEqual(iterator.key(), "key 1".data) + XCTAssertEqual(iterator.value(), "value 1".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("key 2")) - XCTAssertEqual(iterator.value() as? NSData, Data("value 2")) + XCTAssertEqual(iterator.key(), "key 2".data) + XCTAssertEqual(iterator.value(), "value 2".data) iterator.next() @@ -65,36 +65,35 @@ class RocksDBIteratorTests : RocksDBTests { iterator.previous() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("key 1")) - XCTAssertEqual(iterator.value() as? NSData, Data("value 1")) + XCTAssertEqual(iterator.key(), "key 1".data) + XCTAssertEqual(iterator.value(), "value 1".data) iterator.seekToFirst() iterator.seekToLast() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSData, Data("key 2")) - XCTAssertEqual(iterator.value() as? NSData, Data("value 2")) + XCTAssertEqual(iterator.key(), "key 2".data) + XCTAssertEqual(iterator.value(), "value 2".data) iterator.close() } func testSwift_DB_Iterator_EnumerateKeys() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } - let expected = [ "key 1", "key 2", "key 3" ] XCTAssertEqual(actual, expected) @@ -102,19 +101,19 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeys_Reverse() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysInReverse(true, usingBlock: { (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys(inReverse: true, using: { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) }) let expected = [ "key 3", "key 2", "key 1" ] @@ -124,22 +123,20 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeys_RangeStart() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysInRange(RocksDBMakeKeyRange(Data("key 2"), nil), reverse: false) - { - (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys(in: RocksDBMakeKeyRange("key 2", nil), reverse: false) { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } let expected = [ "key 2", "key 3", "key 4" ] @@ -149,22 +146,20 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeys_RangeEnd() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysInRange(RocksDBMakeKeyRange(nil, Data("key 4")), reverse: false) - { - (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys(in: RocksDBMakeKeyRange(nil, "key 4"), reverse: false) { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } let expected = [ "key 1", "key 2", "key 3" ] @@ -174,22 +169,20 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeys_RangeStartEnd() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysInRange(RocksDBMakeKeyRange(Data("key 2"), Data("key 4")), reverse: false) - { - (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys(in: RocksDBMakeKeyRange("key 2", "key 4"), reverse: false) { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } let expected = [ "key 2", "key 3" ] @@ -198,45 +191,21 @@ class RocksDBIteratorTests : RocksDBTests { iterator.close() } - func testSwift_DB_Iterator_EnumerateKeys_Encoded() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.keyType = .NSString - options.valueType = .NSString - }) - - try! rocks.setObject("value 1", forKey: "key 1") - try! rocks.setObject("value 2", forKey: "key 2") - try! rocks.setObject("value 3", forKey: "key 3") - - let actual = NSMutableArray() - let iterator = rocks.iterator() - - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - actual.addObject(key) - } - - let expected = [ "key 1", "key 2", "key 3" ] - XCTAssertEqual(actual, expected) - - iterator.close() - } - func testSwift_DB_Iterator_EnumerateKeysAndValues() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysAndValuesUsingBlock { (key, value, stop) -> Void in - actual.addObject(Str(key as! NSData)) - actual.addObject(Str(value as! NSData)) + iterator.enumerateKeysAndValues { (key, value, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) + actual.append(String(data: value, encoding: .utf8)!) } let expected = [ "key 1", "value 1", "key 2", "value 2", "key 3", "value 3" ] @@ -246,20 +215,20 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeysAndValues_Reverse() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysAndValuesInReverse(true, usingBlock: { (key, value, stop) -> Void in - actual.addObject(Str(key as! NSData)) - actual.addObject(Str(value as! NSData)) + iterator.enumerateKeysAndValues(inReverse: true, using: { (key, value, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) + actual.append(String(data: value, encoding: .utf8)!) }) let expected = [ "key 3", "value 3", "key 2", "value 2", "key 1", "value 1" ] @@ -269,23 +238,21 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeysAndValues_RangeStart() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysAndValuesInRange(RocksDBMakeKeyRange(Data("key 2"), nil), reverse: false) - { - (key, value, stop) -> Void in - actual.addObject(Str(key as! NSData)) - actual.addObject(Str(value as! NSData)) + iterator.enumerateKeysAndValues(in: RocksDBMakeKeyRange("key 2", nil), reverse: false) { (key, value, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) + actual.append(String(data: value, encoding: .utf8)!) } let expected = [ "key 2", "value 2", "key 3", "value 3", "key 4", "value 4" ] @@ -295,23 +262,21 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeysAndValues_RangeEnd() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysAndValuesInRange(RocksDBMakeKeyRange(nil, Data("key 4")), reverse: false) - { - (key, value, stop) -> Void in - actual.addObject(Str(key as! NSData)) - actual.addObject(Str(value as! NSData)) + iterator.enumerateKeysAndValues(in: RocksDBMakeKeyRange(nil, "key 4"), reverse: false) { (key, value, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) + actual.append(String(data: value, encoding: .utf8)!) } let expected = [ "key 1", "value 1", "key 2", "value 2", "key 3", "value 3" ] @@ -321,23 +286,21 @@ class RocksDBIteratorTests : RocksDBTests { } func testSwift_DB_Iterator_EnumerateKeysAndValues_RangeStartEnd() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") + try! rocks.setData("value 4", forKey: "key 4") - let actual = NSMutableArray() + var actual = [String]() let iterator = rocks.iterator() - iterator.enumerateKeysAndValuesInRange(RocksDBMakeKeyRange(Data("key 2"), Data("key 4")), reverse: false) - { - (key, value, stop) -> Void in - actual.addObject(Str(key as! NSData)) - actual.addObject(Str(value as! NSData)) + iterator.enumerateKeysAndValues(in: RocksDBMakeKeyRange("key 2", "key 4"), reverse: false) { (key, value, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) + actual.append(String(data: value, encoding: .utf8)!) } let expected = [ "key 2", "value 2", "key 3", "value 3" ] @@ -346,29 +309,4 @@ class RocksDBIteratorTests : RocksDBTests { iterator.close() } - func testSwift_DB_Iterator_EnumerateKeysAndValues_Encoded() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.keyType = .NSString - options.valueType = .NSString - }) - - try! rocks.setObject("value 1", forKey: "key 1") - try! rocks.setObject("value 2", forKey: "key 2") - try! rocks.setObject("value 3", forKey: "key 3") - - let actual = NSMutableArray() - let iterator = rocks.iterator() - - iterator.enumerateKeysAndValuesUsingBlock { (key, value, stop) -> Void in - actual.addObject(key) - actual.addObject(value) - } - - let expected = [ "key 1", "value 1", "key 2", "value 2", "key 3", "value 3" ]; - XCTAssertEqual(actual, expected) - - iterator.close() - } } - diff --git a/Tests/RocksDBMergeOperatorTests.mm b/Tests/RocksDBMergeOperatorTests.mm index 7a3b9e6..d0fdf2f 100644 --- a/Tests/RocksDBMergeOperatorTests.mm +++ b/Tests/RocksDBMergeOperatorTests.mm @@ -8,112 +8,135 @@ #import "RocksDBTests.h" -@interface RocksDBMergeOperatorTests : RocksDBTests +#pragma mark - Categories + +@interface NSNumber (DataConvertible) +@end + +@implementation NSNumber (RocksDBDataConvertible) +- (instancetype)initWithData:(NSData *)data +{ + double_t value; + [data getBytes:&value length:sizeof(value)]; + return [self initWithDouble:value]; +} + +- (NSData *)data +{ + double_t value = self.doubleValue; + return [NSData dataWithBytes:&value length:sizeof(value)]; +} +@end + +@interface NSDictionary (DataConvertible) +@end + +@implementation NSDictionary (RocksDBDataConvertible) +- (instancetype)initWithData:(NSData *)data +{ + NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; + return [self initWithDictionary:dict]; +} + +- (NSData *)data +{ + return [NSJSONSerialization dataWithJSONObject:self options:0 error:nil]; +} +@end +#pragma mark - Tests + +@interface RocksDBMergeOperatorTests : RocksDBTests @end @implementation RocksDBMergeOperatorTests - (void)testAssociativeMergeOperator { - RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" - andBlock:^id (id key, id existingValue, id value) { - uint64_t prev = 0; - if (existingValue != nil) { - [existingValue getBytes:&prev length:sizeof(uint64_t)]; - } + id block = ^NSData * (NSData *key, NSData *existingValue, NSData *value) { + NSNumber *prev = 0; + if (existingValue != nil) { + prev = [[NSNumber alloc] initWithData:existingValue]; + } + NSNumber *plus = [[NSNumber alloc] initWithData:value]; + NSNumber *result = [NSNumber numberWithUnsignedLongLong: + (prev.unsignedLongLongValue + plus.unsignedLongLongValue)]; + return result.data; + }; - uint64_t plus; - [value getBytes:&plus length:sizeof(uint64_t)]; - - uint64_t result = prev + plus; - return [NSData dataWithBytes:&result length:sizeof(uint64_t)]; - }]; + RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" + andBlock:block]; _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.mergeOperator = mergeOp; }]; - uint64_t value = 1; - [_rocks mergeData:NumData(value) forKey:Data(@"Key 1") error:nil]; + [_rocks mergeData:@(1).data forKey:@"Key 1".data error:nil]; - value = 5; - [_rocks mergeData:NumData(value) forKey:Data(@"Key 1") error:nil]; + [_rocks mergeData:@(5).data forKey:@"Key 1".data error:nil]; - uint64_t res; - Val([_rocks dataForKey:Data(@"Key 1") error:nil], res); - - XCTAssertTrue(res == 6); + NSNumber *res = [[NSNumber alloc] initWithData:[_rocks dataForKey:@"Key 1".data error:nil]]; + XCTAssertEqual(res.unsignedLongLongValue, 6); } -- (void)testAssociativeMergeOperator_NumberAdd_Encoded +- (void)testAssociativeMergeOperator_NumberAdd { + id block = ^NSData *(NSData *key, NSData *existingValue, NSData *value) { + NSNumber *v1 = [[NSNumber alloc] initWithData:existingValue]; + NSNumber *v2 = [[NSNumber alloc] initWithData:value]; + + NSNumber *result = [[NSNumber alloc] initWithFloat:(v1.floatValue + v2.floatValue)]; + return result.data; + }; + RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" - andBlock:^id (id key, NSNumber *existingValue, NSNumber *value) { - NSNumber *result = @(existingValue.floatValue + value.floatValue); - return result; - }]; + andBlock:block]; _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.mergeOperator = mergeOp; - - options.keyType = RocksDBTypeNSString; - - options.valueEncoder = ^ NSData * (id key, id value) { - float val = [value floatValue]; - NSData *data = [NSData dataWithBytes:&val length:sizeof(val)]; - return data; - }; - options.valueDecoder = ^ NSNumber * (id key, NSData * data) { - if (data == nil) return nil; - - float value; - [data getBytes:&value length:sizeof(value)]; - return @(value); - }; }]; - [_rocks mergeObject:@(100.541) forKey:@"Key 1" error:nil]; - - [_rocks mergeObject:@(200.125) forKey:@"Key 1" error:nil]; + [_rocks mergeData:@(100.541).data forKey:@"Key 1".data error:nil]; + [_rocks mergeData:@(200.125).data forKey:@"Key 1".data error:nil]; - XCTAssertEqualWithAccuracy([[_rocks objectForKey:@"Key 1" error:nil] floatValue], 300.666, 0.0001); + NSNumber *number = [[NSNumber alloc] initWithData:[_rocks dataForKey:@"Key 1".data error:nil]]; + XCTAssertEqualWithAccuracy(number.floatValue, 300.666, 0.0001); } -- (void)testAssociativeMergeOperator_DictionaryPut_Encoded +- (void)testAssociativeMergeOperator_DictionaryPut { + id block = ^NSData *(NSData *key, NSData *existingValue, NSData *value) { + if (existingValue == nil) { + return value; + } + NSMutableDictionary *existing = [[NSMutableDictionary alloc] initWithData:existingValue]; + NSDictionary *dict = [[NSMutableDictionary alloc] initWithData:value]; + [existing addEntriesFromDictionary:dict]; + return existing.data; + }; + RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" - andBlock:^id (id key, NSMutableDictionary *existingValue, id value) { - if (existingValue != nil) { - [existingValue addEntriesFromDictionary:value]; - return existingValue; - } else { - return value; - } - }]; + andBlock:block]; _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.mergeOperator = mergeOp; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSJSONSerializable; }]; - [_rocks setObject:@{@"Key 1": @"Value 1"} forKey:@"Dict Key" error:nil]; + [_rocks setData:@{@"Key 1": @"Value 1"}.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeObject:@{@"Key 1": @"Value 1 New"} forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@{@"Key 1": @"Value 1 New"}.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeObject:@{@"Key 2": @"Value 2"} forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@{@"Key 2": @"Value 2"}.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeObject:@{@"Key 3": @"Value 3"} forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@{@"Key 3": @"Value 3"}.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeObject:@{@"Key 4": @"Value 4"} forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@{@"Key 4": @"Value 4"}.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeObject:@{@"Key 5": @"Value 5"} forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@{@"Key 5": @"Value 5"}.data forKey:@"Dict Key".data error:nil]; NSDictionary *expected = @{@"Key 1" : @"Value 1 New", @"Key 2" : @"Value 2", @@ -121,56 +144,63 @@ - (void)testAssociativeMergeOperator_DictionaryPut_Encoded @"Key 4" : @"Value 4", @"Key 5" : @"Value 5"}; - XCTAssertEqualObjects([_rocks objectForKey:@"Dict Key" error:nil], expected); + NSDictionary *actual = [[NSDictionary alloc] initWithData:[_rocks dataForKey:@"Dict Key".data error:nil]]; + XCTAssertEqualObjects(actual, expected); } -- (void)testMergeOperator_DictionaryUpdate_Encoded +- (void)testMergeOperator_DictionaryUpdate { + id partialMerge = ^NSData *(NSData * key, NSData *leftOperand, NSData *rightOperand) { + NSString *left = [[[NSString alloc] initWithData:leftOperand] componentsSeparatedByString:@":"][0]; + NSString *right = [[[NSString alloc] initWithData:rightOperand] componentsSeparatedByString:@":"][0]; + if ([left isEqualToString:right]) { + return rightOperand; + } + return nil; + }; + + id fullMerge = ^NSData *(NSData * key, NSData * _Nullable existingValue, NSArray *operandList) { + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithData:existingValue]; + + for (NSData *op in operandList) { + NSArray *comp = [[[NSString alloc] initWithData:op] componentsSeparatedByString:@":"]; + NSString *action = comp[1]; + if ([action isEqualToString:@"DELETE"]) { + [dict removeObjectForKey:comp[0]]; + } else { + dict[comp[0]] = comp[2]; + } + } + return dict.data; + }; + RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"operator" - partialMergeBlock:^id(id key, NSString *leftOperand, NSString *rightOperand) { - NSString *left = [leftOperand componentsSeparatedByString:@":"][0]; - NSString *right = [rightOperand componentsSeparatedByString:@":"][0]; - if ([left isEqualToString:right]) { - return rightOperand; - } - return nil; - } fullMergeBlock:^id(id key, NSMutableDictionary *existing, NSArray *operands) { - for (NSString *op in operands) { - NSArray *comp = [op componentsSeparatedByString:@":"]; - NSString *action = comp[1]; - if ([action isEqualToString:@"DELETE"]) { - [existing removeObjectForKey:comp[0]]; - } else { - existing[comp[0]] = comp[2]; - } - } - return existing; - }]; - + partialMergeBlock:partialMerge + fullMergeBlock:fullMerge]; + _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.mergeOperator = mergeOp; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSJSONSerializable; }]; NSDictionary *object = @{@"Key 1" : @"Value 1", @"Key 2" : @"Value 2", @"Key 3" : @"Value 3"}; - [_rocks setObject:object forKey:@"Dict Key" error:nil]; + [_rocks setData:object.data forKey:@"Dict Key".data error:nil]; - [_rocks mergeOperation:@"Key 1:UPDATE:Value X" forKey:@"Dict Key" error:nil]; - [_rocks mergeOperation:@"Key 4:INSERT:Value 4" forKey:@"Dict Key" error:nil]; - [_rocks mergeOperation:@"Key 2:DELETE" forKey:@"Dict Key" error:nil]; - [_rocks mergeOperation:@"Key 1:UPDATE:Value 1 New" forKey:@"Dict Key" error:nil]; + [_rocks mergeData:@"Key 1:UPDATE:Value X".data forKey:@"Dict Key".data error:nil]; + [_rocks mergeData:@"Key 4:INSERT:Value 4".data forKey:@"Dict Key".data error:nil]; + [_rocks mergeData:@"Key 2:DELETE".data forKey:@"Dict Key".data error:nil]; + [_rocks mergeData:@"Key 1:UPDATE:Value 1 New".data forKey:@"Dict Key".data error:nil]; NSDictionary *expected = @{@"Key 1" : @"Value 1 New", @"Key 3" : @"Value 3", @"Key 4" : @"Value 4"}; - XCTAssertEqualObjects([_rocks objectForKey:@"Dict Key" error:nil], expected); + NSDictionary *actual = [[NSDictionary alloc] initWithData:[_rocks dataForKey:@"Dict Key".data error:nil]]; + + XCTAssertEqualObjects(actual, expected); } @end diff --git a/Tests/RocksDBMergeOperatorTests.swift b/Tests/RocksDBMergeOperatorTests.swift index 818846f..1e98356 100644 --- a/Tests/RocksDBMergeOperatorTests.swift +++ b/Tests/RocksDBMergeOperatorTests.swift @@ -9,160 +9,194 @@ import XCTest import ObjectiveRocks +protocol DataConvertible { + init?(data: Data) + var data: Data { get } +} + +extension DataConvertible { + init?(data: Data) { + guard data.count == MemoryLayout.size else { + return nil + } + self = data.withUnsafeBytes { $0.pointee } + } + var data: Data { + var value = self + return Data(buffer: UnsafeBufferPointer(start: &value, count: 1)) + } +} + +extension Int : DataConvertible { } +extension Double : DataConvertible { } + +extension Dictionary { + + var data: Data { + return try! JSONSerialization.data(withJSONObject: self, options: []) + } + + mutating func update(with dict: Dictionary) { + for (key, value) in dict { + self.updateValue(value, forKey: key) + } + } +} + +extension Dictionary { + static func from(data: Data) -> [String: Any] { + return try! JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any] + } +} + class RocksDBMergeOperatorTests : RocksDBTests { func testSwift_AssociativeMergeOperator() { - let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> AnyObject in - var prev: UInt64 = 0 + + let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> Data in + let prev: Int if let existing = existing { - existing.getBytes(&prev, length: sizeof(UInt64)) + prev = Int(data: existing) ?? 0 + } else { + prev = 0 } - var plus: UInt64 = 0 - value.getBytes(&plus, length: sizeof(UInt64)) - var result: UInt64 = prev + plus - return NSData(bytes: &result, length: sizeof(UInt64)) + let plus = Int(data: value)! + return (prev + plus).data } - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.mergeOperator = mergeOp }) - var value: UInt64 = 1 - try! rocks.mergeData(NumData(value), forKey: Data("key 1")) - - value = 5 - try! rocks.mergeData(NumData(value), forKey: Data("key 1")) - - let res: UInt64 = Val(try! rocks.dataForKey(Data("key 1"))) + try! rocks.merge(1.data, forKey: "key 1") + try! rocks.merge(5.data, forKey: "key 1") - XCTAssertTrue(res == 6); + let data = try! rocks.data(forKey: "key 1") + let res = Int(data: data)! + XCTAssertEqual(res, 6) } - func testSwift_AssociativeMergeOperator_NumberAdd_Encoded() { - let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> AnyObject in - var val = value.floatValue + func testSwift_AssociativeMergeOperator_NumberAdd() { + let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> Data in + let prev: Double if let existing = existing { - val = val + existing.floatValue + prev = Double(data: existing) ?? 0 + } else { + prev = 0 } - let result: NSNumber = NSNumber(float: val) - return result + + let plus = Double(data: value)! + return (prev + plus).data } - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.mergeOperator = mergeOp - options.keyType = .NSString - - options.valueEncoder = { - (key, value) -> NSData in - let val = value.floatValue - let data = NumData(val) - return data - } - - options.valueDecoder = { - (key, data) -> NSNumber in - if (data == nil) { - return Optional.None! - } - - let value: Float = Val(data) - return NSNumber(float: value) - } }) - try! rocks.mergeObject(NSNumber(float: 100.541), forKey: "key 1") - try! rocks.mergeObject(NSNumber(float: 200.125), forKey: "key 1") + try! rocks.merge(100.541.data, forKey: "key 1") + try! rocks.merge(200.125.data, forKey: "key 1") - let result: Float = try! rocks.objectForKey("key 1").floatValue - XCTAssertEqualWithAccuracy(result, Float(300.666), accuracy: Float(0.0001)) + let data = try! rocks.data(forKey: "key 1") + let res = Double(data: data)! + XCTAssertEqualWithAccuracy(res, Double(300.666), accuracy: Double(0.0001)) } - func testSwift_AssociativeMergeOperator_DictionaryPut_Encoded() { - let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> AnyObject in + func testSwift_AssociativeMergeOperator_DictionaryPut() { + + let mergeOp = RocksDBMergeOperator(name: "operator") { (key, existing, value) -> Data in guard let existing = existing else { return value } - existing.addEntriesFromDictionary(value as! [NSObject : AnyObject]) - return existing + var dict = Dictionary.from(data: existing) + let new = Dictionary.from(data: value) + dict.update(with: new) + return dict.data } - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.mergeOperator = mergeOp - options.keyType = .NSString - options.valueType = .NSJSONSerializable }) - try! rocks.setObject(["key 1": "value 1"], forKey: "dict key") - try! rocks.mergeObject(["key 1": "value 1 new"], forKey: "dict key") - try! rocks.mergeObject(["key 2": "value 2"], forKey: "dict key") - try! rocks.mergeObject(["key 3": "value 3"], forKey: "dict key") - try! rocks.mergeObject(["key 4": "value 4"], forKey: "dict key") - try! rocks.mergeObject(["key 5": "value 5"], forKey: "dict key") + try! rocks.setData(["key 1": "value 1"].data, forKey: "dict key") + try! rocks.merge(["key 1": "value 1 new"].data, forKey: "dict key") + try! rocks.merge(["key 2": "value 2"].data, forKey: "dict key") + try! rocks.merge(["key 3": "value 3"].data, forKey: "dict key") + try! rocks.merge(["key 4": "value 4"].data, forKey: "dict key") + try! rocks.merge(["key 5": "value 5"].data, forKey: "dict key") + + let expected: [String: Any] = ["key 1" : "value 1 new", + "key 2" : "value 2", + "key 3" : "value 3", + "key 4" : "value 4", + "key 5" : "value 5"] + + let data = try! rocks.data(forKey: "dict key") + let actual = Dictionary.from(data: data) + for (key, value) in actual { + XCTAssertEqual(value as! String, expected[key] as! String) + } + } - let expected: NSDictionary = ["key 1" : "value 1 new", - "key 2" : "value 2", - "key 3" : "value 3", - "key 4" : "value 4", - "key 5" : "value 5"] + func testSwift_MergeOperator_DictionaryUpdate() { - XCTAssertEqual(try! rocks.objectForKey("dict key") as! NSDictionary, expected) - } + let partial = { (key: Data, leftOperand: Data, rightOperand: Data) -> Data? in + let left = String(data: leftOperand, encoding: .utf8)!.components(separatedBy: ":")[0] + let right = String(data: rightOperand, encoding: .utf8)!.components(separatedBy: ":")[0] + if left == right { + return rightOperand + } + return nil + } - func testSwift_MergeOperator_DictionaryUpdate_Encoded() { - let mergeOp = RocksDBMergeOperator(name: "operator", partialMergeBlock: - { - (key, leftOperand, rightOperand) -> String! in - let left: NSString = leftOperand.componentsSeparatedByString(":")[0] - let right: NSString = rightOperand.componentsSeparatedByString(":")[0] - if left.isEqualToString(right as String) { - return rightOperand - } - return Optional.None! - - }, - fullMergeBlock: { - (key, existing, operands) -> NSMutableDictionary! in - - let dict: NSMutableDictionary = existing as! NSMutableDictionary - for op in operands as NSArray { - let comp: NSArray = op.componentsSeparatedByString(":") - let action: NSString = comp[1] as! NSString - if action.isEqualToString("DELETE") { - dict.removeObjectForKey(comp[0]) - } else { - dict.setObject(comp[2], forKey: comp[0] as! NSString) - } + let full = { (key: Data, existing: Data?, operands: [Data]) -> Data? in + var dict: [String: Any] = [:] + if let existing = existing { + dict = Dictionary.from(data: existing) + } + + for op in operands { + let comp = String(data: op, encoding: .utf8)!.components(separatedBy: ":") + let action = comp[1] + if action == "DELETE" { + dict.removeValue(forKey: comp[0]) + } else { + dict[comp[0]] = comp[2] } - return existing as! NSMutableDictionary - }) + } + return dict.data + } - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + let mergeOp = RocksDBMergeOperator(name: "operator", partialMerge: partial, fullMerge: full) + + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.mergeOperator = mergeOp - options.keyType = .NSString - options.valueType = .NSJSONSerializable }) - let object = ["key 1" : "value 1", - "key 2" : "value 2", - "key 3" : "value 3"] + let object: [String: Any] = ["key 1" : "value 1", + "key 2" : "value 2", + "key 3" : "value 3"] - try! rocks.setObject(object, forKey: "dict key") + try! rocks.setData(object.data, forKey: "dict key") - try! rocks.mergeOperation("key 1:UPDATE:value X", forKey: "dict key") - try! rocks.mergeOperation("key 4:INSERT:value 4", forKey: "dict key") - try! rocks.mergeOperation("key 2:DELETE", forKey: "dict key") - try! rocks.mergeOperation("key 1:UPDATE:value 1 new", forKey: "dict key") + try! rocks.merge("key 1:UPDATE:value X", forKey: "dict key") + try! rocks.merge("key 4:INSERT:value 4", forKey: "dict key") + try! rocks.merge("key 2:DELETE", forKey: "dict key") + try! rocks.merge("key 1:UPDATE:value 1 new", forKey: "dict key") - let expected = ["key 1" : "value 1 new", - "key 3" : "value 3", - "key 4" : "value 4"]; + let expected: [String: Any] = ["key 1" : "value 1 new", + "key 3" : "value 3", + "key 4" : "value 4"]; - XCTAssertEqual(try! rocks.objectForKey("dict key") as! NSDictionary, expected) + let data = try! rocks.data(forKey: "dict key") + let actual = Dictionary.from(data: data) + for (key, value) in actual { + XCTAssertEqual(value as! String, expected[key] as! String) + } } } diff --git a/Tests/RocksDBPrefixExtractorTests.mm b/Tests/RocksDBPrefixExtractorTests.mm index 0a29051..0d4d056 100644 --- a/Tests/RocksDBPrefixExtractorTests.mm +++ b/Tests/RocksDBPrefixExtractorTests.mm @@ -21,23 +21,20 @@ - (void)testPrefixExtractor_FixedLength _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; options.prefixExtractor = [RocksDBPrefixExtractor prefixExtractorWithType:RocksDBPrefixFixedLength length:3]; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; }]; - [_rocks setObject:@"x" forKey:@"100A" error:nil]; - [_rocks setObject:@"x" forKey:@"100B" error:nil]; + [_rocks setData:@"x".data forKey:@"100A".data error:nil]; + [_rocks setData:@"x".data forKey:@"100B".data error:nil]; - [_rocks setObject:@"x" forKey:@"101A" error:nil]; - [_rocks setObject:@"x" forKey:@"101B" error:nil]; + [_rocks setData:@"x".data forKey:@"101A".data error:nil]; + [_rocks setData:@"x".data forKey:@"101B".data error:nil]; RocksDBIterator *iterator = [_rocks iterator]; NSMutableArray *keys = [NSMutableArray array]; - [iterator enumerateKeysWithPrefix:@"100" usingBlock:^(id key, BOOL *stop) { - [keys addObject:key]; + [iterator enumerateKeysWithPrefix:@"100".data usingBlock:^(NSData *key, BOOL *stop) { + [keys addObject:[[NSString alloc] initWithData:key]]; }]; XCTAssertEqual(keys.count, 2); @@ -46,8 +43,8 @@ - (void)testPrefixExtractor_FixedLength XCTAssertEqualObjects(keys, expected); keys = [NSMutableArray array]; - [iterator enumerateKeysWithPrefix:@"101" usingBlock:^(id key, BOOL *stop) { - [keys addObject:key]; + [iterator enumerateKeysWithPrefix:@"101".data usingBlock:^(NSData *key, BOOL *stop) { + [keys addObject:[[NSString alloc] initWithData:key]]; }]; XCTAssertEqual(keys.count, 2); @@ -55,22 +52,24 @@ - (void)testPrefixExtractor_FixedLength expected = @[@"101A", @"101B"]; XCTAssertEqualObjects(keys, expected); - [iterator seekToKey:@"1000"]; + [iterator seekToKey:@"1000".data]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, @"100A"); + XCTAssertEqualObjects(iterator.key, @"100A".data); [iterator next]; XCTAssertTrue(iterator.isValid); - XCTAssertEqualObjects(iterator.key, @"100B"); + XCTAssertEqualObjects(iterator.key, @"100B".data); } - (void)testPrefixExtractor_FixedLength_CustomComparator { // 1001 < 9910 < 2011 < 3412 ... - RocksDBComparator *cmp = [[RocksDBComparator alloc] initWithName:@"cmp" andBlock:^int(id key1, id key2) { - return [[key1 substringFromIndex:2] compare:[key2 substringFromIndex:2]]; + RocksDBComparator *cmp = [[RocksDBComparator alloc] initWithName:@"cmp" andBlock:^int(NSData *key1, NSData *key2) { + NSString *str1 = [[NSString alloc] initWithData:key1]; + NSString *str2 = [[NSString alloc] initWithData:key2]; + return [[str1 substringFromIndex:2] compare:[str2 substringFromIndex:2]]; }]; _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { @@ -84,25 +83,22 @@ - (void)testPrefixExtractor_FixedLength_CustomComparator options.tableFacotry = [RocksDBTableFactory blockBasedTableFactoryWithOptions:^(RocksDBBlockBasedTableOptions *options) { options.filterPolicy = [RocksDBFilterPolicy bloomFilterPolicyWithBitsPerKey:10 useBlockBasedBuilder:YES]; }]; - - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; }]; - [_rocks setObject:@"x" forKey:@"1010" error:nil]; - [_rocks setObject:@"x" forKey:@"4211" error:nil]; - [_rocks setObject:@"x" forKey:@"1012" error:nil]; - [_rocks setObject:@"x" forKey:@"5313" error:nil]; - [_rocks setObject:@"x" forKey:@"1020" error:nil]; - [_rocks setObject:@"x" forKey:@"4221" error:nil]; - [_rocks setObject:@"x" forKey:@"1022" error:nil]; - [_rocks setObject:@"x" forKey:@"5323" error:nil]; + [_rocks setData:@"x".data forKey:@"1010".data error:nil]; + [_rocks setData:@"x".data forKey:@"4211".data error:nil]; + [_rocks setData:@"x".data forKey:@"1012".data error:nil]; + [_rocks setData:@"x".data forKey:@"5313".data error:nil]; + [_rocks setData:@"x".data forKey:@"1020".data error:nil]; + [_rocks setData:@"x".data forKey:@"4221".data error:nil]; + [_rocks setData:@"x".data forKey:@"1022".data error:nil]; + [_rocks setData:@"x".data forKey:@"5323".data error:nil]; RocksDBIterator *iterator = [_rocks iterator]; NSMutableArray *keys = [NSMutableArray array]; - [iterator enumerateKeysWithPrefix:@"10" usingBlock:^(id key, BOOL *stop) { - [keys addObject:key]; + [iterator enumerateKeysWithPrefix:@"10".data usingBlock:^(NSData *key, BOOL *stop) { + [keys addObject:[[NSString alloc] initWithData:key]]; }]; XCTAssertEqual(keys.count, 4); @@ -111,8 +107,8 @@ - (void)testPrefixExtractor_FixedLength_CustomComparator XCTAssertEqualObjects(keys, expected); keys = [NSMutableArray array]; - [iterator enumerateKeysWithPrefix:@"42" usingBlock:^(id key, BOOL *stop) { - [keys addObject:key]; + [iterator enumerateKeysWithPrefix:@"42".data usingBlock:^(NSData *key, BOOL *stop) { + [keys addObject:[[NSString alloc] initWithData:key]]; }]; XCTAssertEqual(keys.count, 2); @@ -121,8 +117,8 @@ - (void)testPrefixExtractor_FixedLength_CustomComparator XCTAssertEqualObjects(keys, expected); keys = [NSMutableArray array]; - [iterator enumerateKeysWithPrefix:@"53" usingBlock:^(id key, BOOL *stop) { - [keys addObject:key]; + [iterator enumerateKeysWithPrefix:@"53".data usingBlock:^(NSData *key, BOOL *stop) { + [keys addObject:[[NSString alloc] initWithData:key]]; }]; XCTAssertEqual(keys.count, 2); diff --git a/Tests/RocksDBPrefixExtractorTests.swift b/Tests/RocksDBPrefixExtractorTests.swift index a1103d9..18b5952 100644 --- a/Tests/RocksDBPrefixExtractorTests.swift +++ b/Tests/RocksDBPrefixExtractorTests.swift @@ -12,24 +12,22 @@ import ObjectiveRocks class RocksDBPrefixExtractorTests : RocksDBTests { func testSwift_PrefixExtractor_FixedLength() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.prefixExtractor = RocksDBPrefixExtractor(type: .FixedLength, length: 3) - options.keyType = .NSString; - options.valueType = .NSString; + options.prefixExtractor = RocksDBPrefixExtractor(type: .fixedLength, length: 3) }) - try! rocks.setObject("x", forKey: "100A") - try! rocks.setObject("x", forKey: "100B") + try! rocks.setData("x", forKey: "100A") + try! rocks.setData("x", forKey: "100B") - try! rocks.setObject("x", forKey: "101A") - try! rocks.setObject("x", forKey: "101B") + try! rocks.setData("x", forKey: "101A") + try! rocks.setData("x", forKey: "101B") let iterator = rocks.iterator() - let keys = NSMutableArray() + var keys = [String]() - iterator.enumerateKeysWithPrefix("100", usingBlock: { (key, stop) -> Void in - keys.addObject(key) + iterator.enumerateKeys(withPrefix: "100", using: { (key, stop) -> Void in + keys.append(String(data: key, encoding: .utf8)!) }) XCTAssertEqual(keys.count, 2); @@ -38,10 +36,10 @@ class RocksDBPrefixExtractorTests : RocksDBTests { XCTAssertEqual(keys, expected); - keys.removeAllObjects() + keys.removeAll() - iterator.enumerateKeysWithPrefix("101", usingBlock: { (key, stop) -> Void in - keys.addObject(key) + iterator.enumerateKeys(withPrefix: "101", using: { (key, stop) -> Void in + keys.append(String(data: key, encoding: .utf8)!) }) XCTAssertEqual(keys.count, 2); @@ -49,64 +47,64 @@ class RocksDBPrefixExtractorTests : RocksDBTests { expected = ["101A", "101B"] XCTAssertEqual(keys, expected); - iterator.seekToKey("1000") + iterator.seek(toKey: "1000") XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSString, "100A") + XCTAssertEqual(iterator.key(), "100A".data) iterator.next() XCTAssertTrue(iterator.isValid()) - XCTAssertEqual(iterator.key() as? NSString, "100B") + XCTAssertEqual(iterator.key(), "100B".data) } func testSwift_PrefixExtractor_FixedLength_CustomComparator() { // 1001 < 9910 < 2011 < 3412 ... let cmp = RocksDBComparator(name: "cmp") { (key1, key2) -> Int32 in - let sub1: NSString = key1.substringFromIndex(2) as NSString - let sub2: NSString = key2.substringFromIndex(2) as NSString + let str1 = String(data: key1, encoding: .utf8)! + let str2 = String(data: key2, encoding: .utf8)! - let res = sub1.compare(sub2 as String) + let sub1 = str1.substring(from: str1.index(str1.startIndex, offsetBy: 1)) + let sub2 = str2.substring(from: str2.index(str2.startIndex, offsetBy: 1)) + + let res = sub1.compare(sub2) switch res { - case .OrderedAscending: + case .orderedAscending: return -1 - case .OrderedDescending: + case .orderedDescending: return 1 - case .OrderedSame: + case .orderedSame: return 0 } } - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.comparator = cmp - options.prefixExtractor = RocksDBPrefixExtractor(type: .FixedLength, length: 2) - options.keyType = .NSString; - options.valueType = .NSString; + options.prefixExtractor = RocksDBPrefixExtractor(type: .fixedLength, length: 2) options.memtablePrefixBloomBits = 100000000; options.memtablePrefixBloomProbes = 6; - options.tableFacotry = RocksDBTableFactory.blockBasedTableFactoryWithOptions({ - (options) -> Void in - options.filterPolicy = RocksDBFilterPolicy.bloomFilterPolicyWithBitsPerKey(10, useBlockBasedBuilder: true) + options.tableFacotry = RocksDBTableFactory.blockBasedTableFactory(options: { (options) -> Void in + options.filterPolicy = RocksDBFilterPolicy.bloomFilterPolicy(withBitsPerKey: 10, useBlockBasedBuilder: true) }) }) - try! rocks.setObject("x", forKey: "1010") - try! rocks.setObject("x", forKey: "4211") - try! rocks.setObject("x", forKey: "1012") - try! rocks.setObject("x", forKey: "5313") - try! rocks.setObject("x", forKey: "1020") - try! rocks.setObject("x", forKey: "4221") - try! rocks.setObject("x", forKey: "1022") - try! rocks.setObject("x", forKey: "5323") + try! rocks.setData("x", forKey: "1010") + try! rocks.setData("x", forKey: "4211") + try! rocks.setData("x", forKey: "1012") + try! rocks.setData("x", forKey: "5313") + try! rocks.setData("x", forKey: "1020") + try! rocks.setData("x", forKey: "4221") + try! rocks.setData("x", forKey: "1022") + try! rocks.setData("x", forKey: "5323") let iterator = rocks.iterator() - let keys = NSMutableArray() + var keys = [String]() - iterator.enumerateKeysWithPrefix("10", usingBlock: { (key, stop) -> Void in - keys.addObject(key) + iterator.enumerateKeys(withPrefix: "10", using: { (key, stop) -> Void in + keys.append(String(data: key, encoding: .utf8)!) }) XCTAssertEqual(keys.count, 4); @@ -115,10 +113,10 @@ class RocksDBPrefixExtractorTests : RocksDBTests { XCTAssertEqual(keys, expected); - keys.removeAllObjects() + keys.removeAll() - iterator.enumerateKeysWithPrefix("42", usingBlock: { (key, stop) -> Void in - keys.addObject(key) + iterator.enumerateKeys(withPrefix: "42", using: { (key, stop) -> Void in + keys.append(String(data: key, encoding: .utf8)!) }) XCTAssertEqual(keys.count, 2); @@ -126,11 +124,10 @@ class RocksDBPrefixExtractorTests : RocksDBTests { expected = ["4211", "4221"] XCTAssertEqual(keys, expected); + keys.removeAll() - keys.removeAllObjects() - - iterator.enumerateKeysWithPrefix("53", usingBlock: { (key, stop) -> Void in - keys.addObject(key) + iterator.enumerateKeys(withPrefix: "53", using: { (key, stop) -> Void in + keys.append(String(data: key, encoding: .utf8)!) }) XCTAssertEqual(keys.count, 2); diff --git a/Tests/RocksDBPropertiesTests.mm b/Tests/RocksDBPropertiesTests.mm index fd273e4..7cd0f0e 100644 --- a/Tests/RocksDBPropertiesTests.mm +++ b/Tests/RocksDBPropertiesTests.mm @@ -22,9 +22,9 @@ - (void)testProperties options.minWriteBufferNumberToMerge = 10; }]; - [_rocks setData:Data(@"value 1") forKey:Data(@"key 1") error:nil]; - [_rocks setData:Data(@"value 2") forKey:Data(@"key 2") error:nil]; - [_rocks setData:Data(@"value 3") forKey:Data(@"key 3") error:nil]; + [_rocks setData:@"value 1".data forKey:@"key 1".data error:nil]; + [_rocks setData:@"value 2".data forKey:@"key 2".data error:nil]; + [_rocks setData:@"value 3".data forKey:@"key 3".data error:nil]; XCTAssertGreaterThan([_rocks valueForIntProperty:RocksDBIntPropertyNumEntriesActiveMemtable], 0); XCTAssertGreaterThan([_rocks valueForIntProperty:RocksDBIntPropertyCurSizeActiveMemTable], 0); diff --git a/Tests/RocksDBPropertiesTests.swift b/Tests/RocksDBPropertiesTests.swift index dd7bace..83dd84d 100644 --- a/Tests/RocksDBPropertiesTests.swift +++ b/Tests/RocksDBPropertiesTests.swift @@ -12,37 +12,37 @@ import ObjectiveRocks class RocksDBPropertiesTests : RocksDBTests { func testSwift_Properties() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.maxWriteBufferNumber = 10; options.minWriteBufferNumberToMerge = 10; }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1".data, forKey: "key 1".data) + try! rocks.setData("value 2".data, forKey: "key 2".data) + try! rocks.setData("value 3".data, forKey: "key 3".data) - XCTAssertGreaterThan(rocks.valueForIntProperty(.NumEntriesActiveMemtable), 0 as UInt64); - XCTAssertGreaterThan(rocks.valueForIntProperty(.CurSizeActiveMemTable), 0 as UInt64); + XCTAssertGreaterThan(rocks.value(for: .numEntriesActiveMemtable), 0 as UInt64); + XCTAssertGreaterThan(rocks.value(for: .curSizeActiveMemTable), 0 as UInt64); } func testSwift_Properties_ColumnFamily() { let descriptor = RocksDBColumnFamilyDescriptor() - descriptor.addDefaultColumnFamilyWithOptions(nil) - descriptor.addColumnFamilyWithName("new_cf", andOptions: nil) + descriptor.addDefaultColumnFamily(options: nil) + descriptor.addColumnFamily(withName: "new_cf", andOptions: nil) - rocks = RocksDB.databaseAtPath(path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: path, columnFamilies: descriptor, andDatabaseOptions: { (options) -> Void in options.createIfMissing = true options.createMissingColumnFamilies = true }) - XCTAssertGreaterThanOrEqual(rocks.columnFamilies()[0].valueForIntProperty(.EstimatedNumKeys), 0 as UInt64); - XCTAssertNotNil(rocks.columnFamilies()[0].valueForProperty(.Stats)); - XCTAssertNotNil(rocks.columnFamilies()[0].valueForProperty(.SsTables)); + XCTAssertGreaterThanOrEqual((rocks.columnFamilies()[0]).value(for: .estimatedNumKeys), 0 as UInt64); + XCTAssertNotNil((rocks.columnFamilies()[0]).value(for: .stats)); + XCTAssertNotNil((rocks.columnFamilies()[0]).value(for: .ssTables)); - XCTAssertGreaterThanOrEqual(rocks.columnFamilies()[1].valueForIntProperty(.EstimatedNumKeys), 0 as UInt64); - XCTAssertNotNil(rocks.columnFamilies()[1].valueForProperty(.Stats)); - XCTAssertNotNil(rocks.columnFamilies()[1].valueForProperty(.SsTables)); + XCTAssertGreaterThanOrEqual((rocks.columnFamilies()[1]).value(for: .estimatedNumKeys), 0 as UInt64); + XCTAssertNotNil((rocks.columnFamilies()[1]).value(for: .stats)); + XCTAssertNotNil((rocks.columnFamilies()[1]).value(for: .ssTables)); } } diff --git a/Tests/RocksDBReadOnlyTests.m b/Tests/RocksDBReadOnlyTests.m index 77d75f3..165c1e8 100644 --- a/Tests/RocksDBReadOnlyTests.m +++ b/Tests/RocksDBReadOnlyTests.m @@ -38,25 +38,25 @@ - (void)testDB_ReadOnly_NotWritable options.createIfMissing = YES; }]; XCTAssertNotNil(_rocks); - [_rocks setData:Data(@"data") forKey:Data(@"key") error:nil]; + [_rocks setData:@"data".data forKey:@"key".data error:nil]; [_rocks close]; _rocks = [RocksDB databaseForReadOnlyAtPath:_path andDBOptions:nil]; NSError *error = nil; - [_rocks dataForKey:Data(@"key") error:&error]; + [_rocks dataForKey:@"key".data error:&error]; XCTAssertNil(error); error = nil; - [_rocks setData:Data(@"data") forKey:Data(@"key") error:&error]; + [_rocks setData:@"data".data forKey:@"key".data error:&error]; XCTAssertNotNil(error); error = nil; - [_rocks deleteDataForKey:Data(@"key") error:&error]; + [_rocks deleteDataForKey:@"key".data error:&error]; XCTAssertNotNil(error); error = nil; - [_rocks mergeData:Data(@"data") forKey:Data(@"key") error:&error]; + [_rocks mergeData:@"data".data forKey:@"key".data error:&error]; XCTAssertNotNil(error); } diff --git a/Tests/RocksDBReadOnlyTests.swift b/Tests/RocksDBReadOnlyTests.swift index 88d8a96..c507c0b 100644 --- a/Tests/RocksDBReadOnlyTests.swift +++ b/Tests/RocksDBReadOnlyTests.swift @@ -12,43 +12,43 @@ import ObjectiveRocks class RocksDBReadOnlyTests : RocksDBTests { func testDB_Open_ReadOnly_NilIfMissing() { - rocks = RocksDB.databaseForReadOnlyAtPath(path, andDBOptions:nil) + rocks = RocksDB.databaseForReadOnly(atPath: path, andDBOptions:nil) XCTAssertNil(rocks); } func testDB_Open_ReadOnly() { - rocks = RocksDB.databaseAtPath(path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: path, andDBOptions: { (options) -> Void in options.createIfMissing = true; }); XCTAssertNotNil(rocks); rocks.close() - rocks = RocksDB.databaseForReadOnlyAtPath(path, andDBOptions:nil) + rocks = RocksDB.databaseForReadOnly(atPath: path, andDBOptions:nil) XCTAssertNotNil(rocks); } func testDB_ReadOnly_NotWritable() { - rocks = RocksDB.databaseAtPath(path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: path, andDBOptions: { (options) -> Void in options.createIfMissing = true; }); XCTAssertNotNil(rocks); - try! rocks.setData(Data("data"), forKey: Data("key")) + try! rocks.setData("data", forKey: "key") rocks.close() - rocks = RocksDB.databaseForReadOnlyAtPath(path, andDBOptions:nil) + rocks = RocksDB.databaseForReadOnly(atPath: path, andDBOptions:nil) - try! rocks.dataForKey(Data("key")) + try! rocks.data(forKey: "key") AssertThrows { - try self.rocks.setData(Data("data"), forKey:Data("key")) + try self.rocks.setData("data", forKey:"key") } AssertThrows { - try self.rocks.deleteDataForKey(Data("key")) + try self.rocks.deleteData(forKey: "key") } AssertThrows { - try self.rocks.mergeData(Data("data"), forKey:Data("key")) + try self.rocks.merge("data", forKey:"key") } } diff --git a/Tests/RocksDBSnapshotTests.mm b/Tests/RocksDBSnapshotTests.mm index 932160e..a480ef9 100644 --- a/Tests/RocksDBSnapshotTests.mm +++ b/Tests/RocksDBSnapshotTests.mm @@ -20,24 +20,24 @@ - (void)testSnapshot options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; - [_rocks setData:Data(@"Value 2") forKey:Data(@"Key 2") error:nil]; - [_rocks setData:Data(@"Value 3") forKey:Data(@"Key 3") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; + [_rocks setData:@"Value 2".data forKey:@"Key 2".data error:nil]; + [_rocks setData:@"Value 3".data forKey:@"Key 3".data error:nil]; RocksDBSnapshot *snapshot = [_rocks snapshot]; - [_rocks deleteDataForKey:Data(@"Key 1") error:nil]; - [_rocks setData:Data(@"Value 4") forKey:Data(@"Key 4") error:nil]; + [_rocks deleteDataForKey:@"Key 1".data error:nil]; + [_rocks setData:@"Value 4".data forKey:@"Key 4".data error:nil]; - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 1") error:nil], Data(@"Value 1")); - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2")); - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 3") error:nil], Data(@"Value 3")); - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 4") error:nil], nil); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 1".data error:nil], @"Value 1".data); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 2".data error:nil], @"Value 2".data); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 3".data error:nil], @"Value 3".data); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 4".data error:nil], nil); [snapshot close]; - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 1") error:nil], nil); - XCTAssertEqualObjects([snapshot dataForKey:Data(@"Key 4") error:nil], Data(@"Value 4")); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 1".data error:nil], nil); + XCTAssertEqualObjects([snapshot dataForKey:@"Key 4".data error:nil], @"Value 4".data); } - (void)testSnapshot_Iterator @@ -46,20 +46,20 @@ - (void)testSnapshot_Iterator options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; - [_rocks setData:Data(@"Value 2") forKey:Data(@"Key 2") error:nil]; - [_rocks setData:Data(@"Value 3") forKey:Data(@"Key 3") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; + [_rocks setData:@"Value 2".data forKey:@"Key 2".data error:nil]; + [_rocks setData:@"Value 3".data forKey:@"Key 3".data error:nil]; RocksDBSnapshot *snapshot = [_rocks snapshot]; - [_rocks deleteDataForKey:Data(@"Key 1") error:nil]; - [_rocks setData:Data(@"Value 4") forKey:Data(@"Key 4") error:nil]; + [_rocks deleteDataForKey:@"Key 1".data error:nil]; + [_rocks setData:@"Value 4".data forKey:@"Key 4".data error:nil]; NSMutableArray *actual = [NSMutableArray array]; RocksDBIterator *iterator = [snapshot iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysUsingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; NSArray *expected = @[ @"Key 1", @"Key 2", @"Key 3" ]; @@ -69,8 +69,8 @@ - (void)testSnapshot_Iterator [actual removeAllObjects]; iterator = [snapshot iterator]; - [iterator enumerateKeysUsingBlock:^(id key, BOOL *stop) { - [actual addObject:Str(key)]; + [iterator enumerateKeysUsingBlock:^(NSData *key, BOOL *stop) { + [actual addObject:[[NSString alloc] initWithData:key]]; }]; expected = @[ @"Key 2", @"Key 3", @"Key 4" ]; @@ -83,13 +83,13 @@ - (void)testSnapshot_SequenceNumber options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; RocksDBSnapshot *snapshot1 = [_rocks snapshot]; - [_rocks setData:Data(@"Value 2") forKey:Data(@"Key 2") error:nil]; + [_rocks setData:@"Value 2".data forKey:@"Key 2".data error:nil]; RocksDBSnapshot *snapshot2 = [_rocks snapshot]; - [_rocks setData:Data(@"Value 3") forKey:Data(@"Key 3") error:nil]; + [_rocks setData:@"Value 3".data forKey:@"Key 3".data error:nil]; RocksDBSnapshot *snapshot3 = [_rocks snapshot]; XCTAssertEqual(snapshot1.sequenceNumber, 1); diff --git a/Tests/RocksDBSnapshotTests.swift b/Tests/RocksDBSnapshotTests.swift index 48caab6..f03108a 100644 --- a/Tests/RocksDBSnapshotTests.swift +++ b/Tests/RocksDBSnapshotTests.swift @@ -12,48 +12,48 @@ import ObjectiveRocks class RocksDBSnapshotTests : RocksDBTests { func testSwift_Snapshot() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }); - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") let snapshot = rocks.snapshot() - try! rocks.deleteDataForKey(Data("key 1")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.deleteData(forKey: "key 1") + try! rocks.setData("value 4", forKey: "key 4") - XCTAssertEqual(try! snapshot.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertEqual(try! snapshot.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! snapshot.dataForKey(Data("key 3")), Data("value 3")); - XCTAssertNil(try? snapshot.dataForKey(Data("Key 4"))) + XCTAssertEqual(try! snapshot.data(forKey: "key 1"), "value 1".data) + XCTAssertEqual(try! snapshot.data(forKey: "key 2"), "value 2".data) + XCTAssertEqual(try! snapshot.data(forKey: "key 3"), "value 3".data) + XCTAssertNil(try? snapshot.data(forKey: "Key 4")) snapshot.close() - XCTAssertNil(try? snapshot.dataForKey(Data("Key 1"))) - XCTAssertEqual(try! snapshot.dataForKey(Data("key 4")), Data("value 4")); + XCTAssertNil(try? snapshot.data(forKey: "Key 1")) + XCTAssertEqual(try! snapshot.data(forKey: "key 4"), "value 4".data) } func testSwift_Snapshot_Iterator() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 1", forKey: "key 1") + try! rocks.setData("value 2", forKey: "key 2") + try! rocks.setData("value 3", forKey: "key 3") let snapshot = rocks.snapshot() - try! rocks.deleteDataForKey(Data("key 1")) - try! rocks.setData(Data("value 4"), forKey: Data("key 4")) + try! rocks.deleteData(forKey: "key 1") + try! rocks.setData("value 4", forKey: "key 4") - let actual: NSMutableArray = [] + var actual = [String]() var iterator = snapshot.iterator() - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } var expected = [ "key 1", "key 2", "key 3" ] @@ -61,11 +61,11 @@ class RocksDBSnapshotTests : RocksDBTests { snapshot.close() - actual.removeAllObjects() + actual.removeAll() iterator = snapshot.iterator() - iterator.enumerateKeysUsingBlock { (key, stop) -> Void in - actual.addObject(Str(key as! NSData)) + iterator.enumerateKeys { (key, stop) -> Void in + actual.append(String(data: key, encoding: .utf8)!) } expected = [ "key 2", "key 3", "key 4" ] @@ -73,17 +73,17 @@ class RocksDBSnapshotTests : RocksDBTests { } func testSwift_Snapshot_SequenceNumber() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let snapshot1 = rocks.snapshot() - try! rocks.setData(Data("value 2"), forKey: Data("key 2")) + try! rocks.setData("value 2", forKey: "key 2") let snapshot2 = rocks.snapshot() - try! rocks.setData(Data("value 3"), forKey: Data("key 3")) + try! rocks.setData("value 3", forKey: "key 3") let snapshot3 = rocks.snapshot() XCTAssertEqual(snapshot1.sequenceNumber(), 1 as UInt64) diff --git a/Tests/RocksDBStatisticsTests.mm b/Tests/RocksDBStatisticsTests.mm index 143f7d9..8f73f20 100644 --- a/Tests/RocksDBStatisticsTests.mm +++ b/Tests/RocksDBStatisticsTests.mm @@ -23,7 +23,7 @@ - (void)testStatistics options.statistics = statistics; }]; - [_rocks setData:Data(@"abcd") forKey:Data(@"abcd") error:nil]; + [_rocks setData:@"abcd".data forKey:@"abcd".data error:nil]; XCTAssertNotNil(statistics.description); } @@ -37,12 +37,12 @@ - (void)testStatistics_Ticker options.statistics = statistics; }]; - [_rocks setData:Data(@"abcd") forKey:Data(@"abcd") error:nil]; + [_rocks setData:@"abcd".data forKey:@"abcd".data error:nil]; XCTAssertEqual([statistics countForTicker:RocksDBTickerBytesRead], 0); XCTAssertGreaterThan([statistics countForTicker:RocksDBTickerBytesWritten], 0); - [_rocks dataForKey:Data(@"abcd") error:nil]; + [_rocks dataForKey:@"abcd".data error:nil]; XCTAssertGreaterThan([statistics countForTicker:RocksDBTickerBytesRead], 0); } @@ -58,10 +58,10 @@ - (void)testStatistics_Histogram for (int i = 0; i < 10000; i++) { NSString *str = [NSString stringWithFormat:@"a%d", i]; - [_rocks setData:Data(str) forKey:Data(str) error:nil]; + [_rocks setData:str.data forKey:str.data error:nil]; } - [_rocks dataForKey:Data(@"a42") error:nil]; + [_rocks dataForKey:@"a42".data error:nil]; RocksDBStatisticsHistogram *dbGetHistogram = [statistics histogramDataForType:RocksDBHistogramDBGet]; XCTAssertNotNil(dbGetHistogram); diff --git a/Tests/RocksDBStatisticsTests.swift b/Tests/RocksDBStatisticsTests.swift index b96931a..a46940f 100644 --- a/Tests/RocksDBStatisticsTests.swift +++ b/Tests/RocksDBStatisticsTests.swift @@ -14,12 +14,12 @@ class RocksDBStatisticsTests : RocksDBTests { func testSwift_Statistics() { let statistics = RocksDBStatistics() - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.statistics = statistics; }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") XCTAssertNotNil(statistics.description); } @@ -27,37 +27,37 @@ class RocksDBStatisticsTests : RocksDBTests { func testSwift_Statistics_Ticker() { let statistics = RocksDBStatistics() - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.statistics = statistics; }) - try! rocks.setData(Data("abcd"), forKey: Data("abcd")) + try! rocks.setData("abcd", forKey: "abcd") - XCTAssertEqual(statistics.countForTicker(RocksDBTickerType.BytesRead), 0 as UInt64); - XCTAssertGreaterThan(statistics.countForTicker(RocksDBTickerType.BytesWritten), 0 as UInt64); + XCTAssertEqual(statistics.count(for: RocksDBTickerType.bytesRead), 0 as UInt64); + XCTAssertGreaterThan(statistics.count(for: RocksDBTickerType.bytesWritten), 0 as UInt64); - try! rocks.dataForKey(Data("abcd")) + try! rocks.data(forKey: "abcd") - XCTAssertGreaterThan(statistics.countForTicker(RocksDBTickerType.BytesRead), 0 as UInt64); + XCTAssertGreaterThan(statistics.count(for: RocksDBTickerType.bytesRead), 0 as UInt64); } func testSwift_Statistics_Histogram() { let statistics = RocksDBStatistics() - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true options.statistics = statistics; }) for i in 0...10000 { - let str = NSString(format: "a%d", i) - try! rocks.setData(Data(str as String), forKey: Data(str as String)) + let str = String(format: "a%d", i) + try! rocks.setData(str.data, forKey: str.data) } - try! rocks.dataForKey(Data("a42")) + try! rocks.data(forKey: "a42") - let dbGetHistogram = statistics.histogramDataForType(RocksDBHistogramType.DBGet) + let dbGetHistogram = statistics.histogramData(for: RocksDBHistogramType.dbGet) XCTAssertNotNil(dbGetHistogram); XCTAssertGreaterThan(dbGetHistogram.median, 0.0); diff --git a/Tests/RocksDBTests.h b/Tests/RocksDBTests.h index b652ac5..11697db 100644 --- a/Tests/RocksDBTests.h +++ b/Tests/RocksDBTests.h @@ -9,11 +9,25 @@ #import #import "ObjectiveRocks.h" -#define Data(x) [x dataUsingEncoding:NSUTF8StringEncoding] -#define Str(x) [[NSString alloc] initWithData:x encoding:NSUTF8StringEncoding] +#pragma mark - RocksDBDataConvertible -#define NumData(x) [NSData dataWithBytes:&x length:sizeof(x)] -#define Val(data, x) [data getBytes:&x length:sizeof(x)]; +@interface NSString (DataConvertible) +- (instancetype)initWithData:(NSData *)data; +- (NSData *)data; +@end + +@implementation NSString (DataConvertible) +- (instancetype)initWithData:(NSData *)data +{ + return [self initWithData:data encoding:NSUTF8StringEncoding]; +} +- (NSData *)data +{ + return [self dataUsingEncoding:NSUTF8StringEncoding]; +} +@end + +#pragma mark - Base @interface RocksDBTests : XCTestCase { @@ -27,21 +41,3 @@ RocksDB *_rocks; } @end - -@interface NSMutableArray (Shuffle) -- (void)shuffle; -@end - -@implementation NSMutableArray (Shuffle) - -- (void)shuffle -{ - NSUInteger count = [self count]; - for (NSUInteger i = 0; i < count; ++i) { - NSInteger remainingCount = count - i; - NSInteger exchangeIndex = i + arc4random_uniform((u_int32_t )remainingCount); - [self exchangeObjectAtIndex:i withObjectAtIndex:exchangeIndex]; - } -} - -@end \ No newline at end of file diff --git a/Tests/RocksDBWriteBatchTests.mm b/Tests/RocksDBWriteBatchTests.mm index 7e1bb1e..e369003 100644 --- a/Tests/RocksDBWriteBatchTests.mm +++ b/Tests/RocksDBWriteBatchTests.mm @@ -21,15 +21,15 @@ - (void)testWriteBatch_Perform }]; [_rocks performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *options) { - [batch setData:Data(@"Value 1") forKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch setData:@"Value 1".data forKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; } error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], Data(@"Value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], Data(@"Value 3")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], @"Value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], @"Value 2".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], @"Value 3".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], nil); } - (void)testWriteBatch_Perform_DeleteOps @@ -38,18 +38,18 @@ - (void)testWriteBatch_Perform_DeleteOps options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; [_rocks performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *options) { - [batch deleteDataForKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch deleteDataForKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; } error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], Data(@"Value 3")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], @"Value 2".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], @"Value 3".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], nil); } - (void)testWriteBatch_Perform_ClearOps @@ -58,20 +58,20 @@ - (void)testWriteBatch_Perform_ClearOps options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; [_rocks performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *options) { - [batch deleteDataForKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch deleteDataForKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; [batch clear]; - [batch setData:Data(@"Value 4") forKey:Data(@"Key 4")]; + [batch setData:@"Value 4".data forKey:@"Key 4".data]; } error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], Data(@"Value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], Data(@"Value 4")); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], @"Value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], @"Value 4".data); } - (void)testWriteBatch_Apply @@ -82,16 +82,16 @@ - (void)testWriteBatch_Apply RocksDBWriteBatch *batch = [_rocks writeBatch]; - [batch setData:Data(@"Value 1") forKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch setData:@"Value 1".data forKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; [_rocks applyWriteBatch:batch writeOptions:nil error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], Data(@"Value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], Data(@"Value 3")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], @"Value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], @"Value 2".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], @"Value 3".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], nil); } - (void)testWriteBatch_Apply_DeleteOps @@ -100,49 +100,53 @@ - (void)testWriteBatch_Apply_DeleteOps options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; RocksDBWriteBatch *batch = [_rocks writeBatch]; - [batch deleteDataForKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch deleteDataForKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; [_rocks applyWriteBatch:batch writeOptions:nil error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], Data(@"Value 3")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], @"Value 2".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], @"Value 3".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], nil); } - (void)testWriteBatch_Apply_MergeOps { + id block = ^NSData *(NSData *key, NSData *existingValue, NSData *value) { + NSMutableString *result = [NSMutableString string]; + if (existingValue != nil) { + [result setString:[[NSString alloc] initWithData:existingValue]]; + } + [result appendString:@","]; + [result appendString:[[NSString alloc] initWithData:value]]; + return result.data; + }; + + RocksDBMergeOperator *mergeOp = [RocksDBMergeOperator operatorWithName:@"merge" andBlock:block]; + _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { options.createIfMissing = YES; - options.mergeOperator = [RocksDBMergeOperator operatorWithName:@"merge" andBlock:^id(id key, id existingValue, id value) { - NSMutableString *result = [NSMutableString string]; - if (existingValue != nil) { - [result setString:Str(existingValue)]; - } - [result appendString:@","]; - [result appendString:Str(value)]; - return Data(result); - }]; + options.mergeOperator = mergeOp; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; RocksDBWriteBatch *batch = [_rocks writeBatch]; - [batch deleteDataForKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; - [batch mergeData:Data(@"Value 2 New") forKey:Data(@"Key 2")]; + [batch deleteDataForKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; + [batch mergeData:@"Value 2 New".data forKey:@"Key 2".data]; [_rocks applyWriteBatch:batch writeOptions:nil error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], Data(@"Value 2,Value 2 New")); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], @"Value 2,Value 2 New".data); } - (void)testWriteBatch_Apply_ClearOps @@ -151,22 +155,22 @@ - (void)testWriteBatch_Apply_ClearOps options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; RocksDBWriteBatch *batch = [_rocks writeBatch]; - [batch deleteDataForKey:Data(@"Key 1")]; - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch deleteDataForKey:@"Key 1".data]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; [batch clear]; - [batch setData:Data(@"Value 4") forKey:Data(@"Key 4")]; + [batch setData:@"Value 4".data forKey:@"Key 4".data]; [_rocks applyWriteBatch:batch writeOptions:nil error:nil]; - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 1") error:nil], Data(@"Value 1")); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 2") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 3") error:nil], nil); - XCTAssertEqualObjects([_rocks dataForKey:Data(@"Key 4") error:nil], Data(@"Value 4")); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 1".data error:nil], @"Value 1".data); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 2".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 3".data error:nil], nil); + XCTAssertEqualObjects([_rocks dataForKey:@"Key 4".data error:nil], @"Value 4".data); } - (void)testWriteBatch_Count @@ -175,16 +179,16 @@ - (void)testWriteBatch_Count options.createIfMissing = YES; }]; - [_rocks setData:Data(@"Value 1") forKey:Data(@"Key 1") error:nil]; + [_rocks setData:@"Value 1".data forKey:@"Key 1".data error:nil]; RocksDBWriteBatch *batch = [_rocks writeBatch]; - [batch deleteDataForKey:Data(@"Key 1")]; + [batch deleteDataForKey:@"Key 1".data]; XCTAssertEqual(batch.count, 1); - [batch setData:Data(@"Value 2") forKey:Data(@"Key 2")]; - [batch setData:Data(@"Value 3") forKey:Data(@"Key 3")]; + [batch setData:@"Value 2".data forKey:@"Key 2".data]; + [batch setData:@"Value 3".data forKey:@"Key 3".data]; XCTAssertEqual(batch.count, 3); @@ -192,35 +196,14 @@ - (void)testWriteBatch_Count XCTAssertEqual(batch.count, 0); - [batch setData:Data(@"Value 4") forKey:Data(@"Key 4")]; - [batch setData:Data(@"Value 5") forKey:Data(@"Key 4")]; + [batch setData:@"Value 4".data forKey:@"Key 4".data]; + [batch setData:@"Value 5".data forKey:@"Key 4".data]; XCTAssertEqual(batch.count, 2); - [batch deleteDataForKey:Data(@"Key 4")]; + [batch deleteDataForKey:@"Key 4".data]; XCTAssertEqual(batch.count, 3); } -- (void)testWriteBatch_Encoded -{ - _rocks = [RocksDB databaseAtPath:_path andDBOptions:^(RocksDBOptions *options) { - options.createIfMissing = YES; - options.keyType = RocksDBTypeNSString; - options.valueType = RocksDBTypeNSString; - }]; - - [_rocks setObject:@"Value 1" forKey:@"Key 1" error:nil]; - - [_rocks performWriteBatch:^(RocksDBWriteBatch *batch, RocksDBWriteOptions *options) { - [batch setObject:@"Value 2" forKey:@"Key 2"]; - [batch setObject:@"Value 3" forKey:@"Key 3"]; - [batch deleteObjectForKey:@"Key 1"]; - } error:nil]; - - XCTAssertEqualObjects([_rocks objectForKey:@"Key 1" error:nil], nil); - XCTAssertEqualObjects([_rocks objectForKey:@"Key 2" error:nil], @"Value 2"); - XCTAssertEqualObjects([_rocks objectForKey:@"Key 3" error:nil], @"Value 3"); -} - @end diff --git a/Tests/RocksDBWriteBatchTests.swift b/Tests/RocksDBWriteBatchTests.swift index 321e641..852198f 100644 --- a/Tests/RocksDBWriteBatchTests.swift +++ b/Tests/RocksDBWriteBatchTests.swift @@ -12,168 +12,170 @@ import ObjectiveRocks class RocksDBWriteBatchTests : RocksDBTests { func testSwift_WriteBatch_Perform() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) try! rocks.performWriteBatch { (batch, options) -> Void in - batch.setData(Data("value 1"), forKey: Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.setData("value 1", forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") } - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 3")), Data("value 3")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 4"))) + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data); + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2".data); + XCTAssertEqual(try! rocks.data(forKey: "key 3"), "value 3".data); + XCTAssertNil(try? rocks.data(forKey: "Key 4")) } func testSwift_WriteBatch_Perform_DeleteOps() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") try! rocks.performWriteBatch ({ (batch, options) -> Void in - batch.deleteDataForKey(Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.deleteData(forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") }) - XCTAssertNil(try? rocks.dataForKey(Data("Key 1"))) - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 3")), Data("value 3")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 4"))) + XCTAssertNil(try? rocks.data(forKey: "Key 1")) + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2"); + XCTAssertEqual(try! rocks.data(forKey: "key 3"), "value 3"); + XCTAssertNil(try? rocks.data(forKey: "Key 4")) } func testSwift_WriteBatch_Perform_ClearOps() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") try! rocks.performWriteBatch ({ (batch, options) -> Void in - batch.deleteDataForKey(Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.deleteData(forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") batch.clear() - batch.setData(Data("value 4"), forKey: Data("key 4")) + batch.setData("value 4", forKey: "key 4") }) - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 2"))) - XCTAssertNil(try? rocks.dataForKey(Data("Key 3"))) - XCTAssertEqual(try! rocks.dataForKey(Data("key 4")), Data("value 4")); + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data); + XCTAssertNil(try? rocks.data(forKey: "Key 2")) + XCTAssertNil(try? rocks.data(forKey: "Key 3")) + XCTAssertEqual(try! rocks.data(forKey: "key 4"), "value 4".data); } func testSwift_WriteBatch_Apply() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) let batch = rocks.writeBatch() - batch.setData(Data("value 1"), forKey: Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.setData("value 1", forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") try! rocks.applyWriteBatch(batch, writeOptions: nil) - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 3")), Data("value 3")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 4"))) + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1".data); + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2".data); + XCTAssertEqual(try! rocks.data(forKey: "key 3"), "value 3".data); + XCTAssertNil(try? rocks.data(forKey: "Key 4")) } func testSwift_WriteBatch_Apply_DeleteOps() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let batch = rocks.writeBatch() - batch.deleteDataForKey(Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.deleteData(forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") try! rocks.applyWriteBatch(batch, writeOptions: nil) - XCTAssertNil(try? rocks.dataForKey(Data("Key 1"))) - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2")); - XCTAssertEqual(try! rocks.dataForKey(Data("key 3")), Data("value 3")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 4"))) + XCTAssertNil(try? rocks.data(forKey: "Key 1")) + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2".data); + XCTAssertEqual(try! rocks.data(forKey: "key 3"), "value 3".data); + XCTAssertNil(try? rocks.data(forKey: "Key 4")) } func testSwift_WriteBatch_Apply_MergeOps() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true - options.mergeOperator = RocksDBMergeOperator(name: "merge", andBlock: { (key, existing, value) -> AnyObject in - let result: NSMutableString = "" - if let existingValue = existing as? NSData { - result.setString(Str(existingValue) as String) + options.mergeOperator = RocksDBMergeOperator(name: "merge") { (key, existing, value) -> Data in + var result: String = "" + if let existing = existing, let existingString = String(data: existing, encoding: .utf8) { + result = existingString } - result.appendString(",") - result.appendString(Str(value as! NSData) as String) - return Data(result as String) - }) + result.append(",") + if let value = String(data: value, encoding: .utf8) { + result.append(value) + } + return result.data(using: .utf8)! + } }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let batch = rocks.writeBatch() - batch.deleteDataForKey(Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) - batch.mergeData(Data("value 2 new"), forKey: Data("key 2")) + batch.deleteData(forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") + batch.mergeData("value 2 new", forKey: "key 2") try! rocks.applyWriteBatch(batch, writeOptions: nil) - XCTAssertEqual(try! rocks.dataForKey(Data("key 2")), Data("value 2,value 2 new")); + XCTAssertEqual(try! rocks.data(forKey: "key 2"), "value 2,value 2 new"); } func testSwift_WriteBatch_Apply_ClearOps() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let batch = rocks.writeBatch() - batch.deleteDataForKey(Data("key 1")) - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.deleteData(forKey: "key 1") + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") batch.clear() - batch.setData(Data("value 4"), forKey: Data("key 4")) + batch.setData("value 4", forKey: "key 4") try! rocks.applyWriteBatch(batch, writeOptions: nil) - XCTAssertEqual(try! rocks.dataForKey(Data("key 1")), Data("value 1")); - XCTAssertNil(try? rocks.dataForKey(Data("Key 2"))) - XCTAssertNil(try? rocks.dataForKey(Data("Key 3"))) - XCTAssertEqual(try! rocks.dataForKey(Data("key 4")), Data("value 4")); + XCTAssertEqual(try! rocks.data(forKey: "key 1"), "value 1"); + XCTAssertNil(try? rocks.data(forKey: "Key 2")) + XCTAssertNil(try? rocks.data(forKey: "Key 3")) + XCTAssertEqual(try! rocks.data(forKey: "key 4"), "value 4"); } func testSwift_WriteBatch_Count() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in + rocks = RocksDB.database(atPath: self.path, andDBOptions: { (options) -> Void in options.createIfMissing = true }) - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) + try! rocks.setData("value 1", forKey: "key 1") let batch = rocks.writeBatch() - batch.deleteDataForKey(Data("key 1")) + batch.deleteData(forKey: "key 1") XCTAssertEqual(batch.count(), 1 as Int32); - batch.setData(Data("value 2"), forKey: Data("key 2")) - batch.setData(Data("value 3"), forKey: Data("key 3")) + batch.setData("value 2", forKey: "key 2") + batch.setData("value 3", forKey: "key 3") XCTAssertEqual(batch.count(), 3 as Int32); @@ -181,34 +183,13 @@ class RocksDBWriteBatchTests : RocksDBTests { XCTAssertEqual(batch.count(), 0 as Int32); - batch.setData(Data("value 4"), forKey: Data("key 3")) - batch.setData(Data("value 5"), forKey: Data("key 4")) + batch.setData("value 4", forKey: "key 3") + batch.setData("value 5", forKey: "key 4") XCTAssertEqual(batch.count(), 2 as Int32); - batch.deleteDataForKey(Data("key 4")) + batch.deleteData(forKey: "key 4") XCTAssertEqual(batch.count(), 3 as Int32); } - - func testSwift_WriteBatch_Encoded() { - rocks = RocksDB.databaseAtPath(self.path, andDBOptions: { (options) -> Void in - options.createIfMissing = true - options.keyType = .NSString - options.valueType = .NSString - }) - - try! rocks.setData(Data("value 1"), forKey: Data("key 1")) - - try! rocks.performWriteBatch ({ (batch, options) -> Void in - batch.setObject("value 2", forKey: "key 2") - batch.setObject("value 3", forKey: "key 3") - batch.deleteObjectForKey("key 1") - }) - - let value = try? rocks.objectForKey("key 1") - XCTAssertNil(value) - XCTAssertEqual(try! rocks.objectForKey("key 2") as! NSString, "value 2"); - XCTAssertEqual(try! rocks.objectForKey("key 3") as! NSString, "value 3"); - } }